Skip to content

Commit 6f07d63

Browse files
committed
working on prototype
1 parent 1bbbc93 commit 6f07d63

4 files changed

Lines changed: 66 additions & 39 deletions

File tree

‎package-lock.json‎

Lines changed: 14 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"repository": {
1313
"type": "git",
1414
"url": "git+https://github.com/LambdaSchool/javascript-ii.git"
15-
},
15+
},
1616
"devDependencies": {
1717
"babel-jest": "^19.0.0",
1818
"eslint": "^3.17.1",
1919
"eslint-config-airbnb-base": "^11.1.3",
20-
"eslint-plugin-import": "^2.2.0",
20+
"eslint-plugin-import": "^2.9.0",
2121
"jest": "^19.0.2",
2222
"regenerator-runtime": "^0.10.3"
2323
},

‎src/class.js‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,25 @@ checkPasswd.comparePasswords('12345600');
3434
// `meow` that should return the string `<name> meowed!` where `<name>` is the `name`
3535
// property set on the Cat instance.
3636

37-
// code here
37+
//code here
3838

39-
class Animal {
40-
constructor(obj){
41-
this.type = obj.type;
42-
this.name = obj.name;
43-
this.sound = obj.sound;
44-
}
39+
// class Animal {
40+
// constructor(obj){
41+
// this.type = obj.type;
42+
// this.name = obj.name;
43+
// this.sound = obj.sound;
44+
// }
4545

46-
differentSound(){
47-
return this.sound;
48-
}
49-
}
46+
// differentSound(){
47+
// return this.sound;
48+
// }
49+
// }
5050

51-
class Cat.Animal{
52-
53-
}
51+
// class Cat
52+
// extends Animal{
53+
54+
// }
55+
// }
5456

5557

5658
/* eslint-disable no-undef */

‎src/prototype.js‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,58 @@
66
GameObject
77
createdAt
88
dimensions
9-
destroy() // prototype method -> returns the string 'Game object was removed from the game.'
9+
destroy() // prototype method -> returns the string 'Game object was removed from the game.'*/
1010

11+
function GameObject (gameobj) {
12+
this.createdAt = gameobj.createdAt;
13+
this.dimensions = gameobj.dimensions;
14+
}
15+
16+
GameObject.prototype.distroy = function(){
17+
console.log('Game object was removed from the game');
18+
}
19+
/*
1120
NPC
1221
hp
1322
name
1423
takeDamage() // prototype method -> returns the string '<object name> took damage.'
1524
// should inherit destroy() from GameObject's prototype
25+
*/
26+
function NPC(npcObj){
27+
GameObject.call(this,npcObj);
28+
this. hp = npcObj.hp;
29+
this.name = npcObj.name;
30+
}
1631

32+
NPC.prototype.takeDamage = function(){
33+
console.log(`${this.name} took damage`);
34+
}
35+
/*
1736
Humanoid
1837
faction
1938
weapons
2039
language
2140
greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
2241
// should inherit destroy() from GameObject through NPC
2342
// should inherit takeDamage() from NPC
43+
*/
44+
function Humanoid (humanoidObj){
45+
GameObject.call(this.humanoidObj);
46+
this.faction = humanoidObj.faction;
47+
this.weapons = humanoidObj.weapons;
48+
this.language = humanoidObj.language
49+
}
2450

51+
Humanoid.prototype.greet = function(){
52+
console.log(`${this.name} offers greetings in ${this.language}`);
53+
}
54+
/*
2555
Inheritance chain: Humanoid -> NPC -> GameObject
2656
Instances of Humanoid should have all of the same properties as NPC and GameObject.
2757
Instances of NPC should have all of the same properties as GameObject.
2858
2959
Example:
30-
60+
*/
3161
const hamsterHuey = new Humanoid({
3262
createdAt: new Date(),
3363
dimensions: {
@@ -47,7 +77,8 @@
4777
hamsterHuey.greet(); // returns 'Hamster Huey offers a greeting in Hamsterish'
4878
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
4979
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
50-
*/
80+
81+
5182

5283
/* eslint-disable no-undef */
5384

0 commit comments

Comments
 (0)