-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameInfo.c
executable file
·43 lines (37 loc) · 1.06 KB
/
gameInfo.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
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "gameInfo.h"
static bool transformBool(long value) {
if (1 == value) return true;
return false;
}
// Initialize all players
void initializePlayers(gameInfo *info) {
playerInfo *players = info->players;
for (int i = 0; i < MAXPLAYERS; i++) {
players[i].free = true;
}
}
// Add new player to the list
playerInfo *pushPlayer(gameInfo *info, char *id, char *name, long ready) {
// Find first free player
playerInfo *player = NULL;
playerInfo *players = info->players;
for (int i = 0; i < MAXPLAYERS; i++) {
if (players[i].free == true) {
player = &players[i];
players[i].free = false;
break;
}
}
// If player list is full
if (NULL == player) return NULL;
// Set player data
strncpy(player->id, id, IDLENGTH - 1);
player->id[IDLENGTH - 1] = 0;
strncpy(player->name, name, NAMELENGTH - 1);
player->name[NAMELENGTH - 1] = 0;
player->ready = transformBool(ready);
return player;
}