Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- game_results = []
- def calculate_monster_attack():
- return randint(monster["attack_min"], monster["attack_max"])
- def game_ends(winner_name):
- print(f"{winner_name} won the game")
- game_running = True
- while game_running == True:
- counter = 0
- new_round = True
- player = {"name": "Grim", "attack": 13, "heal": 160, "health": 100}
- monster = {"name": "Johan", "attack_min": 1, "attack_max": 2, "health": 100}
- print("---" * 7)
- print("What's your name?")
- player["name"] = input()
- if player["name"] == "123":
- new_round = False
- game_running = False
- else:
- print("---" * 7)
- print(player["name"] + " has " + str(player["health"]) + " health.")
- print(monster["name"] + " has " + str(monster["health"]) + " health.")
- while new_round == True:
- counter += 1
- player_won = False
- monster_won = False
- print("---" * 7)
- print("Please select action")
- print("1) Attack")
- print("2) Heal")
- print("3) Show previous results")
- print("4) Exit game")
- player_choise = input()
- if player_choise == "1":
- monster["health"] = monster["health"] - player["attack"]
- if monster["health"] <= 0:
- player_won = True
- else:
- player["health"] = player["health"] - calculate_monster_attack()
- if player["health"] <= 0:
- monster_won = True
- elif player_choise == "2":
- player["health"] = player["health"] + player["heal"]
- player["health"] = player["health"] - calculate_monster_attack()
- if player["health"] <= 0:
- monster_won = True
- elif player_choise == "3":
- for item in game_results:
- print(item)
- elif player_choise == "4":
- print("Exiting game...")
- new_round = False
- game_running = False
- else:
- print("Does not compute")
- if player_won == False and monster_won == False and new_round == True and game_running == True:
- print("---" * 7)
- print(player["name"] + " has " + str(player["health"]) + " health left.")
- print(monster["name"] + " has " + str(monster["health"]) + " health left.")
- elif player_won:
- game_ends(player["name"])
- end_results = {"Winner": player["name"], "Health left": player["health"], "Rounds": counter}
- game_results.append(end_results)
- new_round = False
- elif monster_won:
- game_ends(monster["name"])
- end_results = {"Winner": monster["name"], "Health left": monster["health"], "Rounds": counter}
- game_results.append(end_results)
- new_round = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement