Coverage report for gui


src/
File: src/parser/Player.cpp
Date: 2024-06-25 10:57:02
Lines:
64/64
100.0%
Functions:
21/21
100.0%
Branches:
20/26
76.9%

Line Branch Exec Source
1 #include "Player.hpp"
2
3 //-----------------------------------------------------------------//
4 //----------------------------SETTERS------------------------------//
5 //-----------------------------------------------------------------//
6
7 4 void Player::setPosition(std::vector<int> newPos) {
8 4 nextPositions.push_back(newPos);
9
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
4 if (!events.empty() && events.back().action == PUSHED) {
10 1 events.back().params = newPos;
11 1 return;
12 }
13 6 events.push_back(Event(MOVING, newPos));
14 };
15
16 2 void Player::setOrientation(int newOrientation) {
17 2 this->orientation = newOrientation;
18 2 };
19
20 3 void Player::setIncanting() {
21
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 events.push_back(Event(INCANTATING));
22 3 };
23
24 3 void Player::setEgging() {
25
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 events.push_back(Event(EGGING));
26 3 };
27
28 3 void Player::setPushed() {
29
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 events.push_back(Event(PUSHED));
30 3 };
31
32 2 void Player::setPickup(int res) {
33 2 events.push_back(Event(PICKUP, std::vector<int>({res})));
34 2 };
35
36 2 void Player::setDrop(int res) {
37 2 events.push_back(Event(DROP, std::vector<int>({res})));
38 2 };
39
40 3 void Player::setAlive(bool alive) {
41 3 this->isAlive = alive;
42 3 };
43
44 2 void Player::setLvl(int newLvl) {
45 2 this->lvl = newLvl;
46 2 events.push_back(Event(LVLUP, std::vector<int>({newLvl})));
47 2 };
48
49 1 void Player::setTeam(std::string newTeam) {
50 1 this->team = newTeam;
51 1 };
52
53 1 void Player::setPlayerNb(int newId) {
54 1 this->id = newId;
55 1 };
56
57 3 void Player::setInventory(std::vector<int> inventoryVals) {
58 3 this->inventory = inventoryVals;
59 3 };
60
61 //-----------------------------------------------------------------//
62 //----------------------------GETTERS------------------------------//
63 //-----------------------------------------------------------------//
64
65
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
13 Event Player::getNextEvent() {
66
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
13 if (events.empty())
67 return NONE;
68 10 Event event = events.front();
69
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (event.action == MOVING)
70
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 popNextPosition();
71
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (event.action == PUSHED)
72
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 popNextPosition();
73 events.erase(events.begin());
74 return event;
75 };
76
77 9 std::vector<int> Player::getPosition() {
78 9 return {position};
79 };
80
81 3 int Player::getOrientation() {
82 3 return this->orientation;
83 };
84
85 3 int Player::getLvl() {
86 3 return this->lvl;
87 };
88
89 3 std::string Player::getTeam() {
90 3 return this->team;
91 };
92
93 3 int Player::getPlayerNb() {
94 3 return this->id;
95 };
96
97 4 bool Player::getAlive() {
98 4 return this->isAlive;
99 };
100
101 11 std::vector<int> Player::getInventory() {
102 11 return this->inventory;
103 };
104
105 //-----------------------------------------------------------------//
106 //---------------------------UTILITIES-----------------------------//
107 //-----------------------------------------------------------------//
108
109
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 void Player::popNextPosition() {
110
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (nextPositions.empty())
111 return;
112 3 this->position = nextPositions.front();
113 nextPositions.erase(nextPositions.begin());
114 };
115