-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.h
82 lines (73 loc) · 1.54 KB
/
tile.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
#pragma once
#include <vector>
#include <iostream>
using namespace std;
class Tile
{
private:
int xpos;
int ypos;
bool hasflag;
bool hasmine;
bool revealed;
int surrondingmines;
vector<Tile*> adjacenttiles;
public:
Tile() {
xpos = 0;
ypos = 0;
hasflag = 0;
hasmine = 0;
revealed = 0;
surrondingmines = 0;
}
Tile(int& x, int& y, bool hasflag, bool hasmine, bool revealed) {
xpos = x;
ypos = y;
this->hasflag = hasflag;
this->hasmine = hasmine;
this->revealed = revealed;
surrondingmines = 0;
}
bool gethasflag(){
return hasflag;
}
bool gethasmine(){
return hasmine;
}
bool getrevealed() {
return revealed;
}
int getsurrondingmines() {
return surrondingmines;
}
void sethasflag(bool x) {
hasflag = x;
}
void sethasmine() {
hasmine = true;
}
void setrevealed() {
revealed = true;
}
void setsurrondingmines(int x) {
surrondingmines = x;
}
vector<Tile*>& getVector() {
return adjacenttiles;
}
int getsizeofneighbors() {
return adjacenttiles.size();
}
void setNeighbors(Tile**& tilegrid, int rows, int columns, int posx, int posy) {
int positiony[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int positionx[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
for (int i = 0; i < 8; i++) {
int row = posy + positiony[i];
int column = posx + positionx[i];
if (row >= 0 && column >= 0 && row < rows && column < columns) {
adjacenttiles.push_back(&tilegrid[row][column]);
}
}
}
};