-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.c
74 lines (55 loc) · 1.6 KB
/
sample.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
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
// Short comment
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
#define MAX_PLAYERS (4)
typedef enum {
Difficulty_easy,
Difficulty_hard,
} Difficulty;
typedef struct {
const char* name;
float position[3];
int health;
} Player;
typedef struct {
Difficulty difficulty;
Player players[MAX_PLAYERS];
int player_count;
} Game;
typedef Player (*FindPlayerByNameFunc)(const char* name);
static int really_long_function(int argument_a, int argument_b, int argument_c, int argument_d, int argument_e, int argument_f, int argument_g){
return argument_a + argument_b + argument_c + argument_d + argument_e + argument_f + argument_g;
}
static void play(const Game* game){
int monsters = 0;
switch (game->difficulty){
case Difficulty_easy:
monsters = 5;
break;
case Difficulty_hard:
monsters = 10;
break;
}
for (int i = 0; i < game->player_count; i++){
const Player* player = &game->players[i];
const int damage = monsters * 10;
if (damage >= player->health){
printf("%s died fighting %i monsters\n", player->name, monsters);
}else{
printf("%s survived\n", player->name);
}
}
}
int main() {
const Player p1 = {
.name = "Steve",
.position = {0.f, 0.f, 0.f},
.health = 100,
};
const Game game = {
.difficulty = Difficulty_easy,
.players = { p1 },
.player_count = 1
};
play(&game);
}