Skip to content

Commit

Permalink
game initialization cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuzia committed Aug 18, 2022
1 parent ded1103 commit 66e2126
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
20 changes: 5 additions & 15 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,6 @@ void Game::updateFlagCount() {
//flagCounter.x = (SCREEN_WIDTH - flagCounter.getWidth()) / 2;
}

TextButton& Game::activeRestartButton() {
return restartBtn;
return (state & GameState::OVER) ? playAgainBtn : restartBtn;
}

void Game::OnUpdate(double dt) {
for (auto& row : board) for (Tile& tile : row) {
tile.OnUpdate(dt);
Expand All @@ -365,24 +360,20 @@ Game::~Game() {
}
}

Game::Game(SDL_Window *window) : Game(window, Difficulty::SIZES[1].rows, Difficulty::SIZES[1].cols) {}

Game::Game(SDL_Window *window, int rows, int cols)
: rows(rows)
, cols(cols)
Game::Game(SDL_Window *window)
: rows(Difficulty::SIZES[1].rows)
, cols(Difficulty::SIZES[1].cols)
, board(rows, std::vector<Tile>(cols))
, rng(std::random_device{}())
, mainFont("fonts/Arbutus-Regular.ttf")
, window(window)
, title(&mainFont, "Minesweeper")
, flagCounter(&mainFont, "0/? flags", 0xA00000)
, restartBtn(&mainFont, "Restart!", 0xFF1000)
, playAgainBtn(&mainFont, "Play again?", 0x00C000)
, rng(std::random_device{}())
, currentHover(nullptr)
, activeBtn(-1)
{
currentHover = nullptr;
activeBtn = -1;

saveDirectory = SDL_GetPrefPath("grassdne", "sdlminesweeper");
if (saveDirectory == NULL) {
printf("Error getting save directory: %s", SDL_GetError());
Expand All @@ -396,7 +387,6 @@ void Game::OnStart() {
load();
int loadedState = state;

board.resize(rows, std::vector<Tile>(cols));
ready();

if (!tileDatas.empty()) {
Expand Down
6 changes: 1 addition & 5 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace SoundEffects {

class Game {
public:
Game(SDL_Window *window, int rows, int cols);
Game(SDL_Window *window);
~Game();

Expand Down Expand Up @@ -82,7 +81,6 @@ class Game {
std::vector<TextButton> difficultyBtns;

std::vector<Button*> buttons;
int activeBtn;

TextButton& activeRestartButton();

Expand All @@ -98,12 +96,10 @@ class Game {

void onRevealTile(Tile& tile);


std::vector<Uint8> tileDatas;


Tile *currentHover;

int activeBtn;
};

#endif

0 comments on commit 66e2126

Please sign in to comment.