Welcome, brave code golfer! Today you will stand in the midst of a great battle between a goblin and an elf!
goblin attacks elf! elf dodges! elf attacks goblin! elf hits goblin for 13 damage! goblin has 37 health left. goblin attacks elf! goblin hits elf for 1 damage! elf has 49 health left. elf attacks goblin! elf hits goblin for 19 damage! goblin has 18 health left. goblin attacks elf! goblin hits elf for 26 damage! elf has 23 health left. elf attacks goblin! elf hits goblin for 20 damage! goblin has been slain!
Your challenge is to simulate a battle, like the above one. You will recieve input in this form:
creatureName health strength defense accuracy agility
For example, the battle between the goblin and elf would be:
goblin 50 40 35 3 2 elf 50 35 30 4 5
The first and second creatures will alternate attacks.
- Print 'creatureName attacks otherCreatureName!'
- Check to see if the creature dodges. The creature will dodge an attack if (its agility times rand() divided by 2) is greater than (the attacker's accuracy times rand()).
- If the creature dodges, print 'creatureName dodges!'
- Otherwise, calculate the damage dealt by subtracting (the attacker's strength times rand()) and (the defender's defense times rand() divided by 2). Minimum damage is 1. Print 'creatureName hits otherCreatureName for (x) damage!' Then print 'creatureName has (x) health left.' unless the creature's health is 0 or less, in which case...
- If the creature's health is 0 or less, print 'creatureName has been slain!' and end the program.
- Shortest code wins.
- Don't literally print 'creatureName,' but replace it with the creature's name. Don't print '(x) damage' or '(x) health;' replace them with the actual amount. (I have to specify this because some people are very creative with bending the rules. :P)