Created
September 26, 2018 06:33
-
-
Save henriquegogo/a412ad601ff32270a35a1022a95c4775 to your computer and use it in GitHub Desktop.
Game prototype
This file contains hidden or 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 Person { | |
constructor(name) { | |
this.name = name; | |
this.age = 0; | |
this.cash = 0; | |
this.job = undefined; | |
this.properties = []; | |
this.children = []; | |
} | |
turn() { | |
this.age = this.age + 0.5; | |
this.cash += this.job.salary; | |
this.properties.forEach(i => this.cash -= i.expenses); | |
this.children.forEach(i => this.cash -= 10); | |
} | |
} | |
class Property { | |
constructor(description) { | |
this.description = description; | |
this.expenses = 10; | |
this.value = 50000; | |
} | |
} | |
class Job { | |
constructor(description) { | |
this.description = description; | |
this.salary = 100; | |
} | |
} | |
let me = new Person('Henrique'); | |
let daughter = new Person('Letícia'); | |
let son = new Person('Pedro Lucas'); | |
let house = new Property('House'); | |
let beachhouse = new Property('House in Miami'); | |
let car = new Property('Car'); | |
let job = new Job('Developer'); | |
me.children.push(daughter, son); | |
me.properties.push(house, beachhouse, car); | |
me.job = job; | |
me.turn(); | |
me.turn(); | |
me.turn(); | |
console.log(me); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment