Program 3: Uno Stack Game

Due Date and Submission Requirements


The goal of this lab is:


Background

Uno is a card game that involves players taking turns and placing cards onto a stack on cards. Each card has a color, and a value. In order to place a card onto the stack, the card being played must either
1. Match the value of the card on the top of the stack
2. Match the color of the card on the top of the stack
3. The card being played is a wildcard (W)
If a player does not have any valid cards to play, they must draw a new card from the deck. The game is over when a player has zero cards left in their hand. In this assignment, you will be playing a simplified, single player version of Uno. Below are the changes for our version of Uno. If the player does not have any cards to play, then they must select an option to add another card to their hand from their deck. If a player tries to make an illegal move, then the move should be denied.

Directions

Card Class

You will need to define a Card class, which holds information about a single Uno Card. Each Uno card has a value, and a color.

Stack Class

Next, you should define your Stack data structure class. The Stack will hold Card objects as the game is being played. The stack should use a linked list to hold Card objects. You should import java.util.LinkedList for this. You will need the following stack methods: push(Card newCard), pop(), peek(), isEmpty(), and getSize();

Demo/Game Class

You may want to define another class, UnoGame, that has all of the logic for playing the Uno game, or you can put all of this inside the Demo class. This class will need to keep track of the Card stack, and the hand of the player. You can use a LinkedList or an ArrayList to represent the hand of the user. You will likely need to define a method, getNewCard(), that will retrieve a random Uno card. You should also define a checkMove() method, which checks to see is a proposed move is legal. You should also define a makeMove() move, which will update the stack.
The player can select a card from their hand to play, or they can press 0 to get a new card from the deck. The program should end when the player has no cards left. If the user tries to make an illegal move, your program should not let them make the move, and print out "Invalid move". If a user tries to play a "Remove" card on a stack with only 1 card, that is an illegal move and should be denied.

Starting Code and Requirements

You are encouraged to develop your solution from scratch, but you must have a Demo class, a Stack class, and a Card/UnoCard class. You must implement your own Stack data structure, and your stack *should* use a linked list.

Restrictions

Sample Output

Your program does not need to match this output exactly, but the functionality of your program should be similar.

Optional Hints

Look back at our code from October 18 for how to implement a stack data structure with a Linked List.

If you get stuck or have a bug in your code, remember that you a rubber duck that can help 😉

Grading (100 points)

Criteria Points
Card class is defined correctly 10
Stack class is defined correctly 10
User is able to get new card by pressing option 0 10
Valid moves are detected, and stack is updated 20
Invalid moves are detected and denied 20
Remove card removes top card from stack 10
Bottom card removes all cards except for the bottom card 10
The game is ended when user has no cards left 10






program 3 solution