#-------------------------------------------------------------------------- # Name : Hasib # Purpose : 11DGT # Author: Hasib # Created : 12/02/2024 # Copyright : © Hasib 19/02/2024 #-------------------------------------------------------------------------- # Set starting variables ----------------------------------- import random def get_player_input(): return input("[A]ttack [D]efend [M]agic [S]hield: ").lower() def player_attack(): return random.randint(10, 20) def thanos_attack(): return random.randint(10, 20) def player_defend(): return random.randint(5, 10) def thanos_defend(): return random.randint(5, 10) def player_magic(): return random.randint(15, 25) def player_shield(): return random.randint(5, 15) def game_round(player_hp, thanos_hp): print(f"\n--- Your Turn ---") player_choice = get_player_input() if player_choice == "a": player_damage = player_attack() thanos_hp -= player_damage print(f"You attacked Thanos and dealt {player_damage} damage!") elif player_choice == "d": player_damage = player_defend() thanos_hp -= player_damage print(f"You defended against Thanos and took {player_damage} damage!") elif player_choice == "m": player_damage = player_magic() thanos_hp -= player_damage print(f"You used magic against Thanos and dealt {player_damage} damage!") elif player_choice == "s": player_damage = player_shield() player_hp += player_damage print(f"You raised a shield and gained {player_damage} HP!") if thanos_hp > 0: print(f"\n--- Thanos' Turn ---") thanos_damage = thanos_attack() player_hp -= thanos_damage print(f"Thanos attacked you and dealt {thanos_damage} damage!") return player_hp, thanos_hp def main(): player_name = input("Enter your name: ") player_score = 0 thanos_score = 0 for round_num in range(1, 3): print(f"\n--- Round {round_num} ---") player_hp = 100 thanos_hp = 100 player_hp, thanos_hp = game_round(player_hp, thanos_hp) if player_hp <= 0: print("Game Over! Thanos wins this round!") thanos_score += 1 elif thanos_hp <= 0: print("Congratulations! You won this round!") player_score += 1 # Tiebreaker round if needed if player_score == thanos_score: print("\n--- Tiebreaker Round ---") player_hp = 100 thanos_hp = 100 player_hp, thanos_hp = game_round(player_hp, thanos_hp) if player_hp <= 0: print("Game Over! Thanos wins the Tiebreaker Round!") thanos_score += 1 elif thanos_hp <= 0: print("Congratulations! You won the Tiebreaker Round!") player_score += 1 print("\n--- Final Scores ---") print(f"{player_name}: {player_score} | Thanos: {thanos_score}") if player_score > thanos_score: print("Congratulations! You have defeated Thanos!") elif player_score < thanos_score: print("Sorry, Thanos has won. The universe is doomed!") else: print("It's a tie! The fate of the universe hangs in the balance.") if __name__ == "__main__": main()