Skip to content

Instantly share code, notes, and snippets.

@maxvolovikov
Last active August 30, 2018 16:46
Show Gist options
  • Save maxvolovikov/deed4d50daa0a536a458fada70d91e7a to your computer and use it in GitHub Desktop.
Save maxvolovikov/deed4d50daa0a536a458fada70d91e7a to your computer and use it in GitHub Desktop.
pseudoclassical class
// 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