Example #1
0
def main():
    # create window for uno
    root = tk.Tk()
    root.title("Uno++")

    # build a list of players for the game
    players = [
        HumanPlayer("Ravi"),
        HumanPlayer(generate_name()),
        ComputerPlayer(generate_name())
    ]

    # build a pickup pile
    pickup_pile = Deck(build_deck(FULL_DECK))
    pickup_pile.shuffle()

    # deal players cards from the pickup pile
    for player in players:
        cards = pickup_pile.pick(7)
        player.get_deck().add_cards(cards)

    # create and play the game
    game = UnoGame(pickup_pile, players)
    app = UnoApp(root, game)
    app.play()

    # update window dimensions
    root.update()
    root.minsize(root.winfo_width(), root.winfo_height())
    root.mainloop()
Example #2
0
def main():
    # create window for coders
    root = tk.Tk()
    root.title("Sleeping Coders")

    # build a list of players for the game
    players = [Player(generate_name()), Player(generate_name())]

    # build a pickup pile
    pickup_pile = Deck(build_deck(FULL_DECK))
    for i in range(5):
        pickup_pile.copy(pickup_pile)
    pickup_pile.shuffle()

    # deal players cards from the pickup pile
    for player in players:
        cards = pickup_pile.pick(5)
        player.get_hand().add_cards(cards)

    # build a list of sleeping coder cards
    coders = CODERS[:]

    # create and play the game
    game = CodersGame(pickup_pile, coders, players)
    app = CoderApp(root, game)
    app.play()

    # update window dimensions
    root.update()
    root.minsize(root.winfo_width(), root.winfo_height())
    root.mainloop()
Example #3
0
 def build_deck(self, cards):
     deck = Deck()
     for card in cards:
         if card is None:
             card = Card()
         deck.add_card(card)
     return deck
Example #4
0
def test_deck():
    # Setup
    card = Card(12, "red")
    special_card = Pickup2Card(0, "red")
    blue_card = ReverseCard(0, "blue")
    cards = [card, special_card, blue_card]
    deck = Deck(cards)

    # Testing
    print("Get Cards:", deck.get_cards(
    ))  #== [Card(12, 'red'), Pickup2Card(0, 'red'), ReverseCard(0, 'blue')])
    print("Amount:", deck.get_amount() == 3)

    print("Top:", deck.top())  #ReverseCard(0, blue)

    print()
    new_card = SkipCard(0, "green")
    deck.add_card(new_card)
    deck.add_cards([card, special_card, blue_card])
    print("new amount:", deck.get_amount() == 7)

    print(
        "New Deck:", deck.get_cards()
    )  # [Card(12, red), Pickup2Card(0, red), ReverseCard(0, blue), SkipCard(0, green), Card(12, red), Pickup2Card(0, red),ReverseCard(0, blue)])

    print("Pick:", deck.pick())  # [ReverseCard(0, blue)]
    print("Pick 2:",
          deck.pick(amount=2))  # [Pickup2Card(0, red), Card(12, red)]
    deck.shuffle()
    print(
        "New Deck", deck.get_cards()
    )  #[SkipCard(0, green), Card(12, red), Pickup2Card(0, red),ReverseCard(0, blue)]
Example #5
0
    def __init__(self, deck, players):
        """
        Construct a game of uno from a pickup pile and list of players.

        Parameters:
            deck (Deck): The pile of cards to pickup from.
            players (list<Player>): The players in this game of uno.
        """
        self.pickup_pile = deck
        self.players = players

        self._turns = TurnManager(players)

        self.putdown_pile = Deck(self.pickup_pile.pick())
        self.special_pile = Deck()

        self._is_over = False
        self.winner = None
Example #6
0
def init():
    anna = ComputerPlayer("Anna Truffet")

    players = [
        anna,
        HumanPlayer("Henry O'Brien"),
        ComputerPlayer("Josh Arnold")
    ]

    deck = Deck(
        [Card(1, "red"),
         Card(2, "blue"),
         Card(3, "red"),
         Card(4, "green")])

    game = UnoGame(deck, players)

    return anna, players, deck, game
Example #7
0
    def new_game(self):
        """Start a new game"""
        # clone the old players
        players = []
        for player in self.game.players:
            players.append(player.__class__(player.get_name()))

        # generate a new deck
        pickup_pile = Deck(build_deck(FULL_DECK))
        pickup_pile.shuffle()

        # make players pickup cards
        for player in players:
            cards = pickup_pile.pick(7)
            player.get_deck().add_cards(cards)

        self.game = UnoGame(pickup_pile, players)
        self.render_decks()
        self.update()
Example #8
0
    def __init__(self, deck, coders, players):
        """
        Construct a game of Sleeping Coders from a pickup pile, a list of coder
        cards and a list of players.

        Parameters:
            deck (Deck): The pile of cards to pickup from.
            coders (List<Card>): The list of sleeping coder cards.
            players (list<Player>): The players in this game.
        """
        self._pickup_pile = deck
        self._coders = coders
        self.players = players

        self._turns = TurnManager(players)

        self.putdown_pile = Deck()

        self._is_over = False
        self.winner = None

        self._action = None
Example #9
0
print('-' * 5)

print('card.matchs(spical_card)')
print(card.matches(special_card))
print('-' * 5)

blue_card = ReverseCard(0, "blue")

print('special_card.matches(blue_card)')
print(special_card.matches(blue_card))
print('-' * 5)
print('*' * 40)

# Deck
cards = [card, special_card, blue_card]
deck = Deck(cards)

print('deck.get_cards()')
print(deck.get_cards())
print('-' * 5)
print('deck.get_amount()')
print(deck.get_amount())
print('-' * 5)
print('deck.top()')
print(deck.top())
print('-' * 5)
new_card = SkipCard(0, "green")
deck.add_card(new_card)
from os import system
system('pause')
deck.add_cards([card, special_card, blue_card])
Example #10
0
from a2 import Card, Player, Pickup2Card, Pickup4Card, HumanPlayer, ComputerPlayer, Deck, ReverseCard, SkipCard
import a2_support

# Set Up Uno Game
anna = ComputerPlayer("Anna Truffet")
players = [anna, HumanPlayer("Henry O'Brien"), ComputerPlayer("Josh Arnold")]

deck = Deck(
    [Card(1, "red"),
     Card(2, "blue"),
     Card(3, "red"),
     Card(4, "green")])

game = a2_support.UnoGame(deck, players)


def test_reverse_card():
    print("reverse", '*' * 10)
    card = ReverseCard(0, "red")
    print(game.current_player().get_name())
    # 'Anna Truffet'
    print(game.next_player().get_name())
    # "Henry O'Brien"
    print(game.next_player().get_name())
    # 'Josh Arnold'
    print(game.next_player().get_name())
    # 'Anna Truffet'
    print("Reverse", '-' * 10)
    card.play(anna, game)
    print(game.next_player().get_name())
    # 'Josh Arnold'