Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please, somebody helps me with this!! This assignment is to implement only the Card and Deck classes . Review the .h files for additional information

Please, somebody helps me with this!!

This assignment is to implement only the Card and Deck classes. Review the .h files for additional information on how to implement the classes. Implement code in the main() to test your classes. In your main() make sure to test for the deck empty and the card comparison operators.

( The card game Three Card War is a simple card game for two players. The game uses a 52 card conventional deck. To begin the deck is shufed and each player draws three cards. The players may look at their three cards. The remaining cards are placed in a pile facedown between the two players. The players decide who is going frst.

The player going frst selects one of his three cards and places it face up.

The opposing player selects one of her three cards and places it face up.

If the ranks of both cards are the same (a push), then both players retain their

cards and set them aside. Otherwise, the player with the highest-ranking card

keeps both cards (again, setting them aside).

After playing the round, each player draws one card from the deck to replace

the card just played with the frst playing drawing frst.

The player that won the round is now the frst player for the next round unless

there was a push then the original frst player goes frst again.

The game ends when the deck is exhausted and both players have played all of

their three cards.

The player with the most cards set aside wins.

Card ranking begins with the 2 as the lowest card going up to the ten, then jack, queen, king, and ace)

Card.h

#ifndef CARD_H_

#define CARD_H_

#include

#include

/**

* String constants for the suits

*/

static const std::string suitNames[] =

{ "Spades", "Hearts", "Diamonds", "Clubs" };

/**

* String constants for the rank

*/

static const std::string rankNames[] = { "Joker", "Two", "Three", "Four",

"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King",

"Ace" };

/**

* Card class to represent a single playing card

*/

class Card {

public:

/**

* Suit enumerations

*/

enum Suit {

Spades = 0, Hearts, Diamonds, Clubs

};

/**

* Rank enumerations ordered by value for game of war

*/

enum Rank {

Joker = 0,

Two,

Three,

Four,

Five,

Six,

Seven,

Eight,

Nine,

Ten,

Jack,

Queen,

King,

Ace

};

/**

* Constructor

*

* @param s

* @param r

*/

Card(Suit s, Rank r);

/**

* Constructor. This empty constructor will create a joker card.

* The joker card is a special card given to the player going first.

*/

Card();

/**

* Destructor

*/

virtual ~Card() {

}

/**

* Return true if this card is a joker

*/

bool isJoker() const {

return (cardRank == Joker);

}

/**

* Output the card to an output stream as "rank of suit"

*/

friend std::ostream& operator <<(std::ostream&, const Card&);

/**

* Compare operators. For the game of war we only care about the rank

*/

friend bool operator ==(const Card &lhs, const Card &rhs);

friend bool operator <(const Card &lhs, const Card &rhs);

private:

Suit cardSuit;

Rank cardRank;

};

#endif /* CARD_H_ */

----------------------------------------------

Deck.h

#ifndef DECK_H_

#define DECK_H_

#include

#include "Card.h"

#define MaxCards 52

/**

* The Deck class holds a deck of 52 cards. Cards are not removed

* from the Deck.

*/

class Deck {

public:

/**

* Constructor and destructor

*/

Deck();

virtual ~Deck();

/**

* Shuffle the deck and reset the next available card to the beginning of the deck

*/

void shuffle();

/**

* Return true if the deck is empty (next available card is past the end of the deck)

*/

bool isEmpty() const;

/**

* Draw a card from the deck. If someone attempts to draw a card when the deck is

* empty then throw an exception.

*/

const Card draw();

private:

unsigned nextCard;

std::vector cardDeck;

};

#endif /* DECK_H_ */

--------------------------------------

Player.h

#ifndef PLAYER_H_

#define PLAYER_H_

#include

#include "Card.h"

#define MAX_HAND_SIZE 3

/**

* Abstract Player classS

*/

class Player {

public:

/**

* Deconstructor

*/

virtual ~Player() {

}

/**

* Play a card. If the player receives a joker then this player is going first

*/

virtual const Card playCard(const Card opponentCard) = 0;

/**

* Receive a card from the dealer

*/

void receiveCard(const Card c) {

hand.push_back(c);

}

/**

* Add points to the score

*/

void addScore(unsigned s) {

score += s;

}

/**

* Get the score

*/

int getScore() const {

return score;

}

/**

* Return true if the player has cards in the hand

*/

bool hasCards() const {

return (hand.size() != 0);

}

/**

* Receive the cards played from the previous round. This member function would

* be used by a computer player that may need to 'see' what cards were played.

*/

void cardsPlayed(const Card card1, const Card card2) {

}

/**

* Output the players name

*/

friend std::ostream& operator <<(std::ostream& out, const Player& p);

protected:

/**

* Constructor. Since this is an abstract class we do not want anyone instantiating

* a player class so we make it protected.

*/

Player(std::string name) :

score(0), name(name), hand(0) {

}

int score;

std::string name;

std::vector hand;

};

#endif /* PLAYER_H_ */

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

1. Identify and describe four individual components of competence.

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago