Skip to content

Instantly share code, notes, and snippets.

@kosmikko
Created January 20, 2016 09:42
Show Gist options
  • Save kosmikko/4a27817b551ca14b5734 to your computer and use it in GitHub Desktop.
Save kosmikko/4a27817b551ca14b5734 to your computer and use it in GitHub Desktop.
robodog
class GameObject {
constructor(name) {
this.name = name;
}
sayName() {
console.log(`Hi, I am ${this.name}`);
}
}
class Animal extends GameObject {
eat() {
console.log(`${this.name} is eating.`);
}
}
class Dog extends Animal {
constructor(name) {
super(name)
this.foodLevel = 0;
}
eat() {
super.eat();
this.foodLevel++;
}
bark() {
console.log(`${this.name} barking`);
}
}
class Robot extends GameObject {
constructor(name, speed) {
super(name);
this.speed = speed;
}
drive() {
console.log(`${this.name} is driving at speed ${this.speed}`);
}
}
class RobotDog extends Robot {
constructor(name, speed) {
super(name);
this.speed = speed;
this.foodLevel = 0;
}
// RobotDog is eating power
eat() {
console.log(`${this.name} is eating.`);
this.foodLevel++;
}
bark() {
console.log(`${this.name} barking`);
}
}
let rdog = new RobotDog("Spottyrobo", 29);
rdog.sayName();
rdog.eat();
rdog.bark();
rdog.drive();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment