-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.c
64 lines (56 loc) · 1.81 KB
/
Player.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "Player.h"
//Initialisierung des Spielers
void initPlayer(Player *player) {
player->scorecard = initializeScorecard();
}
/* Initialisierung der Liste aller Spieler
* @param Spieleranzahl
* @return Liste aller Spielern
*/
PlayerList *initializePlayerList(int amountOfPlayers) {
PlayerList *list = malloc(sizeof(PlayerList) + amountOfPlayers * sizeof(Player));
list->size = amountOfPlayers;
for (int i = 0; i < amountOfPlayers; ++i) {
initPlayer(&list->players[i]);
}
return list;
}
//Freigeben des Speichers der Spielerliste
void destructPlayerList(PlayerList *playerList) {
for(int i = 0; i < playerList->size; i++) {
if(playerList->players[i].name) {
free(playerList->players[i].name);
}
}
free(playerList);
}
/* Setzen des Spielernamens
* @param Spieler, Spielername
* @return none
*/
void setPlayerName(Player *player, char *name) {
player->name = malloc(strlen(name) + 1);
strcpy(player->name, name);
}
//Gibt die spielerspezifische Spielerkarte aus
void printCurrentScoreboard(Player *player) {
printf("\nYour current Scoreboard\n");
for (int i = 0; i < player->scorecard->size; ++i) {
printf("%d: %s, Value: %d \n", i + 1, player->scorecard->entries[i].name, player->scorecard->entries[i].value);
}
printf("\n");
}
//Gibt die Einträge aus, die noch nicht bespielt worden sind
void printRemainingScoreboardEntries(Player *player) {
printf("\nAvailable Entries\n");
for (int i = 0; i < player->scorecard->size; ++i) {
if (player->scorecard->entries[i].hasBeenPlayed == false) {
printf("%d: %s - %s \n", i + 1, player->scorecard->entries[i].name,
player->scorecard->entries[i].description);
}
}
printf("\n");
}