-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
87 lines (72 loc) · 1.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "game.h"
#include "id.h"
#include "ui_game_sdl.h"
static void OnMouseClick(Ifel* i);
static CGame *game;
static CGameUI *gameUI;
/* A generic function to handle all mouse clicks */
/* Most likely this should be broken up for more modular logic */
static void OnMouseClick(Ifel* i)
{
//fprintf(stderr, "OnMouseClick in %i\n", i->id);
switch(i->id)
{
case ID_BTN_OPTIONS:
//fprintf(stderr, "Click in options button\n");
gameUI->ShowOptionsMenu();
break;
case ID_MSGBOX_ROLL:
case ID_BTN_ROLL:
game->RollDice();
game->MovePlayer(ACCORDING_TO_DICE);
break;
}
}
void OnKeyPressed(Ifel* el, int key)
{
switch(key)
{
case 'q':
fprintf(stderr, "Quit\n");
if (ModalMessageBox(ID_MB_YESNO, "Would you like to quit the current game?") == MB_YES)
{
game->Over();
Quit();
}
break;
case 'y':
break;
case 'n':
game->NewGame();
break;
}
}
int main(int argc, char* args[])
{
gameUI = new CSDLGameUI();
game = new CGame(*gameUI);
gameUI->Init(OnKeyPressed, OnMouseClick);
// start from a clean slate
game->Over();
// start the game
Run();
fprintf(stderr, "Save game\n");
if (!game->IsOver())
{
if (ModalMessageBox(ID_MB_YESNO, "Would you like to save the current game?") == MB_YES)
{
//SaveGame("game1.clonopoly");
}
}
fprintf(stderr, "Cleanup\n");
delete gameUI;
delete game;
return 0;
}