-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.h
36 lines (32 loc) · 906 Bytes
/
logic.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
#pragma once
#include <array>
constexpr unsigned fieldWidth = 16;
constexpr unsigned fieldHeight = 16;
constexpr unsigned numberOfMines = (fieldWidth*fieldHeight) / 16;
struct Cell {
bool isOpen = false;
bool isFlagged = false;
bool isSuspect = false;
bool isMine = false;
unsigned neighboringMines = -1;
};
using cArray = std::array<Cell, fieldWidth*fieldHeight>;
class GameLogic {
public:
bool isLoseOrWin = false;
bool isFirstTurn = true;
bool isInMainMenu = true;
int remainingMines = numberOfMines;
cArray field;
public:
void newField(unsigned, unsigned);
void clearField();
bool isCellHere(unsigned, unsigned);
bool isMine(unsigned, unsigned);
unsigned calculateNeighboringMines(unsigned, unsigned);
void calculateNeighboringMinesForAll();
Cell getCell(unsigned, unsigned);
int open(unsigned, unsigned);
void recOpen(unsigned, unsigned);
void mark(unsigned, unsigned);
};