def main(): try: name = input("Enter your name: \n").strip() if " " in name: name = name.replace(' ', '_') print(name) while True: command = input( "Enter start, exit, show scores or help\n").strip().lower() if command == 'start': user = Player(name, settings.HP, settings.SCORE, settings.ALLOWED_ATTACK) enemy = Enemy(settings.ENEMY_LEVEL) print(f'Enemy level is {settings.ENEMY_LEVEL}\n') while True: try: if user.allowed_attack: user.attack(enemy) user.allowed_attack = 0 else: user.allowed_attack = 1 user.defense(enemy) except EnemyDown as err: print("Creating new enemy") settings.ENEMY_LEVEL += 1 enemy = Enemy(settings.ENEMY_LEVEL) print(f'Enemy level is {settings.ENEMY_LEVEL}\n') user.allowed_attack = 1 user.score += 5 print(err) elif command == 'show scores': with open('scores.txt', 'r') as file: for line in file: print(line, end='') print('-' * 10) elif command == 'help': for key in settings.COMMS.keys(): print(f'command {key} {settings.COMMS[key]}') elif command == 'exit': raise KeyboardInterrupt else: print(f'unknown commad {command}') except GameOver as err: err.write_score(user) finally: print('goodbye')
def play(): level = 1 player_name = input('Enter your name Player! \n') print(f"Welcome to The Hunger Games. And may luck always be on your side! {player_name}\n") player = Player(player_name) enemy_name = 'Enemy monster' enemy = Enemy(enemy_name, level) while True: command = input( f"{player_name}, Please enter \"START\" to start the game\n" f"or enter \"HELP\" to enter setup\n") # .lower() if command == "start": print(f'Your enemy name is {enemy_name}!') while True: try: player.allowed_attack = input('Please make a choice for attack: ' '\'1\' - Wizard, \'2\' - Warrior,' ' \'3\' - Rogue \n') player.attack(enemy) print(f'Your lives: {player.lives} | {enemy_name} lives: {enemy.lives}\n') player.allowed_attack = input('Please make a choice for defence: ' '\'1\' - Wizard, \'2\' - Warrior,' ' \'3\' - Rogue \n') player.defence(enemy) print(f'Your lives: {player.lives} | {enemy_name} lives: {enemy.lives}\n') except EnemyDown: player.score += 5 player.level += 1 level += 1 print(f'\n---------------------------------------------------------\n' f' You killed {enemy_name}. Your score: ' f'{player.score}. Level: {player.level}.\n' f'---------------------------------------------------------\n') # format(self.enemy_name, )) enemy_name = 'goga' enemy = Enemy(enemy_name, level) print(f'\nYour enemy name is {enemy_name}!\n') except InvalidLiteral: print('\nONLY 3 classes of fighters!!! 1-2-3\n') elif command == "help": settings.show_commands() elif command == "show scores": print('\n') Scores.show_score() print('\n') elif command == "exit": raise KeyboardInterrupt