88 dimensions
99 destroy() // prototype method -> returns the string 'Game object was removed from the game.'
1010 */
11- function GameObject ( data ) {
12- this . createdAt = data . createdAt ;
13- this . dimensions = data . dimensions ;
14- }
15- GameObject . prototype . destroy = function ( ) {
16- return 'Game object was removed from the game' ;
11+
12+ class GameObject {
13+ constructor ( data ) {
14+ this . createdAt = data . createdAt ;
15+ this . dimensions = data . dimensions ;
16+ }
17+ destroy ( ) {
18+ return 'Game object was removed from the game' ;
19+ }
1720}
21+
1822 /*
1923 NPC
2024 hp
2125 name
2226 takeDamage() // prototype method -> returns the string '<object name> took damage.'
2327 // should inherit destroy() from GameObject's prototype
2428 */
25- function NPC ( data ) {
26- GameObject . call ( this , data ) ;
27- this . hp = data . hp ;
28- this . name = data . name ;
29- }
30-
31- NPC . prototype = Object . create ( GameObject . prototype ) ;
32-
33- NPC . prototype . takeDamage = function ( ) {
34- return `${ this . name } took damage` ;
29+ class NPC extends GameObject {
30+ constructor ( data ) {
31+ super ( data ) ;
32+ this . hp = data . hp ;
33+ this . name = data . name ;
34+ }
35+ takeDamage ( ) {
36+ return `${ this . name } took damage` ;
37+ }
3538}
3639
3740 /*
@@ -47,22 +50,20 @@ NPC.prototype.takeDamage = function () {
4750 Instances of Humanoid should have all of the same properties as NPC and GameObject.
4851 Instances of NPC should have all of the same properties as GameObject.
4952 */
50- function Humanoid ( data ) {
51- NPC . call ( this , data ) ;
52- this . faction = data . faction ;
53- this . weapons = data . weapons ;
54- this . language = data . language ;
55- }
56-
57- Humanoid . prototype = Object . create ( NPC . prototype ) ;
58-
59- Humanoid . prototype . greet = function ( ) {
60- return `${ this . name } offers a greeting in ${ this . language } ` ;
53+ class Humanoid extends NPC {
54+ constructor ( data ) {
55+ super ( data ) ;
56+ this . faction = data . faction ;
57+ this . weapons = data . weapons ;
58+ this . language = data . language ;
59+ }
60+ greet ( ) {
61+ return `${ this . name } offers a greeting in ${ this . language } ` ;
62+ }
6163}
6264
6365 //Example:
6466
65-
6667 const hamsterHuey = new Humanoid ( {
6768 createdAt : new Date ( ) ,
6869 dimensions : {
@@ -79,6 +80,107 @@ Humanoid.prototype.greet = function () {
7980 language : 'Hamsterish' ,
8081 } ) ;
8182
83+
84+
85+
86+
87+
88+ /*
89+ Object oriented design is commonly used in video games. For this part of the assignment
90+ you will be implementing several classes with their correct inheritance heirarchy.
91+
92+ In this file you will be creating three classes:
93+ GameObject
94+ createdAt
95+ dimensions
96+ destroy() // prototype method -> returns the string 'Game object was removed from the game.'
97+ */
98+ //************************************************
99+
100+ // function GameObject(data) {
101+ // this.createdAt = data.createdAt;
102+ // this.dimensions = data.dimensions;
103+ // }
104+ // GameObject.prototype.destroy = function () {
105+ // return 'Game object was removed from the game';
106+ // }
107+
108+ //************************************************
109+ /*
110+ NPC
111+ hp
112+ name
113+ takeDamage() // prototype method -> returns the string '<object name> took damage.'
114+ // should inherit destroy() from GameObject's prototype
115+ */
116+ //************************************************
117+
118+ // function NPC (data) {
119+ // GameObject.call(this, data);
120+ // this.hp = data.hp;
121+ // this.name = data.name;
122+ // }
123+
124+ // NPC.prototype = Object.create(GameObject.prototype);
125+
126+ // NPC.prototype.takeDamage = function () {
127+ // return `${this.name} took damage`;
128+ //}
129+
130+ //************************************************
131+ /*
132+ Humanoid
133+ faction
134+ weapons
135+ language
136+ greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
137+ // should inherit destroy() from GameObject through NPC
138+ // should inherit takeDamage() from NPC
139+
140+ Inheritance chain: Humanoid -> NPC -> GameObject
141+ Instances of Humanoid should have all of the same properties as NPC and GameObject.
142+ Instances of NPC should have all of the same properties as GameObject.
143+ */
144+
145+ //***********************************************
146+
147+ // function Humanoid (data) {
148+ // NPC.call(this, data);
149+ // this.faction = data.faction;
150+ // this.weapons = data.weapons;
151+ // this.language = data.language;
152+ // }
153+
154+ // Humanoid.prototype = Object.create(NPC.prototype);
155+
156+ // Humanoid.prototype.greet = function () {
157+ // return `${this.name} offers a greeting in ${this.language}`;
158+ // }
159+
160+ //**************************************************
161+
162+ //Example:
163+
164+ //**************************************************
165+
166+ // const hamsterHuey = new Humanoid({
167+ // createdAt: new Date(),
168+ // dimensions: {
169+ // length: 2,
170+ // width: 1,
171+ // height: 1,
172+ // },
173+ // hp: 5,
174+ // name: 'Hamster Huey',
175+ // faction: 'Gooey Kablooie',
176+ // weapons: [
177+ // 'bubblegum',
178+ // ],
179+ // language: 'Hamsterish',
180+ // });
181+
182+ //***********************************************
183+
82184 hamsterHuey . greet ( ) ; // returns 'Hamster Huey offers a greeting in Hamsterish'
83185 hamsterHuey . takeDamage ( ) ; // returns 'Hamster Huey took damage.'
84186 hamsterHuey . destroy ( ) ; // returns 'Game object was removed from the game.'
0 commit comments