Skip to content
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
51 changes: 51 additions & 0 deletions src/animals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function Fruit(attrs) {
this.type = attrs.type;
this.name = attrs.name;
this.isRipe = attrs.isRipe;
this.calories = attrs.calories;
}
// constructor

Fruit.prototype.calculateCalories = function() {
console.log(`Calories in a ${this.name} are ${this.calories * 200}`);
};

function Banana(banAttrs) {
Fruit.call(this, banAttrs);
this.doMonkeysEat = banAttrs.doMonkeysEat;
}

function Kiwi(kiwiAttrs) {
Fruit.call(this, kiwiAttrs);
this.isFuzzy = kiwiAttrs.isFuzzy;
}

Banana.prototype = Object.create(Fruit.prototype);
Banana.prototype.ripen = function() {
if(this.isRipe === false) {
this.isRipe = true;
}
};

Kiwi.prototype = Object.create(Fruit.prototype);

const myBanana = new Banana({
type: 'tree',
name: 'Banana',
isRipe: false,
calories: 1,
doMonkeysEat: true,
});

const myKiwi = new Kiwi({
type: 'tree',
name: 'Kiwi',
isRipe: false,
calories: 3,
isFuzzy: true,
});

console.log(myKiwi);
myKiwi.calculateCalories();
myBanana.calculateCalories();
myKiwi.ripen();
52 changes: 51 additions & 1 deletion src/prototype.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Object oriented design is commonly used in video games. For this part of the assignment
you will be implementing several classes with their correct inheritance heirarchy.
you will be implementing several classes with their correct inheritance hierarchy.

In this file you will be creating three classes:
GameObject
Expand Down Expand Up @@ -51,6 +51,56 @@

/* eslint-disable no-undef */

// ===== myCODE ======

function GameObject(attrs) {
this.createdAt = attrs.createdAt;
this.dimensions = attrs.dimensions;
}
GameObject.prototype.destroy = function() { // prototype method -> returns the string 'Game object was removed from the game.'
return 'Game object was removed from the game.';
};

function NPC(attrs) {
this.hp = attrs.hp;
this.name = attrs.name;
};
NPC.prototype = Object.create(GameObject.prototype);
//
NPC.prototype.takeDamage = function() { // prototype method -> returns the string '<object name> took damage.'
return '${this.name} took damage.'; // should inherit destroy() from GameObject's prototype
};

function Humanoid(attrs) {
this.faction = attrs.faction;
this.weapons = attrs.weapons;
this.name = attrs.language;
};
Humanoid.prototype.greet = function() { // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
GameObject.call(this,GameObject(attrs)); // should inherit destroy() from GameObject through NPC
// should inherit takeDamage() from NPC

// Animal.prototype = Object.create(Animal.prototype);
// const mittens

//Example:

const hamsterHuey = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
hp: 5,
name: 'Hamster Huey',
faction: 'Gooey Kablooie',
weapons: [
'bubblegum',
],
language: 'Hamsterish',
});

module.exports = {
GameObject,
NPC,
Expand Down