Skip to content

Commit 068d920

Browse files
committed
Move initializing of cell components to Cell class rather than doing it in grid's Initialize() method
1 parent 47e0864 commit 068d920

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/Cell.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,35 @@ Cell::Cell(Game *game, Game::GameState gameState, Grid *grid)
1818
mNumOfMines = 0;
1919
}
2020

21+
void Cell::SetupComponents()
22+
{
23+
// Add rectangle mesh component for the color of the cells
24+
auto mesh = new RectangleMeshComponent("RectangleMeshComponent", this, 1);
25+
mesh->SetColor(DARKGRAY);
26+
mesh->SetBorderColor(BLACK);
27+
mesh->SetBorderThickness(3.f);
28+
mesh->SetWidth(Cell::LENGTH);
29+
mesh->SetHeight(Cell::LENGTH);
30+
31+
auto textComp = new TextComponent("TextComponent", this, 2);
32+
textComp->SetColor(RAYWHITE);
33+
textComp->SetFont(GetFontDefault());
34+
textComp->SetFontSize(50.f);
35+
textComp->SetSpacing(0.f);
36+
textComp->SetText(std::to_string(this->GetNumOfMines()));
37+
textComp->SetIsShow(false);
38+
39+
// Add line mesh component for the sealed state of cells
40+
auto lineMesh = new LineMeshComponent("LineMeshComponent", this, 2);
41+
lineMesh->SetThickness(3.f);
42+
lineMesh->SetColor(BLACK);
43+
lineMesh->SetLinePair({ this->GetPosition().x - (Cell::LENGTH / 2), this->GetPosition().y - (Cell::LENGTH / 2) },
44+
{ this->GetPosition().x + (Cell::LENGTH / 2), this->GetPosition().y + (Cell::LENGTH / 2) });
45+
lineMesh->SetLinePair({ this->GetPosition().x + (Cell::LENGTH / 2), this->GetPosition().y - (Cell::LENGTH / 2) },
46+
{ this->GetPosition().x - (Cell::LENGTH / 2), this->GetPosition().y + (Cell::LENGTH / 2) });
47+
48+
}
49+
2150
void Cell::UpdateActor(float deltaTime)
2251
{
2352
auto mesh = (RectangleMeshComponent*)(GetComponent("RectangleMeshComponent"));

src/Cell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Cell : public Actor
2828
public:
2929
Cell(class Game* game, Game::GameState gameState, class Grid* grid);
3030

31+
void SetupComponents();
3132
void UpdateActor(float deltaTime) override;
3233

3334
// Getters/Setters

src/Grid.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,8 @@ void Grid::Initialize()
4343
cell->SetIndex(i, j);
4444
cell->SetCellType(UNEXPOSE);
4545
mCellList[i][j] = cell;
46-
47-
// Add rectangle mesh component for the color of the cells
48-
auto mesh = new RectangleMeshComponent("RectangleMeshComponent", cell, 1);
49-
mesh->SetColor(DARKGRAY);
50-
mesh->SetBorderColor(BLACK);
51-
mesh->SetBorderThickness(3.f);
52-
mesh->SetWidth(Cell::LENGTH);
53-
mesh->SetHeight(Cell::LENGTH);
54-
55-
auto textComp = new TextComponent("TextComponent", cell, 2);
56-
textComp->SetColor(RAYWHITE);
57-
textComp->SetFont(GetFontDefault());
58-
textComp->SetFontSize(50.f);
59-
textComp->SetSpacing(0.f);
60-
textComp->SetText(std::to_string(cell->GetNumOfMines()));
61-
textComp->SetIsShow(false);
62-
63-
// Add line mesh component for the sealed state of cells
64-
auto lineMesh = new LineMeshComponent("LineMeshComponent", cell, 2);
65-
lineMesh->SetThickness(3.f);
66-
lineMesh->SetColor(BLACK);
67-
lineMesh->SetLinePair({ cell->GetPosition().x - (Cell::LENGTH / 2), cell->GetPosition().y - (Cell::LENGTH / 2) },
68-
{ cell->GetPosition().x + (Cell::LENGTH / 2), cell->GetPosition().y + (Cell::LENGTH / 2) });
69-
lineMesh->SetLinePair({ cell->GetPosition().x + (Cell::LENGTH / 2), cell->GetPosition().y - (Cell::LENGTH / 2) },
70-
{ cell->GetPosition().x - (Cell::LENGTH / 2), cell->GetPosition().y + (Cell::LENGTH / 2) });
46+
// Setup required components to this cell actor
47+
cell->SetupComponents();
7148
}
7249
}
7350
// SetMines();

0 commit comments

Comments
 (0)