-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.c
100 lines (92 loc) · 1.88 KB
/
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
#include "game.h"
int quit=0;
extern int gameNum;
extern game* cur_game;
extern element_cntrl ui_tree;
int gui_init()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("ERROR: unable to init SDL: %s\n",SDL_GetError());
return -1;
}
if (TTF_Init() < 0){
printf("ERROR: unable to init SDL: %s\n",SDL_GetError());
return -1;
}
//freopen("stdout.log","w",stdout);//make log files
//freopen("stderr.log","w",stderr);
return 1;
}
int main( int argc, char* args[] )
{
element_cntrl pressed_Button=NULL;
SDL_Event test_event;
int pause=0,error;
gui_init();
error=go_to_start_menu(&pause,&test_event);
if (error<0 || cur_game==NULL){
if (quit==1){
free_control_list(ui_tree);
if (cur_game!=NULL)
{
free(cur_game->board);
free(cur_game);
}
}
TTF_Quit();
SDL_Quit();
return 0;
}
while(!quit)
{
while(SDL_PollEvent(&test_event)) {
if(test_event.type == SDL_QUIT){
quit=1;
break;
}
switch(test_event.type) {
case SDL_MOUSEBUTTONDOWN:
find_element_by_coordinates(ui_tree,test_event.button.x,test_event.button.y,&pressed_Button);
if(pressed_Button==NULL)
{
break;
}
error=pressed_Button->cntrl->pressed_button(&pause,&test_event);
if (error<0 ||cur_game==NULL){
printf("a catchAble error occured\n");
TTF_Quit();
SDL_Quit();
return 0;
}
break;
default: //unhandled event
break;
}
if (cur_game!=NULL && cur_game->is_multiplayer==1 && pause==0){
error=handelAI_VS_AI(&pause);
if (error<0 ||cur_game==NULL){
printf("a catchAble error occured\n");
free_control_list(ui_tree);
if (cur_game!=NULL)
{
free(cur_game->board);
free(cur_game);
}
TTF_Quit();
SDL_Quit();
return 0;
}
}
}
}
free_control_list(ui_tree);
if (cur_game!=NULL)
{
free(cur_game->board);
free(cur_game);
}
TTF_Quit();
SDL_Quit();
return 0;
}