ConsoleUNO
Console based UNO game (Java)
Basics:
An UNO game consists of cards – 4 colours (25 each)
Cards:
- 0 : 1 card/colour.
- 1 to 9 : 2 cards/colour.
- Skip / Reverse / Draw 2 : 2 cards/colour.
- Wild Cards : 4 cards.
- "Draw Four" + Wild Cards : 4 cards.
Data Structures used :
- Doubly Linked List for player objects
- Stack/queue for deck of cards
Classes:
1. Card:
Variables:
- int colour – contains color code of card (R-0, G-1, B-2, Y-3)
- int cardType – contains card type code
Methods/Functions:
- setRandomCard() – creates a random card (random colour and type). Returns the card object.
- cardColourCodeConvert() – returns the String equivalent of the card colour.
- cardTypeCodeConvert() – returns the String equivalent of the card type.
2. Player:
Variables:
- String playerName – contains player name
- Int playerNumber – contains playerNumber
- Int numberOfCards – contains total number of cards possessed by player
- Card playerDeck[] - contains array of card objects which player has.
Methods/Functions:
- getPlayerName() – accepts player name
- addCardToDeck(card) – adds parameter card to player deck
- removeCardFromDeck(int) – removes card from player deck
- displayPlayerDeck() – displays complete player deck.
3. Game:
Variables:
- int totalDeck[][] – contains information of all the cards used in the game.
- Card extraDeck[] – array of card objects for extra cards.
- Int topExtraDeck – indicates top of extraDeck stack
- Int bottomExtraDeck – indicates bottom of extraDeck stack
- Card playingCard – the card in play (a.k.a. reference card)
- Int numberOfPlayers – Total no. of players in the game
- Int totalNumberOfCards – total no. of cards (108)
- Int numberOfCardsPerPlayer – number of cards each player has at the start.
- Int gameDirection – used to reverse the flow of control of game
- Player p0: p0 is head of Linked List.
Functions/Methods:
- checkRandomCardValidity() – checks random card generated, then adds entry to totalDeck[][], then returns true or false.
- Main() – main function of program, start-point.
- setCardsForPlayer(Player) – sets initial random cards for player
- setDoublyLinkedList() – sets the linking of all the player objects
- gameStart() – multiple uses – accepts number of users, no. of cards
- displayAllPlayers() – displays details and card deck of every player object
- setExtraDeck() – sets the remaining extra deck as a doubly ended stack
- setFirstCard() – chooses the first card in gameplay
- displayPlayingCard() – displays the reference card object details
- popExtraDeck(), pushExtraDeck()
- playerTurn() – recursive function controlling game play
- nextPlayerDrawsCard() – for Draw 2 and Draw 4 cards
- ifCardIsWild() – accepts change of colour if Wild card is played.
- checkCardPlayable() – checks the card whether it can be played by comparing it to reference card.