@@ -51,6 +51,14 @@ void Grid::Initialize()
51
51
mesh->SetWidth (Cell::LENGTH);
52
52
mesh->SetHeight (Cell::LENGTH);
53
53
54
+ auto textComp = new TextComponent (" TextComponent" , cell, 2 );
55
+ textComp->SetColor (RAYWHITE);
56
+ textComp->SetFont (GetFontDefault ());
57
+ textComp->SetFontSize (40 .f );
58
+ textComp->SetSpacing (0 .f );
59
+ textComp->SetText (std::to_string (cell->GetNumOfMines ()));
60
+ textComp->SetIsShow (false );
61
+
54
62
// Add line mesh component for the sealed state of cells
55
63
auto lineMesh = new LineMeshComponent (" LineMeshComponent" , cell, 2 );
56
64
lineMesh->SetThickness (3 .f );
@@ -70,15 +78,11 @@ void Grid::Reset()
70
78
{
71
79
for (auto cell : row)
72
80
{
73
- cell->SetCellType (UNEXPOSE);
74
- // Reset TextComponent
75
- auto textComp = reinterpret_cast <TextComponent*>(cell->GetComponent (" TextComponent" ));
76
- if (textComp)
77
- {
78
- textComp->SetIsShow (false );
79
- }
81
+ // Reset cell to original state
82
+ cell->Reset ();
80
83
}
81
84
}
85
+ // Re-setup mines randomly
82
86
SetMines ();
83
87
GetGame ()->SetGameState (Game::PLAYING);
84
88
}
@@ -144,7 +148,7 @@ void Grid::SetMines()
144
148
i = GetRandomValue (0 , mRows - 1 );
145
149
j = GetRandomValue (0 , mColumns - 1 );
146
150
// Set Mine cell
147
- if (mCellList [i][j]->GetCellType () != MINE )
151
+ if (mCellList [i][j]->GetCellType () == UNEXPOSE )
148
152
{
149
153
mCellList [i][j]->SetCellType (MINE);
150
154
mMineList .push_back (mCellList [i][j]);
@@ -173,7 +177,7 @@ int Grid::GetAdjacentCells(Cell *cell, std::vector<Cell*>& adjacentCells)
173
177
{
174
178
// Valid adjacent cell
175
179
adjacentCells.push_back (mCellList [i][j]);
176
- if (mCellList [i][j]->GetCellType () == MINE)
180
+ if (mCellList [i][j]->GetCellType () == MINE || mCellList [i][j]-> GetCellType () == MINE_SEALED )
177
181
{
178
182
numOfMines++;
179
183
}
@@ -182,7 +186,7 @@ int Grid::GetAdjacentCells(Cell *cell, std::vector<Cell*>& adjacentCells)
182
186
{
183
187
// Valid adjacent cell
184
188
adjacentCells.push_back (mCellList [z][j]);
185
- if (mCellList [z][j]->GetCellType () == MINE)
189
+ if (mCellList [z][j]->GetCellType () == MINE || mCellList [z][j]-> GetCellType () == MINE_SEALED )
186
190
{
187
191
numOfMines++;
188
192
}
@@ -198,7 +202,7 @@ int Grid::GetAdjacentCells(Cell *cell, std::vector<Cell*>& adjacentCells)
198
202
if ((y - 1 ) >= 0 )
199
203
{
200
204
adjacentCells.push_back (mCellList [x][y - 1 ]);
201
- if (mCellList [x][y - 1 ]->GetCellType () == MINE)
205
+ if (mCellList [x][y - 1 ]->GetCellType () == MINE || mCellList [x][y - 1 ]-> GetCellType () == MINE_SEALED )
202
206
{
203
207
numOfMines++;
204
208
}
@@ -207,7 +211,7 @@ int Grid::GetAdjacentCells(Cell *cell, std::vector<Cell*>& adjacentCells)
207
211
if ((y + 1 ) < mColumns )
208
212
{
209
213
adjacentCells.push_back (mCellList [x][y + 1 ]);
210
- if (mCellList [x][y + 1 ]->GetCellType () == MINE)
214
+ if (mCellList [x][y + 1 ]->GetCellType () == MINE || mCellList [x][y + 1 ]-> GetCellType () == MINE_SEALED )
211
215
{
212
216
numOfMines++;
213
217
}
@@ -243,16 +247,19 @@ void Grid::Expose(Cell *cell)
243
247
cell->SetNumOfMines (numOfMines);
244
248
// Check if this cell already has a TextComponent
245
249
auto textComp = reinterpret_cast <TextComponent*>(cell->GetComponent (" TextComponent" ));
246
- if (! textComp)
250
+ if (textComp)
247
251
{
248
- textComp = new TextComponent (" TextComponent" , cell, 2 );
252
+ textComp->SetColor (RAYWHITE);
253
+ textComp->SetFont (GetFontDefault ());
254
+ textComp->SetFontSize (40 .f );
255
+ textComp->SetSpacing (0 .f );
256
+ textComp->SetText (std::to_string (cell->GetNumOfMines ()));
257
+ textComp->SetIsShow (true );
258
+ }
259
+ else
260
+ {
261
+ printf (" TextComponent is null!!!\n " );
249
262
}
250
- textComp->SetColor (RAYWHITE);
251
- textComp->SetFont (GetFontDefault ());
252
- textComp->SetFontSize (40 .f );
253
- textComp->SetSpacing (0 .f );
254
- textComp->SetText (std::to_string (cell->GetNumOfMines ()));
255
- textComp->SetIsShow (true );
256
263
}
257
264
else
258
265
{
0 commit comments