Beispiel #1
0
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')
Beispiel #2
0
def play():
    """Main game function. Runs game"""
    name = input('Enter your name: ')
    while True:
        option = input('Enter start if you are not a loser: ')
        if option == START:
            player = Player(name)
            level = 1
            enemy = Enemy(level)
            while True:
                try:
                    player.attack(enemy)
                    player.defence(enemy)
                except EnemyDown:
                    level += 1
                    enemy = Enemy(level)
                    player.score += 5
        elif option == SHOW_SCORES:
            with open('scores.txt', 'r') as score:
                print(score.read())
        elif option == EXIT:
            raise KeyboardInterrupt
        elif option == HELP:
            print('Option list:')
            print("\n".join(OPTIONS))
        else:
            print('You mist. Type "help" if you need help')
Beispiel #3
0
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
Beispiel #4
0
def play():
    """
    method play. :)
    """
    pl_name = input("Enter your name : ")
    player = Player(pl_name)
    level = 1
    enemy = Enemy(1)
    while True:
        try:
            player.attack(enemy)
            player.defence(enemy)
        except EnemyDown:
            level += 1
            player.score += 5
            enemy = Enemy(level)
Beispiel #5
0
def play():
    print('Enter your name: ')
    name = input()
    player = Player(name)
    level = 1
    enemy = Enemy(level)
    while player.lives > 0:
        try:
            player.attack(enemy)
            player.defence(enemy)
            print(player.score)
            print(player.lives)
        except exeptions.EnemyDown:
            level += 1
            player.score += 5
            enemy = Enemy(level)
Beispiel #6
0
def play():
    """ Method to start the game"""
    name = input("Enter your name : ")
    player = Player(name)
    start = input("Enter 'start' when you are ready for battle: ")
    if start == 'start':
        print('Get ready')
    else:
        play()
    level = 1
    enemy = Enemy(1)
    while True:
        try:
            player.attack(enemy)
            player.defense(enemy)
        except EnemyDown:
            level += 1
            player.score += 5
            enemy = Enemy(level)
def play():
    """
    - Entering the player's name
    - Creating a player object - level = 1
    - Creating an enemy object
    - calls the attack and defense
      methods of the player object in an endless loop
    - when an exception occurs, EnemyDown raises the game level,
      creates a new Enemy object with a new level,
      adds +5 points to the player."""
    level = 1
    player = Player(Inputs.input_player_name(), LIVES)
    Inputs.input_start()
    enemy = Enemy(level)

    while True:
        try:
            player.attack(enemy)
            player.defence(enemy)

        except EnemyDown:
            level += 1
            enemy = Enemy(level)
            player.score += ENEMY_DOWN_SCORE
            print(cli_color(f'{ENEMY_DOWN_STRING} {player.score}', 'c'))
            print(LIVES_STRING, player.lives)

        except GameOver:
            scores = Scores()
            # read scores from file
            try:
                scores.read_from_file(SCORE_FILE)
            except FileNotFoundError:
                pass
            # write score to scores file
            scores.new_result(player, SCORE_FILE)
            raise GameOver
Beispiel #8
0
def play():
    """Start game, input Player, attack and defense """
    player_name = input("Lets play!\nPlease enter your name:\n > ")
    while not player_name.isalpha():
        if not player_name.isalpha():
            player_name = input("You entered wrong name")
        return player_name
    player = Player(player_name)
    enemy = Enemy(1)
    print(f'score table {Score.check_scores()}')
    while True:
        try:
            print(player.attack(enemy))
            print(player.defense(enemy))
            print(f'You have {player.lives} lives')
            print(f'Enemy has {enemy.lives} lives')
        except EnemyDown:
            enemy = Enemy(enemy.level + 1)
            print(
                f'!!! ENEMY DOWN !!!\nAnother enemy appears! (level {enemy.level}).'
            )
            player.score += 5