def play_game(puzzle: str, remaining_words: List[str]) -> None:
    """Prompt the players to guess words that occur in the puzzle.  Print
    the score after each turn.  Print the winner.
    """

    # Whether it's player one's turn. If False, it's player two's turn.
    player_one_turn = True

    # The scores for the two players.
    player_one_score = 0
    player_two_score = 0

    print('''***************************************
**       Where's That Word?          **
***************************************''')

    # Prompt for a guess and add up the points until the game is over.
    while not game_over(remaining_words):

        print_puzzle(puzzle)
        print('the words left to be found: ')
        print_words(remaining_words)

        # Get the name of the player whose turn it is.
        current_player_name = puzzle_functions.get_current_player(
            player_one_turn)

        # Have the player take their turn and get the score.
        points = take_turn(puzzle, remaining_words, current_player_name)

        if (points == 0):
            print("incorrect guess :-(")
        else:
            print("correct guess!!!")

        # Update the score for whoever's turn it is.
        if player_one_turn:
            player_one_score = player_one_score + points
            current_player_score = player_one_score
        else:
            player_two_score = player_two_score + points
            current_player_score = player_two_score

        print(current_player_name + "'s score is " +
              str(current_player_score) + "\n")

        player_one_turn = not player_one_turn

    print(
        'woohoo!!! ',
        puzzle_functions.get_winner(player_one_score, player_two_score) +
        '!!!')
Ejemplo n.º 2
0
def play_game(puzzle, words):
    """ (str, list of words) -> Nonetype

    Prompt the players to guess words that occur in the puzzle.
    Print the score after each turn.  Print the winner.
    """

    # Whether it's Player One's turn; if False, it's Player Two's turn.
    player_one_turn = True

    # The scores for the two players.
    player_one_score = 0
    player_two_score = 0

    print('''***************************************
**       Where's That Word?          **
***************************************''')

    # Prompt for a guess and add up the points until the game is over.
    while not game_over(words):

        print_puzzle(puzzle)
        print_words(words)

        # Get the name of the player whose turn it is.
        current_player_name = \
            puzzle_functions.get_current_player(player_one_turn)

        # Have the player take their turn and get the score.
        score = take_turn(puzzle, words, current_player_name)

        # Update the score for whoever's turn it is.
        if player_one_turn:
            player_one_score = player_one_score + score
            print(current_player_name + "'s score is " +
                  str(player_one_score) + '.\n')
        else:
            player_two_score = player_two_score + score
            print(current_player_name + "'s score is " +
                  str(player_two_score) + '.\n')

        player_one_turn = not player_one_turn

    print(puzzle_functions.get_winner(player_one_score, player_two_score))
Ejemplo n.º 3
0
def play_game(puzzle, words):
    """ (str, list of words) -> Nonetype

    Prompt the players to guess words that occur in the puzzle.
    Print the score after each turn.  Print the winner.
    """

    # Whether it's Player One's turn; if False, it's Player Two's turn.
    player_one_turn = True

    # The scores for the two players.
    player_one_score = 0
    player_two_score = 0

    print('''***************************************
**       Where's That Word?          **
***************************************''')

    # Prompt for a guess and add up the points until the game is over.
    while not game_over(words):

        print_puzzle(puzzle)
        print_words(words)

        # Get the name of the player whose turn it is.
        current_player_name = \
            puzzle_functions.get_current_player(player_one_turn)

        # Have the player take their turn and get the score.
        score = take_turn(puzzle, words, current_player_name)

        # Update the score for whoever's turn it is.
        if player_one_turn:
            player_one_score = player_one_score + score
            print(current_player_name + "'s score is " +
                  str(player_one_score) + '.\n')
        else:
            player_two_score = player_two_score + score
            print(current_player_name + "'s score is " +
                  str(player_two_score) + '.\n')

        player_one_turn = not player_one_turn

    print(puzzle_functions.get_winner(player_one_score, player_two_score))
Ejemplo n.º 4
0
functions. Before submitting your assignment, run this type-checker on your
puzzle_functions.py. If errors occur when you run this module, fix them
before you submit your assignment.  

When this module runs, if nothing is displayed and no errors occur, then the
type checks passed. This means that the function parameters and return types
match the assignment specification, but it does not mean that your code works
correctly in all situations. Be sure to test your code before submitting.'''

import puzzle_functions as pf

# Get the initial values of the constants
constants_before = [pf.FORWARD_FACTOR, pf.DOWN_FACTOR, pf.BACKWARD_FACTOR,
                    pf.UP_FACTOR]
# Type check pf.get_current_player
result = pf.get_current_player(True)
assert isinstance(result, str), \
       '''pf.get_current_player should return a str, but returned {0}
       .'''.format(type(result))

# Type check pf.get_winner
result = pf.get_winner(17,32)
assert isinstance(result, str), \
       '''pf.get_winner should return a str, but returned {0}.''' \
       .format(type(result))

# Type check pf.get_factor
result = pf.get_factor('forward')
assert isinstance(result, int), \
       '''pf.get_factor should return an int, but returned {0}.''' \
       .format(type(result))
Ejemplo n.º 5
0
CONSTS_BEFORE = [
    pf.FORWARD_FACTOR, pf.DOWN_FACTOR, pf.BACKWARD_FACTOR, pf.UP_FACTOR
]


def type_error_message(func_name: str, expected: str, got) -> str:
    """Return an error message for function func_name returning type got,
    where the correct return type is expected."""

    return ('{0} should return a {1}, but returned {2}' + '.').format(
        func_name, expected, got)


# Type check puzzle_functions.get_current_player
print('Checking get_current_player...')
got = pf.get_current_player(True)
assert isinstance(got, str), \
    type_error_message('puzzle_functions.get_current_player', 'str', type(got))
print('  check complete')

# Type check puzzle_functions.get_winner
print('Checking get_winner...')
got = pf.get_winner(17, 32)
assert isinstance(got, str), \
    type_error_message('puzzle_functions.get_winner', 'str', type(got))
print('  check complete')

# Type check puzzle_functions.reverse
print('Checking reverse...')
got = pf.reverse('hello')
assert isinstance(got, str), \