Skip to content

Instantly share code, notes, and snippets.

@astery
Created October 29, 2016 18:42
Show Gist options
  • Save astery/da7714ea942b4374906cc78bea04eb6b to your computer and use it in GitHub Desktop.
Save astery/da7714ea942b4374906cc78bea04eb6b to your computer and use it in GitHub Desktop.
def health(game_persona):
return game_persona[1]
def set_health(game_persona, health):
game_persona[1] = health
def attack(game_persona):
return game_persona[2]
def set_attack(game_persona, attack):
game_persona[2] = attack
def name(game_persona):
return game_persona[0]
def persona_info(game_persona):
return "["+ name(game_persona) + "❤ " + str(health(game_persona)) + ":⚔ " + str(attack(game_persona)) + "]"
def fight_log(attacker, attacked):
return persona_info(attacker) + " " + name(attacker) + " attack " + name(attacked) + " " + persona_info(attacked)
def meet_log(left_guy, right_guy):
return persona_info(left_guy) + " <<<< VS >>>> " + persona_info(right_guy)
def fight(hero, mob):
print(meet_log(hero, mob))
while health(mob) > 0 and health(hero) > 0:
set_health(mob, health(mob) - attack(hero))
if health(mob) < 0:
set_health(mob, 0)
print(fight_log(hero, mob))
if health(mob) == 0:
break
set_health(hero, health(hero) - attack(mob))
print(fight_log(mob, hero))
hero = ["hero", 20, 7, 0]
mobs = [
["slime", 10, 1, 3],
["belzebub", 100, 1, 3]
]
for mob in mobs:
fight(hero, mob)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment