Exemplo n.º 1
0
def run(game: ModuleType):
    """Starts the game."""
    user_name = welcome_and_acknowledge_user()
    tell_rules(game.RULE)
    for _ in range(0, ROUNDS):
        question, right_answer = game.get_round_data()
        ask_question(question)
        answer = get_answer()
        if answer == right_answer:
            print('Correct!')
        else:
            return loose(answer, right_answer, user_name)
    return congratulate(user_name)
Exemplo n.º 2
0
def game_beginning(game_name):
    name = greeting(game_name)

    for i in range(ROUNDS_COUNT):
        data, correct_answer, _ = game_name()
        ask_question(data)
        answer = string("Your answer: ")
        if answer != correct_answer:
            print(
                f"""{answer} is wrong answer ;(. Correct answer was {correct_answer}
                        Let's try again, {name}!""")
            return
        print('Correct!')
    print(f'My Congratulations, {name}')
Exemplo n.º 3
0
def run(game):
    print("Welcome to the Brain Games!")
    user_name = cli.ask_question("May I have your name? ")
    print(f"Hello, {user_name}!")
    print(game.GAME_DESCRIPTION)
    counter = 0
    while counter < ROUNDS:
        question, answer = game.get_question_answer()
        print(question)
        user_answer = cli.ask_question("Your answer: ")
        if user_answer == answer:
            print("Correct!")
            counter += 1
        else:
            print(f"Let's try again, {user_name}!")
            return
    print(f"Congratulations, {user_name}!")
Exemplo n.º 4
0
def play_game(game_module, user_name: str = None):
    """Play game."""
    cli.print_rules(game_module.RULES)
    if not user_name:
        user_name = cli.welcome_user()
    for _ in range(GAME_ROUNDS_NUMBER):
        question, correct_answer = game_module.create_game_parameters()
        cli.ask_question(question)
        user_answer = cli.take_str_answer()
        if user_answer != correct_answer:
            cli.print_when_lose_game(
                user_name,
                user_answer,
                correct_answer,
            )
            return
        cli.print_when_right_answer()
    cli.print_when_win_game(user_name)
Exemplo n.º 5
0
def run(game):
    """Logic module for all games.

    Args:
        game: game module with game conditions and ruels
    """
    cli.welcome_message(game.RULES)
    username = cli.welcome_player()
    for _ in range(COUNT_OF_QUESTIONS):
        phrase, correct_answer = game.run()
        cli.ask_question(phrase)
        user_answer = cli.get_answer()
        if user_answer != correct_answer:
            cli.inform_wrong(user_answer, correct_answer, username)
            break
        cli.inform_right()
    else:
        cli.congratulate(username)
Exemplo n.º 6
0
def run(game):
    cli.greet(game.GAME_DESCRIPTION)
    name = cli.ask_name()
    player_won = True
    counter = 0
    while counter < 3:
        (question, correct_answer) = game.create_question()
        answer = cli.ask_question(question)
        if answer == correct_answer:
            print("Correct!")
            counter = counter + 1
        else:
            print(WRONG_ANSWER_MESSAGE.format(answer, correct_answer))
            player_won = False
            break
    message = WIN_MESSAGE if player_won else LOSE_MESSAGE
    print(message.format(name))
Exemplo n.º 7
0
def run_game(game, number_of_rounds=3):

    print('Welcome to the Brain Games!')
    print(game.DESCRIPTION)
    name = cli.welcome_user()

    counter = 0
    while counter < number_of_rounds:
        question, correct_answer = game.generate()
        answer = cli.ask_question('Question: {0}'.format(question))
        if answer == correct_answer:
            print('Correct!')
            counter += 1
        else:
            print("'{0}' is wrong answer ;(. Correct answer was '{1}'.".format(
                answer,
                correct_answer,
            ))
            print("Let's try again, {0}!".format(name))
            break

    if counter == 3:
        print('Congratulations, {0}!'.format(name))
Exemplo n.º 8
0
def main():
    print("Welcome to the Brain Games!")
    user_name = cli.ask_question("May I have your name? ")
    print(f"Hello, {user_name}!")