-
Notifications
You must be signed in to change notification settings - Fork 0
/
scores.c
48 lines (41 loc) · 1 KB
/
scores.c
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
#include <string.h>
#include "scores.h"
score_t scores[SCORES_MAX];
char nick[NICK_MAX];
int f_nickform_needs_redraw;
void scores_init()
{
int i;
for (i = 0; i < SCORES_MAX; i++) {
strncpy(scores[i].nick, "EMPTY ", NICK_MAX);
scores[i].nick[NICK_MAX+1] = '\0';
scores[i].value = 0;
}
return;
}
int scores_ishigh(int value)
{
int i;
for (i = 0; i < SCORES_MAX; i++) {
if (scores[i].value < value)
return 1;
}
return 0;
}
int scores_insert(char *nick, int value)
{
int i,j;
for (i = 0; i < SCORES_MAX; i++) {
if (scores[i].value < value) {
/* move all smaller scores down the list */
for (j=i; j < SCORES_MAX-1; j++) {
strncpy(scores[j+1].nick, scores[j].nick, NICK_MAX);
scores[j+1].value = scores[j].value;
}
strncpy(scores[i].nick, nick, NICK_MAX);
scores[i].value = value;
return 0;
}
}
return -1;
}