Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE PLEASE HELP with this C++ problem HERE ARE THE TEMPLATE FILES to create a Hearthstone game ( a game where two players summon creatures

PLEASE PLEASE HELP with this C++ problem

HERE ARE THE TEMPLATE FILES to create a Hearthstone game (a game where two players summon creatures to attack each other until their health points are reduced to zero)

board.cpp

#include "board.h"

using namespace std;

void Board::shuffleDeck(void){

Card * temp;

int numOfShuffles = 100;

int idx1, idx2;

for(int i = 0; i

idx1 = rand() % deck.size();

idx2 = rand() % deck.size();

temp = deck[idx1];

deck[idx1] = deck[idx2];

deck[idx2] = temp;

}

}

void Board::renderMana(void){

cout

for(int i = 1; i

if(i

cout

else

cout

}

cout

}

void Board::renderHand(void){

if(hand.size() > 0){

for(int i = 0; i

for(int j = 0; j

cout render(i)

}

cout

}

} else {

for(int i = 0; i

cout

}

}

void Board::renderField(void){

if(field.size() > 0){

for(int i = 0; i

for(int j = 0; j

cout render(i)

}

cout

}

} else {

for(int i = 0; i

cout

}

}

board.h

#ifndef BOARD_H #define BOARD_H

#include #include #include "card.h"

class Board{ private: // The current amount of health. int hp; // The amount of mana available to spend. int mana; // The max amount of mana available per turn. Should be equal to the current turn. int maxMana; /* deck * * This vector is used to hold pointers to all the cards in a player's * deck. The deck should contain 20 cards at the start of the game. */ vector deck; /* hand * * This vector contains pointers to all the cards in the player's hand. */ vector hand; /* discard * * This vector contains pointers to all the cards in the discard pile. */ vector discard; /* field * * This vector contains pointers to all the cards on the field. */ vector field; public: /* Constructor for Board * * This constructor should be used to initalize a player's health * to 2000 when called. */ Board(void); /* addToDeckList * * This function adds a card pointer to the deck vector. Used to add * cards to the deck before the start of the game. */ void addToDeckList(Card*); /* draw * * This function pops a Card pointer off of the deck vector and * pushes it onto the hand vector. The integer passed to this * function determines how many cards to draw. */ void draw(int); /* playCardFromHand * * This function plays a card from the hand. The integer passed to * the function is the index of the card to play in the hand vector. * The mana cost of the card is subtracted from the player's current * mana count. */ void playCardFromHand(int); /* getCardOnField * * Accessor function to retrieve the pointer to the card on the * field at the specified index. */ Card* getCardOnField(int); /* getCardInHand * * Accessor function to retrieve the pointer to the card in the * hand at the specified index. */ Card* getCardInHand(int); /* getHP * * Accessor function for HP. */ int getHP(void); /* setHP * * Mutator function for HP. */ void setHP(int); /* getHandSize * * Returns the current size of the hand vector. */ int getHandSize(void); /* getFieldSize * * Returns the current size of the field vector. */ int getFieldSize(void); /* getMana * * Returns the current amount of mana. */ int getMana(void); /* setMana * * Mutator function for mana. */ void setMana(int); /* discardCardFromField * * Removes a card at a specified index from the field vector and adds * it to the discard vector. */ void discardCardFromField(int); /* unExhaustField * * Sets the exhausted value to false for all cards in the field vector. */ void unExhaustField(void); /* shuffleDeck * * Scrambles the order of the values in deck vector. */ void shuffleDeck(void); /* renderMana * * Draws the current mana count. */ void renderMana(void); /* renderHand * * Draws the cards in the hand vector to the console. */ void renderHand(void); /* renderField * * Draws the cards in the field vector to the console. */ void renderField(void); };

#endif

card.cpp

#include "card.h"

using namespace std;

string Card::render(int line){ switch(line){ case 0: return ".___________."; case 1: return "| |"; case 2: return "| |"; case 3: return "| |"; case 4: return "| |"; case 5: return "| |"; case 6: return "| |"; case 7: return "|___________|"; default: return " "; } }

card.h

#ifndef CARD_H #define CARD_H

#include

using namespace std;

class Card{ private: string name; int manaCost; int attack; int defense; bool exhausted; public: /* Card Constructor * * This constructor initializes the card object with a * name, mana cost, attack, and defense values. * This will be used by derived classes. */ Card(string, int, int, int); /* Render * * This function is used to print the ASCII image * of the card, line by line. The line to print is * specified by the value passed to render. */ virtual string render(int);

// Accessors and Mutators string getName(void); int getManaCost(void); int getAttack(void); int getDefense(void); bool isExhausted(void); void unExhaust(void); };

#endif

goblin.cpp

#include "goblin.h"

string Goblin::render(int line){ switch(line){ case 0: return ".___________."; case 1: return "|Goblin |"; case 2: return "| ^___^ |"; case 3: return "| ( . . ) |"; case 4: return "| v |"; case 5: return "| |"; case 6: return "| 200/100 |"; case 7: return "|___________|"; default: return " "; } }

goblin.h

#ifndef GOBLIN_H #define GOBLIN_H

#include #include "card.h"

using namespace std;

class Goblin : public Card { private: public: Goblin(void); virtual string render(int); };

#endif

main.cpp

#include #include #include #include "board.h" #include "goblin.h" #include "card.h"

using namespace std;

void getOpponentAction(Board&, Board&); void renderBoard(Board&, Board&);

int main(int argc, char * arv[]){ srand(time(0)); // Set up Player board Board pb; // Create player deck and draw initial hand here:

// Set up opponent board Board ob; // Create opponent deck and draw initial hand here: while(pb.getHP() > 0 && ob.getHP() > 0){ // Take turns here:

turn++; } return 0; }

void renderBoard(Board & pb, Board & ob){ // Render opponent field ob.renderField(); cout

void getOpponentAction(Board & playerBoard, Board & opponentBoard){ // Go through hand and play cards that the opponent can afford to play for(int i = 0; i getManaCost() isExhausted()){ // get target for attack // look through all cards on player's board. If the card is capable of killing one of those, it will chose the first one as its target int targetIndex = -1; for(int j = 0; j getAttack() > opponentBoard.getCardOnField(j)->getDefense()){ targetIndex = j; break; } } if(targetIndex != -1){ // destory creature cout getName() getName() getName() getAttack() getAttack()); } } } }

HOW TO PLAY

Each player has a customized 20-card deck. This deck is filled with various creature cards, each with different properties. Lets look at an example below:

image text in transcribed

Here, we have an ASCII representation of a Goblin card. Each card has five different properties: a name, attack, defense, mana cost, and exhaustion. This ASCII card displays the name at the top of the card, an image of the creature in the center, and two numbers separated by a slash at the bottom. These numbers represent the attack and defense of the creature, respectively. The attack represents how hard the creature hits other creatures and opponents, and the defense represents how hard of a hit the creature can take before dying. The creature also has a mana cost and exhaustion, but well define that later.

Each player begins the game with 2000 health points, shuffles their decks, and draws 5 cards for an initial hand. A coin toss can be used to determine which player goes first. At the beginning of each turn (except for the first turn of the player going first), each player draws 1 card. To play a card, the player must spend mana according to the cards mana cost. Mana is a resource generated each round, and is equal to the number of turns that have past. (e.g., On turn 1, you have 1 mana available. On turn 2, you have 2 mana available. On turn 7, you have 7 mana available.) Each card has a mana cost required to play it, and you must have that much mana available to spend on that card. For example, a Goblin requires 1 mana to summon, so if its the first card I play on turn 3, Ill have 2 mana left over after summoning. Mana is refreshed each round, and unspent mana on your turn doesnt roll over.

When you spend mana to summon a creature, that creature goes onto your side of the field. Each turn players can attack with creatures on their side of the field. A creature can be used to attack either the opponent or other creatures. If the creature attacks the opponent, the opponent loses health points equal to the attack of the attacking creature. If the opponents health points are reduced to 0, then they lose. If the creature attacks another creature, the defending creature dies if its defense is lower than the attacking creatures attack. If a creature dies, it is sent to the discard pile.

image text in transcribed

If Evil Penguin attacks Goblin, Goblin will die and be discarded from the field to the discard pile.

Creatures also become exhausted after they attack and when they are summoned. If a creature is exhausted, it cannot attack. Therefore, creatures can only attack once per turn, and not in the same turn when they are summoned.

image text in transcribed

Above is an example of the board. Here, we have 5 cards in hand, a goblin on the players side of the field, and the opponent has a goblin on their side of the field. The current amount of mana is expressed as @ and O symbols. Here, on turn 1 a goblin was summoned, depleting the 1 mana available. Spent mana slots are expressed as O. If there is still mana available, it is expressed with a @ symbol.

Above, it is turn 2, and 1 mana has been spent. We still have 1 mana available, shown by the remaining @.

If the player runs out of cards, when the player draws from an empty deck, that player instead loses half their health each turn.

IGoblin I I 200/100 IGoblin I I 200/100

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_2

Step: 3

blur-text-image_3

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

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions

Question

What is capitalized interest?

Answered: 1 week ago