Question: write the functions for the classes (Player.cpp, Card.cpp, and Game.cpp) based on the header files (Player.h, Card.h, and Game.h) respectively: o All of the getters
write the functions for the classes (Player.cpp, Card.cpp, and Game.cpp) based on the header files (Player.h, Card.h, and Game.h) respectively: o All of the getters simply return the corresponding member variable. o All of the setters take in the new value and update the member variable (with no checks). o Otherwise, each function in the header files has a description of what that function does. Use those to design your program.
1 (Card.h)
/*
*Title: Exploding Kittens Card Game
*Author: Nick Lawrence and Jeremy Dixon
*Description: This is the card class for the exploding kittens game
*/
#ifndef CARD_H //Include guard to protect against double declarations
#define CARD_H //Includ guard
#include
using namespace std;
class Card {
public:
// Default Constructor
// Unused
Card();
// Name - Constructor
// Preconditions - valid int type for type of card, string name
// Postcontions - A card object with the given input values
Card(int, string);
// Name - GetType() - Returns the type of card
// Preconditions - an initialized card
// Postconditions - integer representing the type of card
// (see reference chart below)
int GetType();
// Name - ToString() - Returns a string representation of the card
// Preconditions - An intitalized card
// Postcontitions - Returns a string containing the representation of the card
string ToString();
private:
// 0 Bomb
// 1 Defuse
// 2 Attack
// 3 Skip
// 4 Peek
// 5 Shuffle
// 6,7,8,9 Normal Cards
int m_type; //Defined by the types of cards above
string m_desc; //Description comes from deck.txt file or bomb.txt file
};
#endif // CARD_H
2 (Player.h)
/* *Title: Exploding Kittens Card Game *Date: 2/22/2017 *Author: Nick Lawrence and Jeremy Dixon *Description: This is the player class for the exploding kittens game */
#ifndef PLAYER_H //Include guard to protect against multiple declarations #define PLAYER_H //Include guard
#include
class Player { public: // Name - Default Constructor // Unused Player();
// Name - Constructor (Overloaded) // Preconditions: A valid input string for the name // Postcondition: A player with a name, an empty hand, and m_lost set to false Player(string);
// Name - PlayCard() // Desc - Function for moving a card from a player's hand to the discard pile // Preconditions - A hand with at least 1 card // Postconditions - Returns a card from the hand and deletes it from the array Card PlayCard();
// Name - LoseCard() // Desc - Function where a player steals card from another player // Preconditions - A hand with at least 1 card, a valid index // Postconditions - Returns and deletes the card at index i Card LoseCard(int);
// Name - HasCards() // Desc - Function to check if the player has cards // Preconditions - None // Postconditions - True if the player has cards, false otherwise bool HasCards();
// Name - HasLost()
3 Game.h
/* *Title: Exploding Kittens Card Game *Date: 2/22/2017 *Author: Nick Lawrence and Jeremy Dixon *Description: This is the game class for the exploding kittens game */
#ifndef GAME_H #define GAME_H
#include "Player.h" #include
// Game Constants
// Number of cards a See into the Future card can show const unsigned int PEEK_NUM = 3; // The number of intial cards const int INIT_CARDS = 4; // Name of the main deck file const string DECK_NAME = "deck.txt"; // Name of the main bomb deck file const string BOMB_NAME = "bomb.txt"; // Seed for the pseudo random number generator const int RAND_SEED = 10;
class Game { public: // Name - Constructor // Desc - Runs the game // Preconditions - a valid constant that holds the name of the deck file and bomb file // Postconditions - Runs the game Game(); void SetNumPlayers(int numPlayers); private: // Name - Shuffle() // Desc - Shuffles the cards that are currently in the deck // Preconditions - A deck with at least 1 card // Postconditions - A deck with the elements shuffled in a different order void Shuffle();
// Name - Peek() // Desc - The Action for the See into the future card // Preconditions - A deck with at least 1 card // Postconditions - Will print the next [insert const num] card(s) in the deck void Peek();
// Name - DrawCard() // Desc - Get the card on the top of the deck and give it to a player // Preconditions - At least 1 card in the deck // Postconditions - Returns and deletes the top card on the deck Card DrawCard();
// Name - HandleCard() // Desc - Handles the last card placed by the currentPlayer // Preconditions - An integer number representing the currentPlayer, // a card placed on the discard pile // Postconditions - Handles the card according to their descriptions int HandleCard(int);
// Name - PlayGame() // Desc - Runs the game // Preconditions - A loaded deck, all players having cards // Postconditions - Determine winner and print to console void PlayGame();
// Name - LoadDeck() // Desc - Loads the cards in from a text file // Preconditions - A valid filepath // Postcondition - m_deck contains cards int LoadDeck(string);
// Name - AddBombCards() // Desc - Loads the bomb cards in from a text file, // this must be separate due to the nature of the game // Preconditions - A valid filepath, the file must contain 1 less bomb // than the number of players // Postconditions - Adds the bomb cards to m_deck int AddBombCards(string); int m_numPlayers; Player m_players[4]; vector
#endif /* GAME_H */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
