-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallvsall.cpp
87 lines (73 loc) · 1.98 KB
/
allvsall.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
#include "allvsall.h"
allvsall::allvsall()
{
this->this_monster_index=0;
this->next_monster_index=0;
}
void allvsall::allvsall_Definition()
{
Monster** winners = new Monster*[this->scheme_fighters.size()];
for(int i = 0; i < this->scheme_fighters.size(); i++)
{
winners[i]=this->scheme_fighters[i];
winners[i]->setMaxHealth(this->scheme_fighters[i]->getHealth());
}
for (int i = 0; i < this->scheme_fighters.size(); i++)
{
for (int j = i+1; j < this->scheme_fighters.size(); j++)
{
while(winners[i]->isAlive() && winners[j]->isAlive())
{
Monster* toGetPoint = &(winners[i]->fight(*winners[j]));
toGetPoint->givePoint();
}
winners[i]->resetHealth();
winners[j]->resetHealth();
}
}
this->serialize();
delete [] winners;
}
void allvsall::serialize()
{
ofstream write_to_file;
write_to_file.open("allvsall_serialized.txt");
write_to_file << "Tournament type: ALL VS ALL" << endl;
for (int i = 0; i < this->getNumOfFighters(); i++)
{
write_to_file << this->scheme_fighters[i]->getName() << " has "
<< this->scheme_fighters[i]->getPoints().getPoint() << " points." << endl;
}
write_to_file.close();
}
void allvsall::print()
{
for(int i = 0; i < this->getNumOfFighters();++i)
{
cout << this->scheme_fighters[i]->getName() << " has " << this->scheme_fighters[i]->getPoints().getPoint() << endl;
}
}
const int allvsall::getNextMonsterIndex() const
{
return next_monster_index;
}
const int allvsall::getThisMonsterIndex() const
{
return this_monster_index;
}
void allvsall::addFighter(Monster& other)
{
this->scheme_fighters.push_back(&other);
}
const int allvsall::getNumOfFighters() const
{
return this->scheme_fighters.size();
}
void allvsall::increment_this_monster_index()
{
this->this_monster_index++;
}
void allvsall::increment_next_monster_index()
{
this->next_monster_index++;
}