|
1 | 1 | /**
|
| 2 | + * Class => Item(name) |
| 3 | + * ----------------------------- |
2 | 4 | * Creates an item.
|
3 | 5 | *
|
4 | 6 | * @name Item
|
|
8 | 10 |
|
9 | 11 |
|
10 | 12 | /**
|
| 13 | + * Class => Weapon(name, damage) |
| 14 | + * ----------------------------- |
11 | 15 | * Creates a weapon item.
|
12 | 16 | * Weapon items can be equipped for use in battle.
|
13 | 17 | *
|
14 |
| - * Use the call method on the Item constructor. |
15 |
| - * Set Weapon's prototype to a new instance of Item. |
| 18 | + * The Weapon class constructor will call |
| 19 | + * the super class (Item) constructor |
| 20 | + * while passing in the 1 Item constructor param |
16 | 21 | *
|
17 | 22 | * @name Weapon
|
18 | 23 | * @param {string} name The weapon's name.
|
|
22 | 27 |
|
23 | 28 |
|
24 | 29 | /**
|
| 30 | + * Weapon Extends Item Class |
| 31 | + * ----------------------------- |
| 32 | + */ |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +/** |
| 37 | + * Class => Food(name, energy) |
| 38 | + * ----------------------------- |
25 | 39 | * Creates a food item.
|
26 | 40 | * Food items give energy, restoring health to the player.
|
27 | 41 | *
|
28 |
| - * Use the call method on the Item constructor. |
29 |
| - * Set Food's prototype to a new instance of Item. |
| 42 | + * The Food class constructor will call |
| 43 | + * the super class (Item) constructor |
| 44 | + * while passing in the 1 Item constructor param |
30 | 45 | *
|
31 | 46 | * @name Food
|
32 | 47 | * @param {string} name The food's name.
|
|
36 | 51 |
|
37 | 52 |
|
38 | 53 | /**
|
| 54 | + * Food Extends Item Class |
| 55 | + * ----------------------------- |
| 56 | + */ |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +/** |
| 61 | + * Class => Player(name, health, strength, speed) |
| 62 | + * ----------------------------- |
39 | 63 | * Creates a player in a zombie-infested world.
|
40 | 64 | *
|
41 | 65 | * @name Player
|
|
57 | 81 |
|
58 | 82 |
|
59 | 83 | /**
|
| 84 | + * Player Class Method => checkPack() |
| 85 | + * ----------------------------- |
60 | 86 | * Player checks the contents of their pack.
|
61 | 87 | *
|
62 | 88 | * Nicely format and print the items in the player's pack.
|
|
68 | 94 |
|
69 | 95 |
|
70 | 96 | /**
|
| 97 | + * Player Class Method => takeItem(item) |
| 98 | + * ----------------------------- |
71 | 99 | * Player takes an item from the world and places it into their pack.
|
72 | 100 | *
|
73 | 101 | * Player's pack can only hold a maximum of 3 items, so if they try to add more
|
|
85 | 113 |
|
86 | 114 |
|
87 | 115 | /**
|
| 116 | + * Player Class Method => discardItem(item) |
| 117 | + * ----------------------------- |
88 | 118 | * Player discards an item from their pack.
|
89 | 119 | *
|
90 | 120 | * Use Array's indexOf method to check if the pack contains the item.
|
|
110 | 140 |
|
111 | 141 |
|
112 | 142 | /**
|
| 143 | + * Player Class Method => equip(itemToEquip) |
| 144 | + * ----------------------------- |
113 | 145 | * Player equips a weapon item.
|
114 | 146 | *
|
115 | 147 | * Player can only equip Weapon instances.
|
|
129 | 161 |
|
130 | 162 |
|
131 | 163 | /**
|
| 164 | + * Player Class Method => eat(itemToEat) |
| 165 | + * ----------------------------- |
132 | 166 | * Player eats a food item, restoring their health.
|
133 | 167 | *
|
134 | 168 | * Player can only eat Food instances.
|
|
147 | 181 |
|
148 | 182 |
|
149 | 183 | /**
|
| 184 | + * Player Class Method => useItem(item) |
| 185 | + * ----------------------------- |
150 | 186 | * Player uses an item from the pack.
|
151 | 187 | *
|
152 | 188 | * If the item is a weapon, the player should equip the item.
|
|
159 | 195 |
|
160 | 196 |
|
161 | 197 | /**
|
| 198 | + * Player Class Method => equippedWith() |
| 199 | + * ----------------------------- |
162 | 200 | * Player checks their equipment.
|
163 | 201 | *
|
164 | 202 | * Prints the player's name and equipped weapon's name.
|
|
172 | 210 |
|
173 | 211 |
|
174 | 212 | /**
|
| 213 | + * Class => Zombie(health, strength, speed) |
| 214 | + * ----------------------------- |
175 | 215 | * Creates a normal zombie.
|
176 | 216 | *
|
177 | 217 | * @name Zombie
|
|
187 | 227 |
|
188 | 228 |
|
189 | 229 | /**
|
| 230 | + * Class => FastZombie(health, strength, speed) |
| 231 | + * ----------------------------- |
190 | 232 | * Creates a fast zombie.
|
191 | 233 | *
|
192 |
| - * Use the call method on the Zombie constructor. |
193 |
| - * Set FastZombie's prototype to a new instance of Zombie. |
| 234 | + * The FastZombie class constructor will call |
| 235 | + * the super class (Zombie) constructor |
| 236 | + * while passing in the 3 Zombie constructor params |
194 | 237 | *
|
195 | 238 | * @name FastZombie
|
196 | 239 | * @param {number} health The zombie's health.
|
|
200 | 243 |
|
201 | 244 |
|
202 | 245 | /**
|
| 246 | + * FastZombie Extends Zombie Class |
| 247 | + * ----------------------------- |
| 248 | + */ |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | +/** |
| 253 | + * Class => StrongZombie(health, strength, speed) |
| 254 | + * ----------------------------- |
203 | 255 | * Creates a strong zombie.
|
204 | 256 | *
|
205 |
| - * Use the call method on the Zombie constructor. |
206 |
| - * Set StrongZombie's prototype to a new instance of Zombie. |
| 257 | + * The StrongZombie class constructor will call |
| 258 | + * the super class (Zombie) constructor |
| 259 | + * while passing in the 3 Zombie constructor params |
207 | 260 | *
|
208 | 261 | * @name StrongZombie
|
209 | 262 | * @param {number} health The zombie's health.
|
|
213 | 266 |
|
214 | 267 |
|
215 | 268 | /**
|
| 269 | + * StrongZombie Extends Zombie Class |
| 270 | + * ----------------------------- |
| 271 | + */ |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | +/** |
| 276 | + * Class => RangedZombie(health, strength, speed) |
| 277 | + * ----------------------------- |
216 | 278 | * Creates a ranged zombie.
|
217 | 279 | *
|
218 |
| - * Use the call method on the Zombie constructor. |
219 |
| - * Set RangedZombie's prototype to a new instance of Zombie. |
| 280 | + * The RangedZombie class constructor will call |
| 281 | + * the super class (Zombie) constructor |
| 282 | + * while passing in the 3 Zombie constructor params |
220 | 283 | *
|
221 | 284 | * @name RangedZombie
|
222 | 285 | * @param {number} health The zombie's health.
|
|
226 | 289 |
|
227 | 290 |
|
228 | 291 | /**
|
| 292 | + * StrongZombie Extends Zombie Class |
| 293 | + * ----------------------------- |
| 294 | + */ |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | +/** |
| 299 | + * Class => ExplodingZombie(health, strength, speed) |
| 300 | + * ----------------------------- |
229 | 301 | * Creates an exploding zombie.
|
230 | 302 | *
|
231 |
| - * Use the call method on the Zombie constructor. |
232 |
| - * Set ExplodingZombie's prototype to a new instance of Zombie. |
| 303 | + * The ExplodingZombie class constructor will call |
| 304 | + * the super class (Zombie) constructor |
| 305 | + * while passing in the 3 Zombie constructor params |
233 | 306 | *
|
234 | 307 | * @name ExplodingZombie
|
235 | 308 | * @param {number} health The zombie's health.
|
|
238 | 311 | */
|
239 | 312 |
|
240 | 313 |
|
| 314 | +/** |
| 315 | + * ExplodingZombie Extends Zombie Class |
| 316 | + * ----------------------------- |
| 317 | + */ |
| 318 | + |
| 319 | + |
| 320 | + |
| 321 | + |
241 | 322 | /**
|
242 | 323 | * Sample run.
|
243 | 324 | * Feel free to edit this and check your game logic.
|
|
0 commit comments