Coverage report for gui


src/
File: src/render/scenes/world/ui/Ranking.hpp
Date: 2024-06-25 10:57:02
Lines:
0/31
0.0%
Functions:
0/3
0.0%
Branches:
0/62
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy
4 ** File description:
5 ** Ranking
6 */
7
8 #ifndef RANKING_HPP_
9 #define RANKING_HPP_
10
11 #include "../../../../parser/Data.hpp"
12
13 class Ranking {
14 public:
15 int _nbPlayer;
16 int _highestLevel;
17 int _score;
18 std::string _teamName;
19
20 static void sortRanking(std::vector<Ranking> &ranking) {
21 std::sort(ranking.begin(), ranking.end(), [](Ranking &a, Ranking &b) {
22 if (a._score == b._score) {
23 return a._highestLevel > b._highestLevel;
24 }
25 return a._score > b._score;
26 });
27 }
28
29 static void getRanking(std::vector<Ranking> &ranking, Data &data) {
30 ranking.clear();
31 auto teams = data.getTeams();
32 for (auto &team : teams) {
33 Ranking rank;
34 rank._teamName = team;
35 rank.getRanking(data);
36 ranking.push_back(rank);
37 }
38 sortRanking(ranking);
39 }
40
41 void getRanking(Data &data) {
42 _nbPlayer = 0;
43 _highestLevel = 0;
44 _score = 0;
45 auto players = data.getPlayers();
46 for (auto &player : players) {
47 if (player.second->getAlive() == false)
48 continue;
49 if (player.second->getTeam() == _teamName) {
50 _nbPlayer++;
51 _score += player.second->getLvl() * 15;
52 _score += 10;
53 if (player.second->getLvl() > _highestLevel)
54 _highestLevel = player.second->getLvl();
55 }
56 }
57
58 }
59 };
60
61 #endif /* !RANKING_HPP_ */
62