-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scoreboard.cpp
82 lines (68 loc) · 1.5 KB
/
Scoreboard.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
#include "Scoreboard.h"
Scoreboard::Scoreboard(unsigned int num, NetManager* nm, bool s)
{
numPlayers = num;
net = nm;
server = s;
playerScore = new unsigned int[numPlayers];
resetAll();
}
Scoreboard::~Scoreboard()
{
if(playerScore) // != null
delete[] playerScore;
}
void Scoreboard::resetAll()
{
for(int num = 1; num <= numPlayers; ++num)
resetScore(num);
highScore = 0;
}
void Scoreboard::resetScore(int num)
{ //check indexing bounds
if (num <= numPlayers && num > 0)
playerScore[num-1] = 0;
// if(net)
// {
// if(server)
// {
// const char buf[128] = {0};
// char message = 'r';
// char * c_buf = (char*)buf;
// c_buf[0] = message;
// c_buf[2] = (char) num;
// net->messageClients(PROTOCOL_UDP,buf, sizeof(buf));
// }
// }
}
void Scoreboard::addScore(int points, int num)
{ //check indexing bounds
if (num <= numPlayers && num > 0)
{
playerScore[num-1] += points;
if (highScore < playerScore[num-1])
highScore = playerScore[num-1];
}
// if(net)
// {
// if(server)
// {
// const char buf[128] = {0};
// char message = 'a';
// char * c_buf = (char*)buf;
// c_buf[0] = message;
// c_buf[1] = (char) points;
// c_buf[2] = (char) num;
// net->messageClients(PROTOCOL_UDP,buf, sizeof(buf));
// }
// }
}
unsigned int Scoreboard::getScore(int num)
{ //check indexing bounds
if (num <= numPlayers && num > 0)
return playerScore[num-1];
else return 0;
}
unsigned int Scoreboard::getHighScore()
{ return highScore;
}