-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
72 lines (59 loc) · 1.77 KB
/
main.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
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "./game.h"
#include "./logic.h"
#include "./rendering.h"
nSDL_Font *font;
int main(void)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Could not initialize sdl2: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Surface *screen = SDL_SetVideoMode(320, 240, has_colors ? 16 : 8, SDL_SWSURFACE);
if (screen == NULL) {
fprintf(stderr, "SDL_CreateRenderer Error: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
font = nSDL_LoadFont(NSDL_FONT_VGA, 255, 255, 255);
game_t game = {
.board = { EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY,
EMPTY, EMPTY, EMPTY },
.player = PLAYER_X,
.state = RUNNING_STATE
};
while (game.state != QUIT_STATE) {
if (isKeyPressed(KEY_NSPIRE_ESC)) {
game.state = QUIT_STATE;
break;
}
else if (isKeyPressed(KEY_NSPIRE_1))
click_on_cell(&game, 2, 0);
else if (isKeyPressed(KEY_NSPIRE_2))
click_on_cell(&game, 2, 1);
else if (isKeyPressed(KEY_NSPIRE_3))
click_on_cell(&game, 2, 2);
else if (isKeyPressed(KEY_NSPIRE_4))
click_on_cell(&game, 1, 0);
else if (isKeyPressed(KEY_NSPIRE_5))
click_on_cell(&game, 1, 1);
else if (isKeyPressed(KEY_NSPIRE_6))
click_on_cell(&game, 1, 2);
else if (isKeyPressed(KEY_NSPIRE_7))
click_on_cell(&game, 0, 0);
else if (isKeyPressed(KEY_NSPIRE_8))
click_on_cell(&game, 0, 1);
else if (isKeyPressed(KEY_NSPIRE_9))
click_on_cell(&game, 0, 2);
SDL_FillRect(screen, NULL, 0x000000);
render_game(screen, &game);
SDL_Flip(screen);
idle();
wait_key_pressed();
}
nSDL_FreeFont(font);
SDL_Quit();
return EXIT_SUCCESS;
}