Ejemplo n.º 1
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.º 2
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))