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
|
/******************************************************************************
* Copyright (C) 2015 Alejandro Colomar Andrés *
******************************************************************************/
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
#include "mine-sweeper/ctrl/start.h"
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#define ALX_NO_PREFIX
#include <libalx/base/errno/error.h>
#include "mine-sweeper/game/core.h"
#include "mine-sweeper/game/iface.h"
#include "mine-sweeper/menu/iface.h"
#include "mine-sweeper/player/iface.h"
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
int start_mode;
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
static void start_foo (void);
static void start_rand (void);
static void start_load (void);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
void start_switch (void)
{
switch (start_mode) {
case START_FOO:
start_foo();
break;
case START_RAND:
start_rand();
break;
case START_LOAD:
start_load();
break;
}
}
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
static void start_foo (void)
{
}
static void start_rand (void)
{
int level;
ptrdiff_t rows, cols;
int mines;
ptrdiff_t r, c;
menu_iface_board(&level, &rows, &cols, &mines);
player_iface_init(rows, cols);
if (player_iface_start(&r, &c))
goto err;
game_init_rand(rows, cols, mines, r, c);
game_iface_init_rand(level, r, c);
/* game loop */
game_iface();
err:
player_iface_cleanup();
}
static void start_load (void)
{
ptrdiff_t rows, cols;
/* size & game init (sets errno) */
errno = 0;
if (game_init_load(&rows, &cols))
goto err;
player_iface_init(rows, cols);
game_iface_init_load();
/* game loop */
game_iface();
player_iface_cleanup();
return;
err:
perrorx("game_init_load");
}
/******************************************************************************
******* end of file **********************************************************
******************************************************************************/
|