-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart_game.c
112 lines (102 loc) · 2.74 KB
/
start_game.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* start_game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/05 21:31:57 by ydeineha #+# #+# */
/* Updated: 2018/09/05 21:32:00 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
unsigned char *create_board(t_player *player)
{
unsigned char *board;
int i;
i = -1;
if (!(board = (unsigned char *)malloc(sizeof(unsigned char) * MEM_SIZE)))
{
perror("malloc() in create_board() failed ");
error(-1);
}
board = ft_memset(board, 0, MEM_SIZE);
while (++i < g_game.players)
ft_memcpy(&board[player[i].start], player[i].comms, player[i].len);
return (board);
}
void dump(void)
{
int i;
i = 0;
while (i < MEM_SIZE)
{
if (i % 64 == 0)
{
if (i != 0)
ft_printf("\n");
if (i == 0)
ft_printf("0x0000 : ");
else
ft_printf("%#06x : ", i);
}
ft_printf("%02x ", g_game.board[i]);
i++;
}
ft_printf("\n");
}
static void introduce(void)
{
int i;
t_player *p;
i = -1;
p = g_game.player;
ft_printf("Introducing contestants...\n");
while (++i < g_game.players)
{
ft_printf("* Player %i, weighing %i bytes, \"%s\" (\"%s\") !\n",
p[i].num, p[i].len, p[i].name, p[i].comment);
}
}
static void winner(void)
{
int num;
num = g_game.player_last_live;
if (num >= 1 && num <= g_game.players)
{
if (!g_game.visu)
ft_printf("Contestant %i, \"%s\", has won !\n",
num, g_game.player[num - 1].name);
else
{
wattron(g_game.win, COLOR_PAIR(num));
mvwprintw(g_game.win, 65, 64 * 3 + 7, "Contestant %i, \"%s\", has won !\n",
num, g_game.player[num - 1].name);
system("pkill afplay");
system("afplay /Users/ydeineha/corwar_fin/visu/audio/win.mp3 &");
make_pause();
system("pkill afplay");
system("reset");
}
}
}
void start_game(void)
{
g_game.player = create_player_arr();
g_game.board = create_board(g_game.player);
g_game.proc = create_process(g_game.player);
if (g_game.visu)
{
g_game.win = visual_init();
draw_map(g_game.win);
}
else
{
introduce();
// if (g_game.v && g_game.number_v > 0)
// initialize_verb();
}
run_game();
winner();
clean_all();
}