-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.h
More file actions
150 lines (141 loc) · 3.74 KB
/
Copy pathTile.h
File metadata and controls
150 lines (141 loc) · 3.74 KB
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
#include <SFML/Graphics.hpp>
#include <vector>
#include <map>
#include <unordered_map>
#include <random>
using namespace std;
using namespace sf;
class Tile{
int minesAround;
bool flagged;
bool isAMine;
bool revealed;
int xPos;
int yPos;
array<Tile*,8> neighbors;
public:
// constructors
Tile()
{
this->minesAround = 0;
this->flagged = false;
this->isAMine = false;
this->revealed = false;
this->xPos = 0;
this->yPos = 0;
this->neighbors[0] = nullptr;
this->neighbors[1] = nullptr;
this->neighbors[2] = nullptr;
this->neighbors[3] = nullptr;
this->neighbors[4] = nullptr;
this->neighbors[5] = nullptr;
this->neighbors[6] = nullptr;
this->neighbors[7] = nullptr;
}
Tile(int minesAround, bool flagged, bool isAMine, bool revealed, int xPos, int yPos)
{
this->minesAround = minesAround;
this->flagged = flagged;
this->isAMine = isAMine;
this->revealed = revealed;
this->xPos = xPos;
this->yPos = yPos;
}
// getter functions
int GetMinesAround() const
{
return this->minesAround;
}
bool GetFlagged() const
{
return this->flagged;
}
bool GetIsAMine() const
{
return this->isAMine;
}
bool GetRevealed() const
{
return revealed;
}
bool GetIfNeutral() const
{
if (GetRevealed() || GetFlagged() || GetIsAMine()) return false;
return true;
}
int GetXPos() const
{
return this->xPos;
}
int GetYPos() const
{
return this->yPos;
}
array<Tile*,8> GetNeighbors() const
{
return this->neighbors;
}
// setter functions
void SetMinesAround(int _minesAround)
{
this->minesAround = _minesAround;
}
void SetFlagged()
{
if (this == nullptr || this->GetRevealed()) return;
this->flagged = !flagged;
}
void SetMine(bool _isAMine)
{
this->isAMine = _isAMine;
}
void Unreveal()
{
this->revealed = true;
}
void SetXPos(int _xPos)
{
this->xPos = _xPos;
}
void SetYPos(int _yPos)
{
this->yPos = _yPos;
}
void SetNeighbors(array<Tile*,8> _neighbors)
{
this->neighbors = _neighbors;
}
void ResetTile()
{
this->flagged = false;
this->isAMine = false;
this->minesAround = 0;
this->revealed = false;
}
// printer function
void PrintTile()
{
cout << "Mines Around: " << this->minesAround << endl;
cout << "Is Flagged: " << this->flagged << endl;
cout << "Is Mine: " << this->isAMine << endl;
cout << "Is Revealed: " << this->revealed << endl;
cout << "Row: " << (this->yPos/32) + 1 << endl;
cout << "Col: " << (this->xPos/32) + 1 << endl;
}
void PrintNeighbors()
{
if (this->GetNeighbors()[0] != nullptr) this->GetNeighbors()[0]->PrintTile();
if (this->GetNeighbors()[1] != nullptr) this->GetNeighbors()[1]->PrintTile();
if (this->GetNeighbors()[2] != nullptr) this->GetNeighbors()[2]->PrintTile();
if (this->GetNeighbors()[3] != nullptr) this->GetNeighbors()[3]->PrintTile();
if (this->GetNeighbors()[4] != nullptr) this->GetNeighbors()[4]->PrintTile();
if (this->GetNeighbors()[5] != nullptr) this->GetNeighbors()[5]->PrintTile();
if (this->GetNeighbors()[6] != nullptr) this->GetNeighbors()[6]->PrintTile();
if (this->GetNeighbors()[7] != nullptr) this->GetNeighbors()[7]->PrintTile();
}
// operator overloading
bool operator==(Tile &rhs)
{
return (rhs.xPos == this->xPos && rhs.yPos == this->yPos);
}
};