-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.h
98 lines (81 loc) · 2.84 KB
/
team.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
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include "player.h"
#include "user_interface.h"
class Team
{
public:
Team(std::string name, std::string coach);
void addPlayer(Player player);
void removePlayer(Player player);
void selectLineup();
void printTeam(bool fullInfo);
void calculateAttackAndDefenceStrength();
std::string getName();
int getAttackStrength();
int getDefenceStrength();
private:
UserInterface userInterface;
std::string name;
std::string coach;
int attackStrength;
int defenceStrength;
std::vector<Player> players;
std::vector<Player> lineup;
};
Team::Team(std::string name, std::string coach)
:name(name), coach(coach) {};
void Team::addPlayer(Player player) { players.push_back(player); }
std::string Team::getName() { return name;}
void Team::removePlayer(Player player)
{
auto it = std::find(players.begin(), players.end(), player);
if(it!=players.end())
players.erase(it);
}
bool compareOveralls (Player p1, Player p2) { return p1.getStats().getOverall()>p2.getStats().getOverall();}
void Team::selectLineup()
{
//Select the lineup based on some player's overall
std::sort(players.begin(), players.end(), compareOveralls);
lineup.clear();
for (int i = 0; i < 3; ++i) {
lineup.push_back(players[i]);
}
}
void Team::printTeam(bool fullInfo)
{
if(fullInfo) {
userInterface.print("Team: "+name+'\n',userInterface.COLOR_YELLOW);
}
userInterface.print("Coach: "+name+'\n',userInterface.COLOR_YELLOW);
userInterface.print("Attack Strength: "+std::to_string(attackStrength)+'\n',userInterface.COLOR_YELLOW);
userInterface.print("Defence Strength: "+std::to_string(defenceStrength)+'\n',userInterface.COLOR_YELLOW);
if(fullInfo) {
userInterface.print("Players:\n",userInterface.COLOR_YELLOW);
for (auto& player : players) {
userInterface.print("- " + player.getName()+'\n',userInterface.COLOR_UNDERLINE);
}
}
userInterface.print("Starting Lineup:\n",userInterface.COLOR_YELLOW);
for (auto& player : lineup) {
userInterface.print("- " + player.getName() + ": Overall Rating - " + std::to_string(player.getStats().getOverall())+'\n',userInterface.COLOR_UNDERLINE);
}
}
void Team::calculateAttackAndDefenceStrength()
{
int totalAttack=0;
int totalDefence=0;
for(auto& player : players)
{
totalAttack+=player.getStats().getAttack();
totalDefence+=player.getStats().getDefence();
}
int numberOfPlayers=players.size();
attackStrength=totalAttack/numberOfPlayers;
defenceStrength=totalDefence/numberOfPlayers;
}
int Team::getAttackStrength() { return attackStrength;}
int Team::getDefenceStrength() { return defenceStrength; }