예제 #1
0
def main():
    """
    Play a game of uno
    """
    # Set up the MVC components.
    print("Welcome to Uno!\n \
        Here are the rules:\n \
        1. Match the card in the middle by either color or number\n \
        2. Watch out for action cards! Plus Two, Skip, Reverse, and Wild Cards\n \
        3. If you are at one card and the game prompts you with: \n\t\"Hit enter once you are finished with your turn\"\n \
        Please type \"Uno!\" or else you will get extra cards\n \
        4. Do not look at other player cards!\n\n")
    continue_game = "y"
    while continue_game == "y":
        uno_set = Deck()
        uno_controller = TextController(uno_set)
        names = uno_controller.start()
        uno_game = PlayGame(uno_set, names)
        uno_set.game_start()
        view = TextView(uno_game)
        while not uno_game.check_win():
            view.display()
            uno_game.play()
        for player in uno_game.player_list:
            if player.check_empty():
                uno_game.win_message(player)
                continue_game = input(
                    "Do you want to continue play again? y/n: ")
    print("Thanks for playing!")
예제 #2
0
def test_shuffle():
    """
    Checks that the shuffle method works properly and the list of cards is randomized
    """
    uno_deck = Deck()
    uno_cards = [] + uno_deck.cards
    uno_deck.shuffle()
    shuffled_uno_cards = [] + uno_deck.cards
    assert uno_cards != shuffled_uno_cards
예제 #3
0
def test_deck_check_action(card, is_action):
    """
    Checks that when given an action card check_action results in true otherwise false

    Args:
        card: a card to be checked
        is_action: a boolean representing the expected result of check_action
    """
    uno_deck = Deck()
    assert uno_deck.check_action(card) == is_action
예제 #4
0
def test_deck_check_match(card, is_match):
    """
    Checks that the average image finder returns an average of all the images in the list
    using our second color averaging method.

    Args:
        image_list: a list representing the images to average.
        resulting_image: a image representing the expected resulting average image.
    """
    uno_deck = Deck()
    uno_deck.game_start()

    assert uno_deck.check_match(card) == is_match
예제 #5
0
def test_draw_card_played(set_direction, set_current_player, number_of_cards,
                          card_count_next_player, next_player):
    """
    Checks that a player playing a draw card updates the game correctly by giving the proper count
    of cards to the next player and skipping them

    Args:
        set_direction: a int representing the direction 1 for forward and -1 for reverse
        set_current_player: a int representing the current player
        number_of_cards: a int representing the number of cards the next player must draw
        card_count_next_player: a int representing the expected amount of cards the next player
            must hold afterwards
        next_player: a int representing the expected next_player
    """
    uno_deck = Deck()
    uno_game = PlayGame(uno_deck, ["0", "1", "2", "3"])
    uno_game.direction = set_direction
    uno_game.current_player = set_current_player
    uno_game.draw_card_played(number_of_cards)
    cards_next_player = len(uno_game.player_list[set_current_player +
                                                 set_direction].hand)
    new_player = uno_game.next_player()

    assert (cards_next_player, new_player) == (card_count_next_player,
                                               next_player)
예제 #6
0
def test_deck_draw(number_cards_pulled, resulting_deck_count,
                   resulting_draw_count):
    """
    Checks that the draw method is properly updating the deck and returning the
    correct amount of cards

    Args:
        number_cards_pulled: a int representing the number of calls to draw from the deck
        resulting_deck_count: a int representing the updated count of cards in the deck
        resulting_draw_count: a int representing the number of cards returned from draw
    """
    shuffled_uno_deck = Deck()
    shuffled_uno_deck.shuffle()
    drawn_cards = shuffled_uno_deck.draw(number_cards_pulled)

    assert (len(shuffled_uno_deck.cards), len(drawn_cards)) == \
        (resulting_deck_count, resulting_draw_count)
예제 #7
0
def test_deck(resulting_card_count, resulting_middle_count):
    """
    Checks that a deck is being created with all 112 cards and the middle is empty

    Args:
        resulting_card_count: a int representing the total cards in the deck
        resulting_middle_count: a int representing the total cards in the middle
    """
    uno_deck = Deck()
    assert (len(uno_deck.cards), len(uno_deck.middle)) == \
        (resulting_card_count, resulting_middle_count)
예제 #8
0
def test_player_display_name(player_name, returned_name):
    """
    Checks that display_name returns the proper player name

    Args:
        player_name: a string representing the player name
        returned_name: a string representing the expected outcome
    """
    uno_deck = Deck()
    uno_player = Player(uno_deck, player_name)
    assert uno_player.display_name() == returned_name
예제 #9
0
def test_playgame_check_for_matches(middle_card, set_player_hand,
                                    set_card_deck, resulting_player_hand_len):
    """
    Checks that the check matches pulls from the deck until a match is found if
    there no match in the hand already

    Args:
        middle_card: a list representing the current middle card
        set_player_hand: a list representing the current player hand
        set_card_deck: a list representing the current cards in the deck
        resulting_player_hand_len: a int representing the updated length of the player hand
    """
    uno_deck = Deck()
    uno_deck.middle = middle_card
    uno_game = PlayGame(uno_deck, ["0", "1", "2", "3"])
    uno_deck.cards = set_card_deck
    uno_game.player_list[0]._hand = set_player_hand
    uno_game.check_for_matches(uno_game.player_list[0])
    length_of_hand = len(uno_game.player_list[0].hand)

    assert length_of_hand == resulting_player_hand_len
예제 #10
0
def test_player_draw(number_cards_pulled, number_cards_in_hand):
    """
    Checks that the draw method in player correctly updates the player's hand

    Args:
        number_cards_pulled: a int representing the number of cards to draw
        number_cards_in_hands: a int representing the resulting number of cards in the
            players hand
    """
    uno_deck = Deck()
    uno_player = Player(uno_deck, "name")
    uno_player.draw(number_cards_pulled)
    assert len(uno_player.hand) == number_cards_in_hand
예제 #11
0
def test_reverse_played(set_direction, new_direction):
    """
    Checks that the reverse_played method properly changes the direction

    Args:
        set_direction: a int representing the current direction of the game
        new_direction: a int representing the expected new direction of the game
    """
    uno_deck = Deck()
    uno_game = PlayGame(uno_deck, ["0", "1", "2", "3"])
    uno_game.direction = set_direction
    uno_game.reverse_card_played()

    assert uno_game.direction == new_direction
예제 #12
0
def test_next_player(set_direction, set_current_player, next_player):
    """
    Checks that next_player returns the correct next player to play

    Args:
        set_direction: a int representing the direction 1 for forward and -1 for reverse
        set_current_player: a int representing the current player
        next_player: a int representing the expected next_player
    """
    uno_deck = Deck()
    uno_game = PlayGame(uno_deck, ["0", "1", "2", "3"])
    uno_game.direction = set_direction
    uno_game.current_player = set_current_player

    assert uno_game.next_player() == next_player
예제 #13
0
"""
Check the correctness of functions in icon_averaging
"""
# Import required libraries.
import pytest

# Import the code to be tested.
from uno_deck import (Card, Deck, Player, PlayGame)

# create test objects
test_uno_deck = Deck()
test_uno_deck.game_start()
test_uno_player = Player(test_uno_deck, "name")


@pytest.mark.parametrize(
    "color, rank, resulting_card",
    [
        # Checks that creating a card with a minimum rank is created correctly
        ("Red", 0, "Red 0"),
        # Checks that creating a card with a maximum rank is created correctly
        ("Green", 9, "Green 9"),
        # Checks that creating a card with rank 10 outputs a Draw Two card
        ("Yellow", 10, "Yellow Draw Two"),
        # Checks that creating a card with rank 11 outputs a Reverse card
        ("Blue", 11, "Blue Reverse"),
        # Checks that creating a card with rank 12 outputs a Skip card
        ("Red", 12, "Red Skip"),
        # Checks that creating a card with rank 13 outputs a Wild Card card
        ("Wild", 13, "Wild Card"),
        # Checks that creating a card with rank 14 outputs a Wild Draw Four card