Created
January 20, 2016 09:42
-
-
Save kosmikko/4a27817b551ca14b5734 to your computer and use it in GitHub Desktop.
robodog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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