Uno Game

Today I just made the player play a card if it has the same number or color. Create an Uno file, set the draw button, update the card value to pile file, set the player turn. And show the player’s turn on the window.

In uno file, I initialize the window, game_deck, and pile. Draw the one card from the deck and put it on the screen.

Create a show_uno_btn() function, that is create a draw button on the screen and its command is player_draw(). In the player_draw(), it check if the player 1’s turn is true then the drawn card will added to player 1’s hand and same thing with player 2.

In change_turn(), it check if username is “p1”, player 1’s turn is false and player 2’s turn is true, then call the show_current_player() to it show the player’s turn on the window. And if the username is “p2” , player 1’s turn is true and player 2’s turn is false.

And create an update_top_card() function, so it can update the top card to 2 players.

def update_card_value(self, top_card, color):
        self.pile.top_card = top_card
        self.p1.top_card = top_card
        self.p2.top_card = top_card
        self.pile.top_card_color = color

And pass the change_turn() and update_top_card when called the Player class in the start_game() function. And set the first player to play as player.

In the Player class, create remove_and_update_turn() that will remove the card out of the player’s hand, show all the cards in the player’s hand in the window again, and call the change_turn() and update_top_card() function. Then create a check_and_play() function, it will check if the player’s turn is true, then check is that card is valid. If it is valid, call the remove_and_update_turn().

In the main.py file, call the start_game(), show_uno_btn(), and show_current_player(). Then the game window will pop up. This game is not complete, it just can play if it has the same color or value with the card in the pile.

Tags:

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *