Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You just need to complete these requirements with C++ . Crazy Eights For this assignment, you will write a program that allows one player to

image text in transcribedimage text in transcribedimage text in transcribedYou just need to complete these requirements with C++ . image text in transcribed

Crazy Eights 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 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. (6 pts) The Big Three In Program 2, you need to handle dynamic memory in your classes. Write the Big Three as needed for your classes. For example, here are some of the prototypes for the destructor, copy constructor, and assignment operator overload for the Hand class to get you started. Hand(); Hand(const Hand&); Hand& operator= (const Hand&); (3 pts) Testing To get points for the lab, show your TA that all of the functions are working as expected. You should test that they are called at the appropriate times. This may be done with print statements in the functions to show it is being called as well as printing the objects before and after the call to show the changes (or not) that occurred. (1 pt) Makefile Create a Makefile that compiles all of your .cpp files and makes an executable showing off their functionality. Remember, you will not receive lab credit if you do not get checked off by the TA before leaving each lab. Once you have a zero on a lab, then it cannot be changed because we have no way of knowing if you were there or not! Crazy Eights 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 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. (6 pts) The Big Three In Program 2, you need to handle dynamic memory in your classes. Write the Big Three as needed for your classes. For example, here are some of the prototypes for the destructor, copy constructor, and assignment operator overload for the Hand class to get you started. Hand(); Hand(const Hand&); Hand& operator= (const Hand&); (3 pts) Testing To get points for the lab, show your TA that all of the functions are working as expected. You should test that they are called at the appropriate times. This may be done with print statements in the functions to show it is being called as well as printing the objects before and after the call to show the changes (or not) that occurred. (1 pt) Makefile Create a Makefile that compiles all of your .cpp files and makes an executable showing off their functionality. Remember, you will not receive lab credit if you do not get checked off by the TA before leaving each lab. Once you have a zero on a lab, then it cannot be changed because we have no way of knowing if you were there or not

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Describe six biases affecting perception.

Answered: 1 week ago

Question

State the three objectives of the book.

Answered: 1 week ago