Question: (C++) Download the starter code main.cpp, Character.h and Character.cpp, Combat.cpp and Combat.h contained in the zip file Combat.zip. We have provided main.cpp to give you
(C++) Download the starter code main.cpp, Character.h and Character.cpp, Combat.cpp and Combat.h contained in the zip file Combat.zip. We have provided main.cpp to give you an idea of how we intend to use the Combat class. You may not use global variables. Complete the implementations for the Combat class, which simulates a text combat game with multiple monsters, in the file Combat.cpp.
Complete the implementations for the Combat class, which simulates a text combat game with multiple monsters, in the file Combat.cpp. You should only modify Combat.cpp and submit only Combat.cpp
===================================
//Main.cpp
#include "Matrix.h"
using namespace std;
int main()
{
// construct three 3 by 5 matrices
Matrix A(3,5);
Matrix B(3,5);
Matrix C(3,5);
C = A+B; // perform matrix addition with matrix A and B
// write the values of A, B and C to a text file.
ofstream fout;
fout.open("out.txt");
A.print(fout);
B.print(fout);
C.print(fout);
fout.close();
return 0;
}
===================================================
//matrix.cpp
#include "Matrix.h"
Matrix::Matrix ()
{
num_rows = 0;
num_cols = 0;
}
// Put your code below:
=====================================
//Matrix.h
//matrix.h
#ifndef MATRIX_H
#define MATRIX_H
#include
#include
#include
#include
#include
using namespace std;
class Matrix
{
public:
Matrix();
Matrix(int new_num_rows, int new_num_cols);
Matrix operator+ (const Matrix& M2) const;
void print(ofstream& fout) const;
private:
int num_rows;
int num_cols;
vector
};
#endif
===================================
COMBAT FOLDER
//Character.cpp
include "Character.h"
Character::Character()
{
name = " ";
health = 0;
damage = 0;
arrows = 0;
}
Character::Character(string newName, int newHealth, int newDamage, int newArrows)
{
name = newName;
health = newHealth;
damage = newDamage;
arrows = newArrows;
}
void Character::set_health(int newHealth)
{
health = newHealth;
}
void Character::attack(Character& target)
{
target.health -= damage;
cout
cout
}
void Character::rangedAttack(Character& target)
{
if (arrows == 0)
cout
else
{
int rangedDamage = rand() % 5 + 1;
target.health -= rangedDamage;
arrows--;
cout
cout
}
}
void Character::display() const
{
cout
}
string Character::get_name() const
{
return name;
}
int Character::get_health() const
{
return health;
}
======================================
//Character.h
//Character.h
#ifndef Character_h
#define Character_h
#include
#include
#include
#include
using namespace std;
class Character
{
public:
Character();
Character(string newName, int newHealth, int newDamage, int newArrows);
void attack(Character& target);
void rangedAttack(Character& target);
void set_health(int newHealth);
int get_health() const;
string get_name() const;
void display() const;
private:
string name;
int health;
int damage;
int arrows;
};
#endif
================================
//Combat.cpp
#include "Combat.h"
Combat::Combat()
:hero("Hero", 30, 3, 5), NumberOfMonsters(1), tokens(2)
{
Character M("Monster", 5, 2, 0);
monsterList.push_back(M);
}
void Combat::start()
{
int choice, iMonster;
srand(time(0));
while (NumberOfMonsters>0 && hero.get_health()>0)
{
for (int i = 0; i monsterList[i].attack(hero); cout if (hero.get_health() break; hero.display(); cout cout printMonsterList(); cout cin >> choice; if (choice == 1 || choice == 2) { cout cin >> iMonster; if (cin.fail() || iMonster >= NumberOfMonsters) { cout break; } } cout switch (choice) { case 1: hero.attack(monsterList[iMonster]); break; case 2: hero.rangedAttack(monsterList[iMonster]); break; case 3: attackAll(); break; default: cout break; } checkAliveMonster(); cout } if (NumberOfMonsters == 0) cout if (hero.get_health() cout cout } // Put your code below: ======================================= //Combat.h //Combat.h #ifndef COMBAT_h #define COMBAT_h #include #include #include "Character.h" using namespace std; class Combat { public: Combat(); Combat(int newNumberOfMonsters); void attackAll(); void start(); void checkAliveMonster(); void printMonsterList() const; private: int NumberOfMonsters; vector Character hero; int tokens; }; #endif ==================================== //main.cpp #include "Combat.h" using namespace std; int main() { Combat game(3); game.start(); return 0; } The private data members: int NumberOfMonsters represents the number of monsters in the game; vector monsterList stores a list of monsters; Character hero represents the hero you play; int tokens represents the number of tokens the hero has, which would allow the hero to attack all the monsters at the same time. A default constructor has been included in Combat.cpp The other constructor Combat(int newNumberOfMonsters) creates a hero named Hero and a list of newNumberOfMonsters monsters. The monsters are named Monster0, Monster1, Monster2, etc. The other data fields are initialized as - For the hero: health = 30, damage = 3, arrows = 5; - For all the monsters: health = 5, damage = 2, arrows = 0; - tokens = 1. Hint: the function to string might be helpful. http://www.cplusplus.com/reference/string/to string/ The public methods: void attackAll() lets the hero do a regular attack to ALL the monsters in the monsterlist. Every attackAll costs one token. If the hero has no tokens left, print something like Hero is out of tokens! start() defines the game process and has been provided in Combat.cpp; void checkAliveMonster() checks if every monster in the monsterList is still alive. For any monster with negative or zero health, remove that monster from the monsterList, add 5 points to the heros health, and add 1 tokens as a bonus. Print to the console something like You killed a monster! Hero gets 5 health bonus points! Hero gets 1 bonus tokens! void printMonsterList() const prints the name and health of every existing monster in the monsterList. A sample print may look like Monster0 health: 3 Monster1 health: 2 Monster2 health: 4 Eventually a sample run of main.cpp using the Combat class may look like: 


Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
