Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment implement the TerminalPlayer class and use the main() to test that the class is operating correctly. The terminal player will extend the

For this assignment implement the TerminalPlayer class and use the main() to test that the class is operating correctly. The terminal player will extend the Player class and should do the following:

Tell the player if they are going first (they receive a joker) or they are going second

Display the cards in the player's hand (could be 1 - 3) cards

Prompt the player for the card they want to play

Removed the chosen card from the player's hand and return the chosen card

You do not need to implement that main() game loop for this assignment but the main() should contain code to test your terminal player class.

Card.h

// 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

/* Deck.h */

#ifndef DECK_H_ #define DECK_H_

#include

#include "Card.h"

#define MaxCards 52

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

/* 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_ */

Create Card.cpp, Deck.cpp, Player.cpp and Main.cpp

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago