Ejemplo n.º 1
0
def main():
    '''The main entry point for the game Go Fish'''
    ui = UserInterface()
    g = Game()
    #welcom the user
    auto = ui.welcome()
    #deal the cards
    g.deal()
    ui.print_player_hand(g.player1.hand)
    while not g.game_over():
        if not auto:
            #ask the user for a value
            value = ui.request_fish()
            #attempt to get the cards from the opponent
            computer_transfers = g.player_turn(value)
            #display the transaction to the user
            ui.display(computer_transfers, g.player1_turn)
        #ask the computer for a value
        #and attempt to get the cards from the opponent
        player_transfers = g.auto_turn()
        #display the result
        ui.display(player_transfers, g.player1_turn)
        #print the player's hand
        ui.print_player_hand(g.player1.hand)
        #print the books on the table
        ui.print_books(g.player1.books, g.player2.books)
    #print the winner
    ui.print_winner(g.tally_scores())
Ejemplo n.º 2
0
def test_game_deal():
    """
  A hand is dealt to a player and a dealer.
  """
    def _random(start, end):
        return start

    game = Game(_random=_random)
    game.deal()

    hidden_card = Card('Clubs', '4')
    hidden_card.set_hidden(True)
    expected_dealer_cards = [Card('Clubs', '2'), hidden_card]
    expected_player_cards = [Card('Spades', 'Ace'), Card('Clubs', '3')]

    actual_dealer_cards = game.get_dealer().get_hand().get_cards()
    actual_player_cards = game.get_player().get_hand().get_cards()

    assert len(actual_dealer_cards) == len(expected_dealer_cards)
    for i in range(len(actual_dealer_cards)):
        assert actual_dealer_cards[i].get_suit(
        ) == expected_dealer_cards[i].get_suit()
        assert actual_dealer_cards[i].get_pip(
        ) == expected_dealer_cards[i].get_pip()
        assert actual_dealer_cards[i].get_hidden(
        ) == expected_dealer_cards[i].get_hidden()

    assert len(actual_player_cards) == len(expected_player_cards)
    for i in range(len(actual_player_cards)):
        assert actual_player_cards[i].get_suit(
        ) == expected_player_cards[i].get_suit()
        assert actual_player_cards[i].get_pip(
        ) == expected_player_cards[i].get_pip()
        assert actual_player_cards[i].get_hidden(
        ) == expected_player_cards[i].get_hidden()
Ejemplo n.º 3
0
def main():

    game = Game()

    game.create_players('Justin')
    game.create_players('Katrin')
    game.create_players('Sophie')

    game.shuffle_deck()
    game.deal()
    game.get_chip_count()