Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is in C++. For this assignment, you will write a program that allows one player to play a game of Crazy Eights against

This program is in C++.

For this assignment, you will write a program that allows one player to play a game of Crazy Eights against the computer. Crazy Eights is a game that uses a standard deck of 52 cards. Specifically, each card has a rank and a suit. There are 13 ranks: the numbers 2 through 10, Jack (usually represented with the letter J), Queen (Q), King (K), and Ace (A). There are 4 suits: clubs, diamonds, hearts, and spades. In a 52-card deck, there is one card of each rank for each suit.

A game of Crazy Eights between two players proceeds as follows:

  • The deck of cards is shuffled, randomizing the order of the cards.
  • Each player is dealt 7 cards.
  • The remaining cards are placed face-down (i.e. with their rank and suit hidden) in a stack on the table and becomes the "stock", with the top card turned over and displayed in a separate "pile".
  • One of the players (player A) begins the game by playing a card from their hand that is the same suit or same rank as the top card on the pile, which becomes the new top of the pile.
  • Player B then plays a card from their hand that is the same suit or rank as the top card, which becomes the new top of the pile.
  • If a player does not have any cards of the required rank or suit, they must draw from the top of the deck (stock) and add cards to their hand until they draw a card that can be played on the pile, or until the deck runs out of cards.
  • The game continues with the players alternating turns until one of the players gets rid of all the cards in their hand, or until all of the cards are drawn and no one can play a card. If neither player has zero cards at the end of the game, the player with the least amount of cards in their hand wins.
  • Eights of any suit are considered "wild" and may be played on any turn. When an eight is played, the player must specify a suit for the next player to match.

Needed classes

To write your Crazy Eights game, you should implement the following classes, including the specified members and methods. You may also add more members and methods, as needed.

class Card { private: int rank; // Should be in the range 0-12. int suit; // Should be in the range 0-3. public: // must have constructors, destructor, accessor methods, and mutator methods };

In the Card class above, rank and suit are represented with int values, but you must also have some way to map those values to representations players will be familiar with (e.g. a string representation of the suit or rank).

class Deck { private: Card cards[52]; int n_cards; // Number of cards remaining in the deck. public: // must have constructors, destructor, accessor methods, and mutator methods };

The Deck class is the source of all of the cards. Cards will initially start in a Deck object and then be transferred to players' hands. An important method that should be implemented for the Deck class is one to remove a card and return it so it can be placed in a player's hand (deal a card from the deck to the player).

class Hand { private: Card* cards; int n_cards; // Number of cards in the hand. public: // must have constructors, destructor, accessor methods, and mutator methods };

The Hand class will hold the cards in one player's hand. The number of cards a player holds may change, so the size of the array of Card objects in a hand may also need to change. Cards may be added to a player's hand and removed from a player's hand, so the Hand class will need functions to do both of those things. Other useful methods might check for a given suit or rank.

class Player { private: Hand hand; string name; public: // must have constructors, destructor, accessor methods, and mutator methods };

The Player class represents a single player. Each Player will have a Hand object representing its hand and an array keeping track of the books the player has laid down. Depending on how you implement things, the Player class may need methods to add and remove cards from their hand or to check their hand for cards with a specific suit or rank. Another useful method the Player class might have is one to figure out what suit they want to ask for if they play an eight. Note that the Player class must represent both the human player and the computer player. You should write your class methods accordingly and add any extra data members needed to accomplish this.

class Game { private: Deck cards; Player players[2]; public: // must have constructors, destructor, accessor methods, and mutator methods }

The Game class represents the state of an entire game. It contains objects representing the deck of cards and both players. It would be useful to have methods in the Game class that check whether the game is over and that execute a player's turn.

Program features

Your program should do the following:

  • Set up a deck of 52 cards as described above.
  • Shuffle the deck (i.e. randomize the order of cards).
  • Deal the cards to the two players.
  • Play a game of Crazy Eights as described above, with the following gameplay features:
    • Print the current state of the game (e.g. the cards held by the human player and the card of on the top of the pile) after each turn (keeping the computer player's cards hidden).
    • On the human player's turn, prompt the user for a card to play. When they enter a card, either put the card on top of the pile or have them draw a card from the deck if they can't play. If the card is an 8, prompt the user to declare a suit for the next player.
  • Once the game is over, you should announce the winner and ask the user if they want to play again.
  • You should not have any memory leaks in your program.

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago