Coverage report for gui


src/
File: src/parser/Data.hpp
Date: 2024-06-25 10:57:02
Lines:
11/12
91.7%
Functions:
2/3
66.7%
Branches:
13/37
35.1%

Line Branch Exec Source
1 #ifndef DATA_HPP
2 #define DATA_HPP
3
4 #include "Map.hpp"
5 #include "Egg.hpp"
6 #include "Player.hpp"
7 #include "Incantation.hpp"
8 #include "Broadcast.hpp"
9 #include "ServerConnect.hpp"
10
11 #include <memory>
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <optional>
16
17 class Data
18 {
19 private:
20 int tickRate = 0;
21 std::vector<std::string> teamNames = {};
22 std::map<int, Egg> eggs = {};
23 std::map<int, std::shared_ptr<Player>> players = {};
24 std::vector<std::shared_ptr<Incantation>> incantations = {};
25 std::vector<Broadcast> broadcasts = {};
26 std::optional<std::string> winner = std::nullopt;
27 Map map = Map();
28
29 public:
30 91 Data() {};
31 264 ~Data() {};
32
33 /**
34 * @brief Set the tick rate of the game high values will make the game run faster
35 * @param rate between 2 and 10000
36 * @return void
37 */
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
3 void setTickRate(int rate) { this->tickRate = rate; };
39
3/7
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 int getTickRate() { return this->tickRate; };
40 void requestNewTickRate(int rate, ServerConnect &server) { server.sendToServer(std::string("sst " + std::to_string(rate) + "\n")); };
41
42
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 void setWinner(std::string team) { this->winner = team; };
43 2 std::optional<std::string> getWinner() { return this->winner; };
44
45 /**
46 * @brief Add an egg to the game
47 * @param values the values of the egg
48 * @param playerId the id of the player that laid the egg
49 * @param state the state of the egg
50 * @return void
51 */
52 void addEgg(std::vector<int> pos, int eggId, int playerId, EggStatus state);
53 std::map<int, Egg> &getEggs() { return this->eggs; };
54 Egg &getEggById(int eggid);
55
56
57
5/10
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 void addTeam(std::string team) { this->teamNames.push_back(team); };
58
1/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 std::vector<std::string> getTeams() { return this->teamNames; };
59 std::string getTeamByName(std::string name);
60 bool doesTeamExist(std::string team);
61
62
63 void addPlayer(std::vector<int> values, std::string teamName);
64 2 std::map<int, std::shared_ptr<Player>> getPlayers() { return players; };
65
66 /**
67 * @brief Get the player corresponding to the given id
68 * @param id the id of the player (player number)
69 * @return a reference to the player
70 * @throw guiException if the player does not exist
71 */
72 std::shared_ptr<Player> getPlayerById(int id);
73 bool playerExists(int id);
74
75
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1 std::vector<std::shared_ptr<Incantation>> getIncantations() { return this->incantations; };
76 std::shared_ptr<Incantation> getIncantationByPos(std::vector<int> pos);
77 void addIncantation(std::vector<int> pos, int lvl, std::vector<int> playersId);
78
79 std::vector<Broadcast> &getBroadcasts() { return this->broadcasts; };
80 std::optional<Broadcast> getNextBroadcast();
81 void addBroadcast(int playerNb, std::vector<int> pos, std::string msg);
82
83
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4 Map &getMap() { return this->map; };
84
85 void resetGame();
86 };
87
88 #endif // DATA_HPP
89