Last active
August 30, 2018 16:46
-
-
Save maxvolovikov/deed4d50daa0a536a458fada70d91e7a to your computer and use it in GitHub Desktop.
pseudoclassical class
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
// pseudoclassical class | |
var Dogs = function (name, breed, age, happiness, hunger, energy){ | |
this.name = name; | |
this.breed = breed; | |
this.age = age; | |
this.happiness = happiness; | |
this.hunger = hunger; | |
this.energy = energy; | |
} | |
Dogs.prototype.feed = function(food){ | |
if(this.hunger - food > 0) { | |
this.hunger -= food; | |
} else { | |
this.hunger = 0; | |
} | |
}; | |
Dogs.prototype.play = function(time){ | |
if(this.happiness + time < 100) { | |
this.happiness += time; | |
} else { | |
this.happiness = 100; | |
} | |
if(this.energy - time > 0) { | |
this.energy -= time; | |
} else { | |
this.energy = 0; | |
} | |
}; | |
Dogs.prototype.nap = function(time) { | |
if(this.energy + time < 100) { | |
this.energy += time; | |
} else { | |
this.energy = 100; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment