Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oop lab #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions food.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
// Create class below
class Food {
constructor(name, daysToSpoil, fresh = true) {
this.name = name;
this.daysToSpoil = daysToSpoil;
this.fresh = fresh;
}

prepare() {
console.log(`${this.name} is being prepared`);
}

isFresh() {
if (this.fresh == false || this.daysToSpoil <= 0) {
console.log(`${this.name} has spoiled.`);
} else {
console.log(
`There are ${this.daysToSpoil} days left before ${this.name} spoils.`
);
}
}

aDayPasses() {
this.daysToSpoil--;
this.isFresh();
}
}

class BadFood extends Food {
constructor(name, weapons) {
super(name, 20, true);
this.weapons = weapons;
}

isFresh() {
super.isFresh();
}

prepare() {
console.log(
`Fight preparation: I am ${this.name} and my calories are too high to count!`
);
}
}

// Do not edit below this line
module.exports = Food;
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions tamagotchi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,86 @@
// 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;