Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programing language: C++ Game: Crazy 8s game of cards four parts: Cards.h, MatchingCardGame.h, Crazy8s.h, and Driver3.cpp I have to use inheritance and pure virtual functions.

Programing language: C++

Game: Crazy 8s game of cards

four parts: Cards.h, MatchingCardGame.h, Crazy8s.h, and Driver3.cpp

I have to use inheritance and pure virtual functions. I need to implement some code that could be part of a program to play a popular card game called Crazy 8s, which is the basis for the game Uno. I need to start to implement the rules found on youtube site (https://www.youtube.com/watch?v=9Fd0WUaTHZU)

Rules ------

- Jokers don't play on this game.

- If only 2 people are playing then each player should recived 7 cards. - If more than 2 people are playing, then each member should be given 5 cards. - After distributing cards to each player, the leftover deck of cards should be placed on the center of the table facedown next to only one card facing up to get the game going.

The Goal of the game: -------------------- - Player that gets rid of all his/her cards first, wins and must do so by matching the sign or number of the card hi/she has to the card facing-up on the table from left over deck of cards (facing-down). - If a player cannot match either by sign or number the card that's placed on the table, thus, must fetch for a card from the facedown deck of cards the on the table. - Any player who has an 8 of any sign (Hearts, Spades, Clubs, Diamonds) can call out the sign or number that should placed on the table by the other player/s.

. Note that the inheritance relationship below is also based on the organization of card games described on that website.

Requirements: It needs to be split into 3 classes, which should be in the files card.h, matchingCardGame.h and crazy8s.h. There will be a test driver again in the file Driver3.cpp. Please treat the file names and class/method names as case-sensitive.

1. The Card class (in card.h)

a. Private fields for rank and suit, both of which are of type string. Ex: 2 and Hearts you are to assume the values are valid

b. The method functions, here and in the other classes, are all public

c. A constructor that takes the rank and the suit as parameters and initializes the fields from the parameters

d. sameRank(Card &) const : returns true if this and the parameter card have the same rank, false if not

e. sameSuit(Card &) const: returns true if this and the parameter card have the same suit, false if not

2. The MatchingCardGame class (in matchingCardGame.h)

a. This is supposed to only be a partial implementation you will get to fill in the rest on a later assignment

b. A protected pointer to a Card variable that points to the top card of the deck this is in place of the deck

c. A setter setTop(Card *) which initializes the field. Note that when you complete the implementation, you will be replacing the pointer and this setter.

d. A pure virtual function canPlay(Card &) which returns true if it is valid to play the parameter card on top of the above top card

3. The Crazy8s class (in crazy8s.h)

a. This is a subclass of MatchingCardGame

b. The only thing required here is an implementation of canPlay which satisfies the following:

i. A card can be played if it is of the same rank as the top card

ii. A card can be played if it is of the same suit as the top card

iii. A card can be played if its rank is 8 (there is a feature that whoever plays the 8 then chooses what the next suit must be, but we will skip that requirement for now)

4. The driver should, as usual, test the above code.

a. Must hard-code the test cases to save time and to make sure you cover the different scenarios

b. To make sure you have implemented the inheritance relationship properly, declare a pointer to a MatchingCardGame and use that to point to a Crazy8s object. This would be like how the in-class exercise had you declare a pointer to a Polygon and use that to point to the Rectangle or the Triangle. Use this pointer to make the calls to to test canPlay()

therefore 4 parts:

- Card.h

- MatchingCardGame.h

- Crazy8s.h

- Driver3.cpp

comments for each file/class, something for each method/function, other comments to explain parts of the code

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

What does Copp say is the most important asset of any airline?

Answered: 1 week ago

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago