-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·93 lines (84 loc) · 2.29 KB
/
main.c
File metadata and controls
executable file
·93 lines (84 loc) · 2.29 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <luperez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/27 23:57:31 by luperez #+# #+# */
/* Updated: 2015/02/28 05:00:10 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "game_2048.h"
void game_windows(t_game *g)
{
getmaxyx(stdscr, g->h, g->w);
g->tile_width = (g->w - 6) / g->tile_size;
g->tile_height = (g->h - g->score_size - 10) / g->tile_size;
g->score_size = 10;
g->board.h = g->h - g->score_size + 1;
g->board.w = g->w;
g->score.h = g->score_size;
g->score.w = g->w;
g->score.y = g->board.h - 1;
}
void listen(t_game *g)
{
int c;
ft_putstrerrno("\n\n=====\nListen...\n====\n\n");
c = getch();
while (c == KEY_LEFT || c == KEY_RIGHT || c == KEY_UP || c == KEY_DOWN
|| c != 27)
{
if (c == KEY_LEFT || c == KEY_RIGHT || c == KEY_UP || c == KEY_DOWN)
{
ft_putstrerrno("\n\n====\nKey move detected\n====\n\n");
displacement(g, c);
}
else
ft_putstrerrno("\n\n====\nNot a key for diplacement\n====\n\n");
resize(g);
c = getch();
}
ft_putstrerrno("\n\n=====\nEnd of listening...\n====\n\n");
}
void game(t_game *g)
{
game_windows(g);
background(g);
board_create(g);
refresh();
listen(g);
}
void end_game(t_game *g)
{
int x;
int y;
y = -1;
while (g->tiles[++y])
{
x = -1;
while (g->tiles[y][++x])
free(g->tiles[y][++x]);
}
free(g);
}
int main(void)
{
t_game *g;
if (!(g = (t_game *)ft_memalloc(sizeof(t_game))))
return (-1);
if (WIN_VALUE % 2 > 0)
ft_error("Invalide win value.");
g->tile_size = TILE_SIZE;
initscr();
keypad(stdscr, TRUE);
noecho();
cbreak();
curs_set(0);
start_color();
game(g);
end_game(g);
endwin();
return (0);
}