Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ (visual studio) Uno You will implement a simplified version of The worlds most beloved card game (Uno). Here are the basic rules of

Use C++ (visual studio)

Uno

You will implement a simplified version of The worlds most beloved card game (Uno). Here are the basic rules of the game you will implement (note some simplified variations from actual rules).

  • Each card in the deck has a value between 0 and 9 and a color of blue, green, red, or yellow. Traditional Uno also includes cards such as wild, skip, draw, and reverse but your game will not use these special cards.
  • Each player initially receives 5 cards and one card is placed face up (this is the up-card). Players take turns until one player no longer has any cards.
  • On a player's turn, the player can select one of their cards of the same color or same value to be placed on top of the up-card (thus becoming the new up-card). If the player does not have such a card, the player must draw a card from the deck. For example, if the up-card is a yellow 7, then the player can play a red 7 or a yellow 2. However, if the player has no 7s and no yellow cards, the player must draw a card. Players must wait one turn to place a drawn card.

In traditional Uno no player can see any other player's card, but in your version of Uno each player can see all of the other players' cards. Your version of Uno should proceed as follows.

  1. Ask the user for the number of players (between two and four)
    1. Validate and repeat asking until the user enters a valid number of players
  2. Ask the user for each player's initials (two characters)
    1. Validate and repeat asking until the user enters a string with exactly two characters
  3. Create a 5-card hand for each player (randomize card selection)
  4. Randomly assign a player to the first turn
  5. Repeat the following procedure until one player has no cards
    1. Show the up-card, the hand of each player, and the current turn (see details below).
    2. Prompt the user for action D (to draw a card) or P (to place a card).
      1. If something else is entered, inform of invalid choice and allow user to reenter.
    3. If the user draws, add a card to their hand and move to the next turn.
    4. If a user places, use the following procedure.
      1. Ask the user for the color and numerical value of the card they want to place (in that order). User should enter a single character for color (B, G, R, or Y).
      2. If the user does not have the card they specified, inform the user and repeat the turn for that player.
      3. If the user has the card but cannot be played on the up-card, inform the user and repeat the turn for that player.
      4. If the user has the card and the card can be played, remove the card from the player's hand, set the new up-card to be the placed card, and move to the next players turn.
  6. Print the name of the winning player

There are several requirements in designing this project.

  • A single card should be represented by an UnoCard class. The card should be described by its color and number value, and you must include a pointer to a UnoCard named nextCard as one of the private data members. Implement appropriate getter and setter functions and two constructors (one for default values and one with explicit parameters). Use UnoCard.h and UnoCard.cpp files to develop the class.
  • A hand of cards should be represented by an UnoHand class containing one private data member: an UnoCard pointer named first. This will be a pointer to a linked list of UnoCard objects (UnoCards will be the nodes of the linked list). The functions to implement for this class are as follows. Implement the class using UnoHand.h and UnoHand.cpp files.
    • UnoHand (constructor). The function sets the list pointer to be null.
    • insertOne(value, color). The function inserts a card using the parameters. Cards should always be sorted by color (blues, greens, reds, then yellows) and then by value (e.g. blue 8, then green 2, then green 5, then red 3, then red 5, etc.).
    • removeOne(value, color). The function searches for a card based on the parameters and removes it from the list if the card is found. Return true if the card is removed but return false if not.
    • isEmpty(). The function returns true if there are no cards in the list but returns false if there is at least one card in the list.
    • print(). The function prints out each card in order. Print the color character, then the value, then a space. This function should not print any blank lines. See the example below for additional guidance.
  • Game play should be simulated in a client file called UnoGame.cpp. Follow the directions above for the way the game is played. Represent the different players by using a dynamic array of UnoHand objects. Use functions to aid in the development and readability of your code (i.e. the code within main() should be highly modularized). One function in particular to implement is printState, which handles showing the up-card, each player's hand, and the current turn. The printout should follow the example below as closely as possible.
Up: G5
JR B2 B5 G6 G8 Y0
CG * G7 Y6 Y8 Y8
MG B0 B5 B6 B9 G1 G4 G7 R3 R3 R7 Y6

In the example, the up card is a green 5. The players are JR, CG, MG and the star indicates that it is CG's turn. Each card in each hand is printed out and ordered by color, then by value. Suppose that CG places the green 7. Then the next printout would appear as follows.

Up: G7
JR B2 B5 G6 G8 Y0
CG Y6 Y8 Y8
MG * B0 B5 B6 B9 G1 G4 G7 R3 R3 R7 Y6

Notice in the previous example that CG has two yellow 8s. You may simplify the game simulation by assuming that there are an unlimited number of each card in the deck. You'll likely want to use the rand() function to help you with random number generation:

  • include the cstdlib and ctime files.
  • place the following line as the first line of main():
    • srand(time(NULL));

If there are any additional class member functions that you would like to implement to ease the programming, you are allowed to do so. However, they should be clearly documented where necessary and should follow a structured object-oriented design approach.

. Make sure the following five files are within that folder:

  • UnoGame.cpp
  • UnoHand.cpp
  • UnoHand.h
  • UnoCard.cpp
  • UnoCard.h

Here is the sample output

Sample Output: Use the following as a guide to what your output should look like. Note that the three columns on following page are to save printing space here. The actual program will output in typical top-to-bottom fashion.

Please enter how many players (between 2-4) will be playing:

3

Please enter each player's initials below, one line at a time:

JR

JR: B7 B7 G7 R1 Y9

CG

CG: B9 G6 R4 Y3 Y7

MG

MG: B8 G4 G4 G5 Y9

Up: G8

JR: B7 B7 G7 R1 Y9

CG: * B9 G6 R4 Y3 Y7

MG: B8 G4 G4 G5 Y9

Action (D or P): Y

Invalid Choice!

Action (D or P): P

Color: G

Value: 6

Up: G6

JR: B7 B7 G7 R1 Y9

CG: B9 R4 Y3 Y7

MG: * B8 G4 G4 G5 Y9

Action (D or P): P

Color: G

Value: 4

Up: G4

JR: * B7 B7 G7 R1 Y9

CG: B9 R4 Y3 Y7

MG: B8 G4 G5 Y9

Action (D or P): P

Color: G

Value: 7

Up: G7

JR: B7 B7 R1 Y9

CG: * B9 R4 Y3 Y7

MG: B8 G4 G5 Y9

Action (D or P): P

Color: Y

Value: 7

Up: Y7

JR: B7 B7 R1 Y9

CG: B9 R4 Y3

MG: * B8 G4 G5 Y9

Action (D or P): P

Color: Y

Value: 9

Up: Y9

JR: * B7 B7 R1 Y9

CG: B9 R4 Y3

MG: B8 G4 G5

Action (D or P): P

Color: Y

Value: 9

Up: Y9

JR: B7 B7 R1

CG: * B9 R4 Y3

MG: B8 G4 G5

Action (D or P): P

Color: Y

Value: 3

Up: Y3

JR: B7 B7 R1

CG: B9 R4

MG: * B8 G4 G5

Action (D or P): D

Up: Y3

JR: * B7 B7 R1

CG: B9 R4

MG: B8 G4 G5 R2

Action (D or P): D

Up: Y3

JR: B4 B7 B7 R1

CG: * B9 R4

MG: B8 G4 G5 R2

Action (D or P): D

Up: Y3

JR: B4 B7 B7 R1

CG: B7 B9 R4

MG: * B8 G4 G5 R2

Action (D or P): D

Up: Y3

JR: * B4 B7 B7 R1

CG: B7 B9 R4

MG: B8 G4 G5 R2 Y5

Action (D or P): D

Up: Y3

JR: B4 B7 B7 G1 R1

CG: * B7 B9 R4

MG: B8 G4 G5 R2 Y5

Action (D or P): D

Up: Y3

JR: B4 B7 B7 G1 R1

CG: B7 B9 G6 R4

MG: * B8 G4 G5 R2 Y5

Action (D or P): P

Color: Y

Value: 5

Up: Y5

JR: * B4 B7 B7 G1 R1

CG: B7 B9 G6 R4

MG: B8 G4 G5 R2

Action (D or P): D

Up: Y5

JR: B4 B7 B7 G1 R1 R7

CG: * B7 B9 G6 R4

MG: B8 G4 G5 R2

Action (D or P): D

Up: Y5

JR: B4 B7 B7 G1 R1 R7

CG: B7 B9 G6 R4 R8

MG: * B8 G4 G5 R2

Action (D or P): P

Color: G

Value: 5

Up: G5

JR: * B4 B7 B7 G1 R1 R7

CG: B7 B9 G6 R4 R8

MG: B8 G4 R2

Action (D or P): P

Color: G

Value: 1

Up: G1

JR: B4 B7 B7 R1 R7

CG: * B7 B9 G6 R4 R8

MG: B8 G4 R2

Action (D or P): P

Color: G

Value: 6

Up: G6

JR: B4 B7 B7 R1 R7

CG: B7 B9 R4 R8

MG: * B8 G4 R2

Action (D or P): P

Color: G

Value: 4

Up: G4

JR: * B4 B7 B7 R1 R7

CG: B7 B9 R4 R8

MG: B8 R2

Action (D or P): P

Color: B

Value: 4

Up: B4

JR: B7 B7 R1 R7

CG: * B7 B9 R4 R8

MG: B8 R2

Action (D or P): P

Color: R

Value: 4

Up: R4

JR: B7 B7 R1 R7

CG: B7 B9 R8

MG: * B8 R2

Action (D or P): P

Color: R

Value: 2

Up: R2

JR: * B7 B7 R1 R7

CG: B7 B9 R8

MG: B8 UNO!

Action (D or P): D

Up: R2

JR: B7 B7 G7 R1 R7

CG: * B7 B9 R8

MG: B8

Action (D or P): P

Color: R

Value: 8

Up: R8

JR: B7 B7 G7 R1 R7

CG: B7 B9

MG: * B8

Action (D or P): P

Color: B

Value: 8

***GAME OVER***

MG Wins!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions