-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
109 lines (86 loc) · 2.67 KB
/
Game.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
#ifndef MINEFIELD_H
#define MINEFIELD_H
#include "types.h"
#include "Tile.h"
#include <ostream>
#include <ncurses.h>
enum GameState {
GAMESTATE_INIT,
GAMESTATE_PLAY,
GAMESTATE_WIN,
GAMESTATE_LOSE
};
class Game {
public:
Game(Dimension dimensioncount, SizeVector dimensions, class NullTimer *timer, ProgramOptions);
void startgame(int mines);
void setBombField(WINDOW *w);
// Getters
GameState getState();
unsigned int totalMines();
unsigned int totalFlags();
CoordinateSet origo();
Tile *getTile(CoordinateSet pos);
Dimension getDimensioncount() {return this->dimensioncount;}
unsigned int getPressedCount() {return this->pressedcount;}
unsigned int getTileCount() {return this->tilecount;}
// Iterators
CoordinateSetList::const_iterator coordbegin();
CoordinateSetList::const_iterator coordend();
PTileVector::const_iterator tilebegin();
PTileVector::const_iterator tileend();
// Coordinate conversion
int getOutputWidth();
int getOutputHeight();
int getOutputColumn(CoordinateSet p);
int getOutputRow(CoordinateSet p);
// used by PlayerRobot
CoordinateSetList neighbourhoodpositions(CoordinateSet pos, bool includeself = false);
PTileSet neighbourhood(CoordinateSet pos, bool includeself = false);
// Player interface (called by subclasses of Move)
bool amIDeadNow(CoordinateSet pos);
bool flagon(CoordinateSet pos);
bool flagoff(CoordinateSet pos);
// Drawing
void output();
void drawtile(CoordinateSet p);
private:
NullTimer *timer;
SizeVector dimensions;
Dimension dimensioncount;
PTileVector tiles;
unsigned int tilecount;
CoordinateSetList allpositionslist;
bool allpositions_initialised;
unsigned int minecount;
unsigned int flagcount;
unsigned int pressedcount;
GameState state;
WINDOW *window;
ProgramOptions opts;
// coordbegin and coordend helpers
CoordinateSetList allpositions();
void _allpositions(Dimension dim, CoordinateSet basis, CoordinateSetList *list);
// tile initialisation
void inittiles(int mines);
void deploythemines(int);
void filltheblanks();
bool pressblanks(bool one);
CoordinateSetSet findblanks();
void findblanks(Dimension dim, CoordinateSet basis, CoordinateSetSet *result);
void pressrandom();
void pressborders();
// Coordinate conversion
unsigned int coordstofieldindex(CoordinateSet pos);
CoordinateSet fieldindextocoords(unsigned int idx);
// used by PlayerRobot
void _neighbourhoodpositions(Dimension dim, CoordinateSet basis,
bool includebasis, CoordinateSetList *list);
// amIDeadNow helper
void press(CoordinateSet pos, bool norecursivespread = false);
// Drawing
void drawborders();
void drawhorzborders(int *y, int w, Dimension d);
void drawvertborders(int *x, int h, Dimension d);
};
#endif