-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmines.h
178 lines (172 loc) · 4.07 KB
/
mines.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef __MINES_H__
#define __MINES_H__
#define SHORTHELP "%s [OPTIONS] [FIELDSPEC]\n"
#define FIELDHELP "FIELDSPEC: WxH[xM] (width 'x' height 'x' mines)\n"
#define LONGHELP \
"OPTIONS:\n" \
" -n(o flagging)\n" \
" -f(lagging)\n" \
" -q(uestion marks; implies -f)\n" \
" -b(land symbols)\n" \
" -c(olorful symbols)\n" \
" -d(ec charset symbols)\n" \
"FIELDSPEC:\n" \
" WxH[xM] (width 'x' height 'x' mines)\n" \
" defaults to 30x16x99; mines default to ~20%%\n" \
"\n"
#define KEYHELP \
"Keybindings:\n" \
" hjkl :move left/down/up/right\n" \
" bduw :move to next boundary (landing on closed cell)\n" \
" ^Gg$ :move to the left/bottom/top/right\n" \
" z :center cursor on minefield\n" \
" o :open/choord\n" \
" i :flag/unflag\n" \
" space:modeful cursor (either open or flag)\n" \
" s :toggle mode for space (open/flag)\n" \
" mX :set a mark for letter X\n" \
" `X :move to mark X (aliased to ')\n" \
" f/F x:find forward/backward [012345678 ocfq]\n" \
" t/T x:'til -\"-\n" \
" a/A x:after -\"-\n" \
" ! :open with a bang! (find large cluster of zeros)\n" \
" :n :start a new game\n" \
" :h :help\n" \
" :r :resize\n" \
" :q :quit\n"
struct minefield {
struct minecell {
unsigned m:2; /* mine?1:killmine?2:0 */
unsigned o:1; /* open?1:0 */
unsigned f:2; /* flagged?1:questioned?2:0 */
unsigned n:4; /* 0<= neighbours <=8 */
} **c;
int w; /* width */
int h; /* height */
int m; /* number of mines */
};
struct game {
int f; /* flags counter */
int t; /* time of game start */
int p[2]; /* cursor position {line, col} */
int s; /* space mode */
int o; /* mode */
int n; /* new game? */
struct markers {
int s; /* set? */
int l; /* line */
int c; /* col */
} m[26]; /* a-z */
};
struct opt {
struct minescheme* scheme;
int mode; /* allow flags? quesm? */
};
int minesviiper(void);
void fill_minefield (int, int);
void move_ph (int, int);
void move_hi (int, int);
void to_next_boundary (int, int, char);
int find (int, char, int);
int getch (unsigned char*);
int getch_wrapper (void);
int getctrlseq (unsigned char*);
int everything_opened (void);
int wait_mouse_up (int, int);
void redraw_cell (int, int, int);
void show_minefield (int);
void show_stomp (int, int, int);
void wait_keypress (int);
int get_neighbours (int, int, int);
int closed_neighbours (int, int);
int uncover_square (int, int);
void flag_square (int, int);
void quesm_square (int, int);
void flagall_square (int, int);
int choord_square (int, int);
int do_uncover (int*, int);
int grand_opening (int*);
int assign_cluster (int, int, int, int*);
int ex_cmd(void);
void set_mark(void);
void jump_mark(void);
void interactive_resize(void);
struct minecell** alloc_array (int, int);
void free_field (void);
char* get_emoticon(void);
int screen2field_l (int);
int screen2field_c (int);
int field2screen_c (int);
int clicked_emoticon (unsigned char*);
void quit(void);
void clamp_fieldsize (void);
int mines_percentage(int, int);
int parse_fieldspec(char*);
void signal_handler (int);
void signal_setup (void);
void timer_setup (int);
void screen_setup (int);
void raw_mode(int);
enum modes {
NORMAL,
REDUCED,
SHOWMINES,
SHOWFLAGS,
HIGHLIGHT,
RESIZEMODE,
};
enum flagtypes {
NOFLAG,
FLAG,
QUESM,
};
enum fieldopenstates {
CLOSED,
OPENED,
};
enum game_states {
GAME_NEW = 0, /* expected zero while resetting `g' */
GAME_INPROGRESS,
GAME_WON,
GAME_LOST,
GAME_QUIT,
};
enum space_modes {
MODE_OPEN = 0, /* expected zero while resetting `g' */
MODE_FLAG,
MODE_QUESM,
};
enum event {
/* for getctrlseq() */
CTRSEQ_NULL = 0,
CTRSEQ_EOF = -1,
CTRSEQ_INVALID = -2,
CTRSEQ_MOUSE = -3,
/* for getch() */
CTRSEQ_MOUSE_LEFT = -4,
CTRSEQ_MOUSE_MIDDLE = -5,
CTRSEQ_MOUSE_RIGHT = -6,
CTRSEQ_CURSOR_LEFT = -7,
CTRSEQ_CURSOR_DOWN = -8,
CTRSEQ_CURSOR_UP = -9,
CTRSEQ_CURSOR_RIGHT = -10,
/* for getch_wrapper() */
WRAPPER_EMOTICON = -11,
};
enum actor {
KEYBOARD,
MOUSE,
};
enum colon {
EX_INVALID,
EX_QUIT,
EX_NEW,
EX_HELP,
EX_RESZ,
};
enum mine_types {
NO_MINE,
STD_MINE,
DEATH_MINE,
};
#endif