Skip to content

Commit

Permalink
finished tamagotchi class
Browse files Browse the repository at this point in the history
  • Loading branch information
shanicegrif committed Jan 14, 2024
1 parent 60ba374 commit 9cf10af
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion tamagotchi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,81 @@
// Create class below
class Tamagotchi {

constructor(name, energy=9, full=8, mood=6, sick=false, rehomed=false) {
this.name = name;
this.energy = energy;
this.full = full;
this.mood = mood;
this.sick = sick;
this.rehomed = rehomed;
}

greet() {
console.log(`Hell, I'm ${this.name}!`)
}

status() {

}

eat() {
this.full +=2;
this.energy -= 1;

if(this.full > 10 ) {
this.sick = true;
}
}

medicate() {
if(this.sick) {
this.full = 9;
this.energy -= 3;
this.sick = false;
} else {
console.log("refusal to take medicine");
this.energy -= 1;
}
}

play() {
if(this.sick) {
this.mood -= 1;
this.energy -= 1;
} else if(this.energy <= 3) {
console.log("I'm took tired to play");
this.energy -= 1;
} else if(this.mood > 9){
this.energy -= 2;
this.full -= 1;
} else {
this.mood += 2;
this.energy -= 1;
this.full -= 1;
}
}

sleep() {
this.energy += 4;
this.full -= 3;
}

timePasses() {
if(!this.sick) {
this.mood -= 2;
this.full -= 1;
this.energy -= 1;
} else {
this.mood -= 3;
this.full -= 2;
this.energy -= 2;
}
}

badGuardian() {
if(this.energy <= 0 || this.mood <= 0 || this.full <= 0) {
this.rehomed = true;
}
}
}
// Do not edit below this line
module.exports = Tamagotchi;

0 comments on commit 9cf10af

Please sign in to comment.