Skip to content

Commit 7ab5a53

Browse files
committed
Move calculateAttackDamage and related functions to attack-damage branch
1 parent 81d8ceb commit 7ab5a53

File tree

3 files changed

+3
-665
lines changed

3 files changed

+3
-665
lines changed

README.md

-158
Original file line numberDiff line numberDiff line change
@@ -257,161 +257,3 @@ Set ExplodingZombie's prototype to a new instance of Zombie.
257257
`health`: number, The zombie's health.
258258
`strength`: number, The zombie's strength.
259259
`speed`: number, The zombie's speed.
260-
261-
262-
calculateAttackDamage(creature)
263-
-----------------------------
264-
*Calculates the attack damage of a creature instance.*
265-
266-
Use `instanceof` to determine what type of object the creature is.
267-
Then, based on the type, set a variable called `randomizer` equal to a `Math.floor((Math.random() * x) + y)` formula to achieve the following random values:
268-
-- Player: `2, 3, 4`
269-
-- Zombie: `5, 6, 7`
270-
-- FastZombie: `2, 3, 4, 5`
271-
-- StrongZombie: `2, 3, 4, 5, 6, 7, 8, 9`
272-
-- RangedZombie: `2, 3, 4, 5, 6, 7`
273-
-- ExplodingZombie: `3, 4, 5`
274-
Lastly, set the damage to the following formula and return this damage:
275-
`Math.floor((creature.strength / randomizer) + (Math.log(creature.speed) / randomizer * 10))`.
276-
277-
**Parameters**
278-
`creature`: Player/Zombie/FastZombie/StrongZombie/RangedZombie/ExplodingZombie, The creature instance whose attack damage is to be calculated.
279-
280-
**Returns**: number, The amount of damage the creature will inflict.
281-
282-
283-
takeDamage(damage)
284-
-----------------------------
285-
*Zombie takes damage.*
286-
287-
The zombie's health decreases by the amount of damage taken.
288-
The zombie's health should not drop lower than 0.
289-
If the zombie's health is 0, set their `isAlive` property to false.
290-
If the zombie is dead, print a message that the zombie is slain.
291-
You should be able to invoke this function on a Zombie instance.
292-
293-
**Parameters**
294-
`damage`: number, The amount of damage the zombie receives.
295-
296-
297-
attack(zombie)
298-
-----------------------------
299-
*Player attacks a zombie.*
300-
301-
Calculate the player's base attack damage by passing this instance to the `calculateAttackDamage` function.
302-
303-
If the player has a weapon equipped, print a message with the weapon's name.
304-
The total damage then becomes the base player damage plus the weapon damage.
305-
306-
If the player has no weapon equipped, print any weaponless attack to console.
307-
In this case, the total damage is just the base player damage.
308-
309-
The zombie then takes all this damage.
310-
You should be able to invoke this function on a Player instance.
311-
312-
**Parameters**
313-
`zombie`: Zombie, The zombie to attack.
314-
315-
**Returns**: number, Damage dealt by attacking.
316-
317-
318-
takeDamage(damage)
319-
-----------------------------
320-
*Player takes damage.*
321-
322-
The player's health decreases by the amount of damage taken.
323-
The player's health should not drop lower than 0.
324-
If the player's health is 0, set their `isAlive` property to false.
325-
If the player is dead, print a message that they're dead and the game is over.
326-
You should be able to invoke this function on a Player instance.
327-
328-
**Parameters**
329-
`damage`: number, The amount of damage the player receives.
330-
331-
332-
attack(player)
333-
-----------------------------
334-
*Zombie attacks a player.*
335-
336-
Calculate the zombie's attack damage by passing this instance to the `calculateAttackDamage` function. Player takes this amount of damage.
337-
Print any zombie attack message you'd like; just include the player's name.
338-
You should be able to invoke this function on a Zombie instance.
339-
340-
**Parameters**
341-
`player`: Player, The player to attack.
342-
343-
**Returns**: number, Damage dealt by attacking.
344-
345-
346-
charge(player)
347-
-----------------------------
348-
*FastZombie charges at full speed.*
349-
350-
Calculate the zombie's base attack damage by passing this instance to the `calculateAttackDamage` function. Player takes this amount of damage.
351-
Print any zombie charge message you'd like; just include the player's name.
352-
353-
Player takes additional damage if the zombie's speed is greater than the player's.
354-
Additional damage should equal the floor of half the base zombie attack damage.
355-
356-
You should be able to invoke this function on a FastZombie instance.
357-
358-
**Parameters**
359-
`player`: Player, The player to charge at.
360-
361-
**Returns**: number, Damage dealt by charging.
362-
363-
364-
crush(player)
365-
-----------------------------
366-
*StrongZombie crushes with might.*
367-
368-
Calculate the zombie's base attack damage by passing this instance to the `calculateAttackDamage` function. Player takes this amount of damage.
369-
Print any zombie crush message you'd like; just include the player's name.
370-
371-
Player takes additional damage if the zombie's strength is greater than the player's.
372-
Additional damage should equal the floor of 80% of the base zombie attack damage.
373-
374-
You should be able to invoke this function on a StrongZombie instance.
375-
376-
**Parameters**
377-
`player`: Player, The player to crush.
378-
379-
**Returns**: number, Damage dealt by crushing.
380-
381-
382-
spit(player)
383-
-----------------------------
384-
*RangedZombie spits toxic ooze from afar.*
385-
386-
Calculate the zombie's base attack damage by passing this instance to the `calculateAttackDamage` function. Player takes this amount of damage.
387-
Print any zombie spit message you'd like; just include the player's name.
388-
389-
Player takes additional damage if their current health is less than half of max health.
390-
Additional damage should equal the floor of 70% of the base zombie attack damage.
391-
392-
You should be able to invoke this function on a RangedZombie instance.
393-
394-
**Parameters**
395-
`player`: Player, The player to spit at.
396-
397-
**Returns**: number, Damage dealt by spitting.
398-
399-
400-
explode(player)
401-
-----------------------------
402-
*ExplodingZombie explodes burning flesh and guts in every direction.*
403-
404-
Calculate the zombie's base attack damage by passing this instance to the `calculateAttackDamage` function. Player takes this amount of damage.
405-
Print any zombie explode message you'd like; just include the player's name.
406-
407-
Player takes additional damage if the zombie's speed is greater than the player's and the player's current health is less than half of max health.
408-
Additional damage should equal twice the base zombie attack damage.
409-
410-
ExplodingZombie should now be dead (health set to 0, `isAlive` set to false).
411-
412-
You should be able to invoke this function on an ExplodingZombie instance.
413-
414-
**Parameters**
415-
`player`: Player, The player to explode by.
416-
417-
**Returns**: number, Damage dealt by exploding.

0 commit comments

Comments
 (0)