-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arena.cpp
113 lines (101 loc) · 2.39 KB
/
Arena.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
104
105
106
107
108
109
110
111
112
113
#include "Arena.h"
#include "ArenaInterface.h"
#include "Cleric.h"
#include "Archer.h"
#include "Robot.h"
#include <sstream>
#include <iostream>
#include <vector>
using namespace std;
Arena::Arena()
{
}
bool Arena::addFighter(string info)
{
istringstream in(info);
in >> name >> type >> health >> strength >> speed >> magic;
if (in.fail() || !in.eof())
{
return false;
}
// cout << "\nValues in: \nName: " << name << " Type: " << type << " Health: " << health << " Strength: " << strength << " Speed: " << speed << " Magic: " << magic << "\n";
if (getFighter(name))
{
return false;
}
if (health < 1)
{
return false;
}
if (strength < 1)
{
return false;
}
if (speed < 1)
{
return false;
}
if (magic < 1)
{
return false;
}
if (type == "C")
{
Cleric* bob = new Cleric(name, health, strength, speed, magic);
fighters.push_back(bob);
// cout << "\nCleric name, health, strength, speed, magic: " << name << " " << type << " " << health << " " << strength << " " << speed << " " << magic << "\n";
}
else if (type == "A")
{
Archer* steve = new Archer(name, health, strength, speed, magic);
fighters.push_back(steve);
// cout << "\nArcher name, health, strength, speed, magic: " << name << " " << type << " " << health << " " << strength << " " << speed << " " << magic << "\n";
}
else if (type == "R")
{
Robot* fred = new Robot(name, health, strength, speed, magic);
fighters.push_back(fred);
// cout << "\nRobot name, health, strength, speed, magic: " << name << " " << type << " " << health << " " << strength << " " << speed << " " << magic << "\n";
}
else
{
return false;
}
return true;
}
/*
* removeFighter(string)
*
* Removes the fighter whose name is equal to the given name. Does nothing if
* no fighter is found with the given name.
*
* Return true if a fighter is removed; false otherwise.
*/
bool Arena::removeFighter(string name)
{
for (int i = 0; i < fighters.size(); i++)
{
if (fighters[i]->getName() == name)
{
fighters.erase(fighters.begin() +i);
return true;
}
}
return false;
}
FighterInterface* Arena::getFighter(string name)
{
for (int i = 0; i < fighters.size(); i++)
{
if (fighters[i]->getName() == name)
return fighters[i];
}
return NULL;
}
int Arena::getSize() const
{
return fighters.size();
}
Arena::~Arena()
{
}