summaryrefslogtreecommitdiffstats
path: root/inc/mine-sweeper/game/core.h
blob: b07e38fc6ae3ecbc669aebfdcedf9b546364b498 (plain) (blame)
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
/******************************************************************************
 *	Copyright (C) 2015	Alejandro Colomar Andrés		      *
 *	SPDX-License-Identifier:	GPL-2.0-only			      *
 ******************************************************************************/


/******************************************************************************
 ******* include guard ********************************************************
 ******************************************************************************/
#ifndef MSW_GAME_CORE_H
#define MSW_GAME_CORE_H


/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
#include <stdbool.h>
#include <stddef.h>

#include "mine-sweeper/game/iface.h"


/******************************************************************************
 ******* macros ***************************************************************
 ******************************************************************************/


/******************************************************************************
 ******* enums ****************************************************************
 ******************************************************************************/
enum	Game_Mine_Board {
	GAME_MINE_NO = 0,
	GAME_MINE_YES = 9
};

enum	Game_Usr_Board {
	GAME_USR_KBOOM = -1,
	GAME_USR_HIDDEN,
	GAME_USR_CLEAR,
	GAME_USR_FLAG,
	GAME_USR_POSSIBLE
};

enum	Game_Action {
	GAME_ACT_FOO = 0,
	GAME_ACT_STEP,
	GAME_ACT_FLAG,
	GAME_ACT_FLAG_POSSIBLE,
	GAME_ACT_RM_FLAG
};

enum	Game_State {
	GAME_STATE_PLAYING = 0,
	GAME_STATE_SAFE,
	GAME_STATE_GAMEOVER
};



/******************************************************************************
 ******* structs / unions *****************************************************
 ******************************************************************************/
struct	Game_Board {
	ptrdiff_t	rows;
	ptrdiff_t	cols;
	int		mines;
	int		gnd [ROWS_MAX] [COLS_MAX];
	int		usr [ROWS_MAX] [COLS_MAX];
	int		flags;
	int		clr;
	int		state;
};


/******************************************************************************
 ******* variables ************************************************************
 ******************************************************************************/
extern	struct Game_Board	game_board;


/******************************************************************************
 ******* extern functions *****************************************************
 ******************************************************************************/
void	game_init	(void);
void	game_init_rand	(ptrdiff_t rows, ptrdiff_t cols, int mines,
					ptrdiff_t pos_row, ptrdiff_t pos_col);
int	game_init_load	(ptrdiff_t *rows, ptrdiff_t *cols);
void	game_action	(int action, ptrdiff_t row, ptrdiff_t col);


/******************************************************************************
 ******* static inline functions (prototypes) *********************************
 ******************************************************************************/


/******************************************************************************
 ******* static inline functions (definitions) ********************************
 ******************************************************************************/


/******************************************************************************
 ******* include guard ********************************************************
 ******************************************************************************/
#endif		/* mine-sweeper/game/core.h */


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/