Skip to content

Commit 1a4e4ce

Browse files
committed
prototype challenge complete
1 parent d9dbb17 commit 1a4e4ce

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/prototype.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,63 @@
11
/*
22
Object oriented design is commonly used in video games. For this part of the assignment
33
you will be implementing several classes with their correct inheritance heirarchy.
4-
54
In this file you will be creating three classes:
65
GameObject
76
createdAt
87
dimensions
98
destroy() // prototype method -> returns the string 'Game object was removed from the game.'
9+
*/
10+
function GameObject(object) {
11+
this.createdAt = object.createdAt;
12+
this.dimensions = object.dimensions;
13+
}
14+
GameObject.prototype.destroy = () => {
15+
return 'Game object was removed from the game.';
16+
};
1017

18+
/*
1119
NPC
1220
hp
1321
name
1422
takeDamage() // prototype method -> returns the string '<object name> took damage.'
1523
// should inherit destroy() from GameObject's prototype
24+
*/
25+
function NPC(npc) {
26+
GameObject.call(this, npc);
27+
this.hp = npc.hp;
28+
this.name = npc.name;
29+
// GameObject.call(this, options);
30+
}
1631

32+
NPC.prototype = Object.create(GameObject.prototype);
33+
NPC.prototype.takeDamage = function () {
34+
return `${this.name} took damage.`;
35+
};
36+
/*
1737
Humanoid
1838
faction
1939
weapons
2040
language
2141
greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
2242
// should inherit destroy() from GameObject through NPC
23-
// should inherit takeDamage() from NPC
43+
// should inherit takeDamage() from NPC */
2444

45+
function Humanoid(player) {
46+
NPC.call(this, player);
47+
GameObject.call(this, player);
48+
this.faction = player.faction;
49+
this.weapons = player.weapons;
50+
this.language = player.language;
51+
}
52+
// Humanoid.prototype = Object.create(GameObject.prototype);
53+
Humanoid.prototype = Object.create(NPC.prototype);
54+
Humanoid.prototype.greet = function () {
55+
return `${this.name} offers a greeting in ${this.language}.`;
56+
};
57+
/*
2558
Inheritance chain: Humanoid -> NPC -> GameObject
2659
Instances of Humanoid should have all of the same properties as NPC and GameObject.
2760
Instances of NPC should have all of the same properties as GameObject.
28-
2961
Example:
3062
3163
const hamsterHuey = new Humanoid({
@@ -51,8 +83,8 @@
5183

5284
/* eslint-disable no-undef */
5385

54-
module.exports = {
55-
GameObject,
56-
NPC,
57-
Humanoid,
58-
};
86+
module.exports = {
87+
GameObject,
88+
NPC,
89+
Humanoid,
90+
};

yarn-error.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Arguments:
2-
C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test class.test.js
2+
C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test prototype.test.js
33

44
PATH:
55
C:\Users\2940c\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\2940c\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files (x86)\Yarn\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Users\2940c\AppData\Roaming\npm;C:\Users\2940c\AppData\Local\Yarn\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
@@ -55,7 +55,7 @@ Trace:
5555
Error: Command failed.
5656
Exit code: 1
5757
Command: C:\WINDOWS\system32\cmd.exe
58-
Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose class.test.js
58+
Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose prototype.test.js
5959
Directory: C:\Users\2940c\Desktop\Lambda\JavaScript-II
6060
Output:
6161

0 commit comments

Comments
 (0)