Combat Game

Pages: 12
Mar 8, 2020 at 11:15pm
Hi everyone,
So I'm currently taking a class for programming and can't figure out how to solve one of the assignments. Note that all five downloads are together in the code section - I've separated them with their titles above. Also, I know the code I have is incomplete but that's cause I can't figure this out. The assignment is as follows:

In this problem we are going to use the Character class from Homework 6 to develop a more interesting
game. Download the starter code main.cpp, Character.h and Character.cpp, Combat.cpp and Combat.h
contained in the zip file Combat.zip from CCLE. 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. You should only modify Combat.cpp and submit only Combat.cpp to
CCLE.
The private data members:
• int NumberOfMonsters represents the number of monsters in the game;
• vector<Character> 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 hero’s
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


main.cpp
1
2
3
4
5
6
7
8
9
10
#include "Combat.h"
using namespace std;

int main() 
{
	Combat game(3);
 	game.start();

	return 0;
}


Character.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Character.h
#ifndef Character_h
#define Character_h

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
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 


Character.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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 << name << " attacks " << target.name << " doing " << damage << " damage!" << endl;
	cout << target.name << " health: " << target.health << endl;
}

void Character::rangedAttack(Character& target)
{
	if (arrows == 0)
		cout << name << " is out of arrows!" << endl;
	else
	{
		int rangedDamage = rand() % 5 + 1;
		target.health -= rangedDamage;
		arrows--;
		cout << name << " shoots " << target.name << " doing " << rangedDamage << " damage!" << endl;
		cout << target.name << " health: " << target.health << endl;
	}
}

void Character::display() const
{
	cout << name << "  health: " << health << "  arrows: " << arrows << endl;
}

string Character::get_name() const
{
	return name;
}

int Character::get_health() const
{
	return health;
}


Combat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Combat.h
#ifndef COMBAT_h
#define COMBAT_h

#include <iostream>
#include <vector>
#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> monsterList;
	Character hero;
	int tokens;
};
#endif 


Combat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//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<NumberOfMonsters; i++)
			monsterList[i].attack(hero);
		cout << "----------------------\n";
		if (hero.get_health() <= 0)
			break;
		hero.display();
		cout << hero.get_name() << " has " << tokens << " tokens left.\n";
		cout << "----------------------\n";
		printMonsterList();
		cout << "What do you do? 1 attack, 2 fire arrow, 3 attack all,  Q exit: ";
		cin >> choice;
		if (choice == 1 || choice == 2)
		{
			cout << "Which monster do you want to attack? (0-" << NumberOfMonsters - 1 << "): " << endl;
			cin >> iMonster;
			if (cin.fail() || iMonster >= NumberOfMonsters)
			{
				cout << "Input Error!\n";
				break;
			}
		}
		cout << "----------------------\n";
		switch (choice)
		{
		case 1:
			hero.attack(monsterList[iMonster]);
			break;

		case 2:
			hero.rangedAttack(monsterList[iMonster]);
			break;

		case 3:
			attackAll();
			break;

		default:
			cout << "Input error!\n";
			break;
		}
		checkAliveMonster();
		cout << "----------------------\n";
	}
	if (NumberOfMonsters == 0)
		cout << "Congratulations! You have killed all the monster!" << endl;
	if (hero.get_health() <= 0)
		cout << "You have died! GAME OVER! " << endl;

	cout << "Thanks for playing!" << endl;

}
// Put your code below:
//IMPLEMENTATIONS
Combat::Combat(int newNumberOfMonsters) {
	NumberOfMonsters = newNumberOfMonsters;
}
void Combat::attackAll() {
	if (tokens != 0) {
		vector<int> monsterList{ 0, 1, 2 };
		for (int i = 0; i < NumberOfMonsters - 1; i++) {
			cout << hero.get_name() << " attacks " << monsterList[i] << endl;
		}
		--tokens;
	}
	else if (tokens == 0) {
		cout << "Hero is out of tokens!";
	}
}
void Combat::checkAliveMonster() {
	for (int i = 0; i < NumberOfMonsters - 1; i++) {
		if (monsterList[i].get_health <= 0) {
			--NumberOfMonsters;
			cout << "You killed a monster!" << endl;
			hero.set_health((hero.get_health() + 5));
			cout << "Hero gets 5 health bonus points!" << endl;
			++tokens;
			cout << "Hero gets 1 bonus tokens!" << endl;
		}
	}
}
void Combat::printMonsterList() const {
	for (int i = 0; i < NumberOfMonsters - 1; i++) {
		cout << "Monster" << monsterList[i].get_name() << "   health: " << monsterList[i].get_health();
	}
	
}


Any assistance would be much appreciated.
Last edited on Mar 9, 2020 at 2:19am
Mar 9, 2020 at 12:19am
Which part are you stuck on?
Mar 9, 2020 at 12:46am
Pretty much everything.

1. I don't understand what to write within each implementation eg. Not sure how to add health to the hero, no idea how to display the monsters and their healths, no idea about iMonster, monsterList and M etc.
2. I try running the program but it has unidentifiable building errors.

The issue is that the teachers' notes are not helpful at all - nor were his lectures, making it difficult to understand, let alone complete the work.
The other thing is that I only have another couple of days to upload the assignment and it counts to my final grade.
Mar 9, 2020 at 1:28am
It would be a bit more helpful to give each CPP a different code bracket, and label the one that you're working on.


Your combat class has a Character member, so adding/removing health should be as simple as hero.set_health(12) or whatever number health they should have. So you can do something like this when the hero defeats a monster:

hero.set_health(hero.get_health() + (whatever number); You already have this as line 228 for when a monster is defeated.


This is your main function to focus on: void Combat::start()

This is the function that's going to dictate the entire combat situation, with a loop for the monsters to attack the hero, checking if the hero is dead, gives the user attack choices, and then follows through with it.


Honestly, most of the code is already there. You should make this change however:

1
2
3
4
5
6
7
8
9
Combat::Combat(int newNumberOfMonsters) 
:hero("Hero", 30, 3, 5), NumberOfMonsters(newNumberOfMonsters), tokens(2)
{
     for(int i = 0; i < newNumberOfMonsters; i++)
    {
         Character M("Monster", 5, 2, 0);
	 monsterList.push_back(M);
    }
}



This new constructor will make as many monsters as called for in the int main, pushing each on into the vector monsterList.



You should try coding this and fixing the errors that come up, if you get stuck on something in particular, you can ask and you'll get better help :)



EDIT:

I highly recommend learncpp.com to learn anything in C++ that you're not 100% about. You can go there and get some good information on things like classes, which may help you with this assignment.
Last edited on Mar 9, 2020 at 1:30am
Mar 9, 2020 at 2:17am
Wow! Thanks so much for the info!

As per your suggestion, I edited the post to make it easier to distinguish between the files. Also, I cannot make any changes or add anything except after where it says "Put your code below:" - in case you or anyone thought otherwise...

Just one other thing though; how comes no errors seem to be showing yet when I run the program, I get building errors?

I personally think it's because of this statement:

cout << hero.get_name() << " attacks Monster" << monsterList[i] << endl;

because a red error bar pops up here. But, when I change "monsterList[i] to monsterList[i].get_name", the red thing disappers but the code still brings errors.

This, in turn, makes me think that the error lies here:

cout << "Monster" << monsterList[i].get_name() << " health: " << monsterList[i].get_health() << endl;

I'm not exactly sure where the error is but there is one somewhere - and the compiler can't seem to display it.
I have no idea how to find the error; I was initially trying breaking points but to no avail.
In your opinion, do you think I missed some code somewhere or utilized a wrong command?
Last edited on Mar 9, 2020 at 2:22am
Mar 9, 2020 at 2:29am
In function void Combat::checkAliveMonster(), the if statement has monsterList[i].get_health instead of monsterList[i].get_health()

Also, don't forget #include <vector> since the class Combat uses it.

After making those two changes and then adding the constructor I recommended, the program compiled took user input to play. I'm not fully sure of how the gameplay should be, it may have some kinks in the code that need ironing out. Here's the full code that I compiled (all in one program and not separate):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>

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;
};

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 << name << " attacks " << target.name << " doing " << damage << " damage!" << endl;
	cout << target.name << " health: " << target.health << endl;
}

void Character::rangedAttack(Character& target)
{
	if (arrows == 0)
		cout << name << " is out of arrows!" << endl;
	else
	{
		int rangedDamage = rand() % 5 + 1;
		target.health -= rangedDamage;
		arrows--;
		cout << name << " shoots " << target.name << " doing " << rangedDamage << " damage!" << endl;
		cout << target.name << " health: " << target.health << endl;
	}
}

void Character::display() const
{
	cout << name << "  health: " << health << "  arrows: " << arrows << endl;
}

string Character::get_name() const
{
	return name;
}

int Character::get_health() const
{
	return health;
}

class Combat
{
public:
	Combat();
	Combat(int newNumberOfMonsters);

	void attackAll();
	void start();
	void checkAliveMonster();

	void printMonsterList() const;


private:
	int NumberOfMonsters;
	vector<Character> monsterList;
	Character hero;
	int tokens;
};

Combat::Combat()
	:hero("Hero", 30, 3, 5), NumberOfMonsters(1), tokens(2)
{
	Character M("Monster", 5, 2, 0);
	monsterList.push_back(M);
}

Combat::Combat(int newNumberOfMonsters)
	:hero("Hero", 30, 3, 5), NumberOfMonsters(newNumberOfMonsters), tokens(2)
{
	for (int i = 0; i < newNumberOfMonsters; i++)
	{
		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 < NumberOfMonsters; i++)
			monsterList[i].attack(hero);
		cout << "----------------------\n";
		if (hero.get_health() <= 0)
			break;
		hero.display();
		cout << hero.get_name() << " has " << tokens << " tokens left.\n";
		cout << "----------------------\n";
		printMonsterList();
		cout << "What do you do? 1 attack, 2 fire arrow, 3 attack all,  Q exit: ";
		cin >> choice;
		if (choice == 1 || choice == 2)
		{
			cout << "Which monster do you want to attack? (0-" << NumberOfMonsters - 1 << "): " << endl;
			cin >> iMonster;
			if (cin.fail() || iMonster >= NumberOfMonsters)
			{
				cout << "Input Error!\n";
				break;
			}
		}
		cout << "----------------------\n";
		switch (choice)
		{
		case 1:
			hero.attack(monsterList[iMonster]);
			break;

		case 2:
			hero.rangedAttack(monsterList[iMonster]);
			break;

		case 3:
			attackAll();
			break;

		default:
			cout << "Input error!\n";
			break;
		}
		checkAliveMonster();
		cout << "----------------------\n";
	}
	if (NumberOfMonsters == 0)
		cout << "Congratulations! You have killed all the monster!" << endl;
	if (hero.get_health() <= 0)
		cout << "You have died! GAME OVER! " << endl;

	cout << "Thanks for playing!" << endl;

}
// Put your code below:
//IMPLEMENTATIONS
void Combat::attackAll() {
	if (tokens != 0) {
		vector<int> monsterList{ 0, 1, 2 };
		for (int i = 0; i < NumberOfMonsters - 1; i++) {
			cout << hero.get_name() << " attacks " << monsterList[i] << endl;
		}
		--tokens;
	}
	else if (tokens == 0) {
		cout << "Hero is out of tokens!";
	}
}
void Combat::checkAliveMonster() {
	for (int i = 0; i < NumberOfMonsters - 1; i++) {
		if (monsterList[i].get_health() <= 0) {
			--NumberOfMonsters;
			cout << "You killed a monster!" << endl;
			hero.set_health((hero.get_health() + 5));
			cout << "Hero gets 5 health bonus points!" << endl;
			++tokens;
			cout << "Hero gets 1 bonus tokens!" << endl;
		}
	}
}
void Combat::printMonsterList() const {
	for (int i = 0; i < NumberOfMonsters - 1; i++) {
		cout << "Monster" << monsterList[i].get_name() << "   health: " << monsterList[i].get_health();
	}

}

int main()
{
	Combat game(3);
	game.start();

	return 0;
}
Mar 9, 2020 at 2:31am
BTW, I recommend using Visual Studio, it's a really good IDE. I recommend an IDE instead of using a terminal to compile code.
Mar 9, 2020 at 2:48am
Oh alright, I see where the code went wrong... It seems to run now *Silently screams "Yay"*

I removed this piece of code cause it seemed unnecessary:
vector<int> monsterList{ 0, 1, 2 };

I replaced the following (from void Combat::attackAll()):
cout << hero.get_name() << " attacks " << monsterList[i] << endl;

with this:
hero.attack(monsterList[i]);

I hope that's ok? Though it again brings up build errors...

EDIT: Nevermind. Just realized it runs now... All I now need is to display the vectors as "Monster0", "Monster1" and "Monster2" instead of just "Monster" and figure out what "c++ debug assertion failed vector subscript out of range" means...

Also, I currently use Visual Studio (though I kinda prefer CodeBlocks)



Last edited on Mar 9, 2020 at 3:34am
Mar 9, 2020 at 4:25am
EDIT: Nevermind. Just realized it runs now... All I now need is to display the vectors as "Monster0", "Monster1" and "Monster2" instead of just "Monster" and figure out what "c++ debug assertion failed vector subscript out of range" means...

I didn't get any error like that, but glad you fixed it. Removing the vector line is not wise, you need to hold the Character objects that are the monsters the Hero fights.

Also, I currently use Visual Studio (though I kinda prefer CodeBlocks)

To each their own, but Visual Studio is very powerful :))
Mar 9, 2020 at 5:34am
I'm not 100% sure about the vector line cause when I add it, it brings back the red error bars...

Really? You didn't get that error. I searched it up and it's because, according to someone on another forum:

"Well, the debugger shows you the error reason very clear: "vector subscript out of range"!
So you are trying to use the vector index that is => the vector size!
And it is what you have now to fix!"

Following this, I made some changes to the implementations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//IMPLEMENTATIONS
Combat::Combat(int newNumberOfMonsters)
	:hero("Hero", 30, 3, 5), NumberOfMonsters(newNumberOfMonsters), tokens(1)
{
	for (int i = 0; i <= NumberOfMonsters -1; i++)
	{
		Character M("Monster", 5, 2, 0);
		monsterList.push_back(M);
	}
}
void Combat::attackAll() {

	if (tokens != 0) {
		for (int i = 0; i <= NumberOfMonsters-1; i++) {
			hero.attack(monsterList[i]);
		}
		--tokens;
	}
	else if (tokens == 0) {
		cout << "Hero is out of tokens!" << endl;
	}
}
void Combat::checkAliveMonster() {
	for (int i = 0; i <= NumberOfMonsters-1; i++) {
		if (monsterList[i].get_health() <= 0) {
			monsterList.erase(monsterList.begin()+i);
			cout << "You killed a monster!" << endl;
			hero.set_health((hero.get_health() + 5));
			cout << "Hero gets 5 health bonus points!" << endl;
			++tokens;
			cout << "Hero gets 1 bonus tokens!" << endl;
		}
		else {
			continue;
		}
	}
}
void Combat::printMonsterList() const {
	for (int i = 0; i <= NumberOfMonsters-1; i++) {
		cout << monsterList[i].get_name() << i << "   health: " << monsterList[i].get_health() << endl;
	}	
}


The issue still keeps arising though and I've narrowed it down to this specific set of code (I think):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Combat::checkAliveMonster() {
	for (int i = 0; i <= NumberOfMonsters-1; i++) {
		if (monsterList[i].get_health() <= 0) {
			monsterList.erase(monsterList.begin()+i);
			cout << "You killed a monster!" << endl;
			hero.set_health((hero.get_health() + 5));
			cout << "Hero gets 5 health bonus points!" << endl;
			++tokens;
			cout << "Hero gets 1 bonus tokens!" << endl;
		}
		else {
			continue;
		}
	}
}


To each their own, indeed.
Last edited on Mar 9, 2020 at 5:35am
Mar 9, 2020 at 6:09am
Is vector monsterList[] supposed to have NumberOfMonsters items in it?

Because if you erase items from it, then it will no longer have NumberOfMonsters in it. So your for-loop will (a) lead to you going beyond the end of the array; (b) jumping over the item immediately after the one you erase without considering it.
Mar 9, 2020 at 5:44pm
Yes, it is I suppose, but I don't know where it is declared. The thing is, if I introduce the following line of code(in Combat::Combat(int newNumberOfMonsters)):
vector<int> monsterList{NumberOfMonsters};
It brings up an error on this line:
monsterList.push_back(M);
And if I remove monsterList.push_back(M); it brings up the same error message: "c++ debug assertion failed vector subscript out of range"

Also, I need to erase the ith element from the vector ie. the dead monster.
I'm fairly uncertain of what to do at this point.
Any fixes?
Last edited on Mar 9, 2020 at 5:51pm
Mar 9, 2020 at 5:51pm
It should be:

vector<Character> monsterList;

Put in <> The TYPE of objects the vector needs to hold. Look at the code I posted which compiled and ran. You should also read up on vectors:

https://www.learncpp.com/cpp-tutorial/6-16-an-introduction-to-stdvector/
Mar 9, 2020 at 6:23pm
After adding

vector<Character> monsterList;

it builds but immediately brings up the same error message again.

I read up on vectors from the book Big C++ but I never figured that you can define the type of vector as Character; I thought it must be "int", "string" or something similar.
Mar 9, 2020 at 8:07pm
I thought it must be "int", "string" or something similar.

What makes std::vector so powerful is that it can be a vector of any object type.

Suggestion:
Instead of:
for (int i = 0; i <= NumberOfMonsters-1; i++)
Use:
for (int i = 0; i < monstersize.size(); i++)
You don't need to keep track of the number of monsters yourself. A std::vector<> automatically keeps track of how many entries are in the vector.

monsterList.erase(monsterList.begin()+i);
You're not adjusting NumberOfMonsters.
Also, since you deleted a monster, by using i, you're going to be skipping over a monster.
i.e. Lets say you deleted monster[3]. erase moves monster[4] to monster[3] slot.
The next iteration of the loop, i is 4, and the monster that is now in slot 3 is never checked.

Mar 9, 2020 at 9:07pm
I see.

I added the line:

--NumberOfMonsters;

and it now runs fine.

Two follow-up questions though:
1) How do I make the vector display "monster0", "monster1" and "monster2" using the vector alone rather than outputting the ith term after the monster's name i.e. how do I output, say, "monster 0" using
cout << monsterList[i].get_name()
instead of
cout << monsterList[i].get_name() << i
?
2) How do I adjust checkAliveMonster so that when I kill a monster, that monster is removed. Right now, the program works as follows:
If prompted to input which monster I want to attack and I input, say 1, and I end up killing that monster, the program says that the monsters "monster0" and "monster1" are alive and removes "monster2" despite the fact that "monster1" was killed. How do you suggest I fix this?

EDIT: I'm trying to use "insert" to add i to the monsterList but the it doesn't work probably because i is an int and monsterList is a vector of type "Character"...

EDIT2: I FINALLY FIGURED OUT ALL THE CODE! A friendly professor showed my one of the tiny errors I made and it fixed everything. THANKS EVERYONE WHO HELPED OUT!
Last edited on Mar 10, 2020 at 1:36am
Mar 10, 2020 at 2:38am
EDIT2: I FINALLY FIGURED OUT ALL THE CODE! A friendly professor showed my one of the tiny errors I made and it fixed everything. THANKS EVERYONE WHO HELPED OUT!

Congratz, it was a bit weird how the code you started with compiled and the more code you posted, the more there were minor changes with errors!
Mar 10, 2020 at 5:39pm
Yep. Now it's onto the second issue of Matrices. Thanks!
Mar 11, 2020 at 6:04pm
Hey, any chance you can help me with my Matrix problem? I've posted it but cannot finish or solve it? It's due in a few hours...
Mar 12, 2020 at 5:38am
Sorry, just saw this, too late now :(
Pages: 12