-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.h
121 lines (106 loc) · 2.96 KB
/
field.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
#ifndef FIELD_H
#define FIELD_H
#include <vector>
#include <iostream>
#include <functional>
#include "tile.h"
#include "settings.h"
namespace minis
{
class Field
{
public:
/**
* @brief Construct a new Field object
*
* @param position Field's screen position
* @param settings - Game/Field settings
*/
Field(Vector2 position, GameSettings settings);
/**
* @brief Destroy the Field object
*
*/
~Field();
/**
* @brief Draw the field with all its content
*
*/
void Draw();
Tile *GetTile(int row, int col);
void RevealGrid();
void FloodFill(Tile *tile);
bool WinningConditionMet();
bool GameOver();
void HandleLeftMouse(Vector2 *mouse_point, std::function<void()> sound_callback);
void HandleRightMouse(Vector2 *mouse_point, std::function<void()> sound_callback);
Vector2 Position();
inline const GameSettings *GetGameSettings()
{
return &settings;
}
/**
* @brief Returns the count of mines hidden in the field
*
* @return int Number of mines in the field
*/
inline int MineCount()
{
return settings.mines;
}
/**
* @brief Returns the number of currently set flags on the field.
*
* @return int Current number of set flags
*/
inline int FlagCount()
{
return flag_count;
}
/**
* @brief Returns the number of rows in the field.
*
* @return int Number of rows in the field
*/
inline int Rows()
{
return settings.rows;
}
/**
* @brief Returns the number of columns in the field
*
* @return int Number of colimns in the field
*/
inline int Columns()
{
return settings.columns;
}
inline int TileSize()
{
return settings.tile_size;
}
private:
std::vector<std::vector<Tile>> grid;
Vector2 grid_position;
bool game_over = false;
int tiles_open_count = 0;
/**
* @brief Checks if the row and column indices are valid (lie within the bound) for this field.
*
* @param row Target row index
* @param col Target column index
* @return true If row and column are within the field bounds
* @return false If row or column are not within field bounds
*/
bool IsTileValid(int row, int col);
bool MineInTile(int row_pos, int col_pos);
int GetNeighborMineCount(int own_row_pos, int own_col_pos);
GameSettings settings;
int flag_count = 0;
Texture2D tile_texture;
Texture2D flag_texture;
Texture2D mine_texture;
Texture2D cross_texture;
};
}
#endif