summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Board.cpp4
-rw-r--r--Board.h2
-rw-r--r--MainWindow.cpp15
-rw-r--r--MainWindow.h2
4 files changed, 12 insertions, 11 deletions
diff --git a/Board.cpp b/Board.cpp
index 39caacf..f6eb593 100644
--- a/Board.cpp
+++ b/Board.cpp
@@ -29,8 +29,8 @@ Board:: Board(int width, int height, int minecount)
{
for (int y = 0; y < width; y++)
{
- std::shared_ptr<Tile> t(new Tile(x, y));
- tiles.push_back(t);
+ std::unique_ptr<Tile> t(new Tile(x, y));
+ tiles.push_back(std::move(t));
}
}
generate_mines();
diff --git a/Board.h b/Board.h
index 55e1f09..50e9fa4 100644
--- a/Board.h
+++ b/Board.h
@@ -35,7 +35,7 @@ class Board
bool is_game_won() { return this->game_won; };
bool check_win();
private:
- std::vector<std::shared_ptr<Tile>> tiles;
+ std::vector<std::unique_ptr<Tile>> tiles;
void generate_mines();
void retrieve_neighbors();
void count_neighbor_mines(Tile *tile);
diff --git a/MainWindow.cpp b/MainWindow.cpp
index ffc27c2..d800d33 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -138,20 +138,21 @@ MainWindow::new_game(int width, int height, int minecount)
{
seconds = 0;
ticking = false;
- tile_buttons.clear();
delete board;
delete matrix;
+ board = nullptr;
+ matrix = nullptr;
puts("starting new game..");
int tilecount = width*height;
board = new Board(width, height, minecount);
matrix = new FXMatrix(scroll_area, width, MATRIX_BY_COLUMNS|LAYOUT_CENTER_Y|LAYOUT_CENTER_X);
for (int i = 0; i < tilecount; i++)
{
- std::shared_ptr<FXButton> b(new FXButton(matrix, "", nullptr, this, UI_Tile));
- tile_buttons.push_back(b);
- b->setIcon(empty_icon);
+ std::unique_ptr<FXButton> b(new FXButton(matrix, "", nullptr, this, UI_Tile));
+ tile_buttons.push_back(std::move(b));
+ tile_buttons.at(i)->setIcon(empty_icon);
}
- printf("rows: %d columns: %d\n", matrix->getNumRows(), matrix->getNumColumns());
+ printf("matrix thinks rows: %d columns: %d\n", matrix->getNumRows(), matrix->getNumColumns());
draw_buttons();
}
@@ -323,12 +324,12 @@ MainWindow::on_New_Click(FXObject *sender, FXSelector sel, void *data)
{
/* cannot have more mines that tiles */
app->beep();
- FXMessageBox::information(app, FX::MBOX_OK, "Invalid game options", "You cannot have more mines that tiles (mines > (width*height)");
+ FXMessageBox::information(app, FX::MBOX_OK, "Invalid game options", "You cannot have more mines that tiles (mines > (width*height))");
return 1;
}
printf("new game width = %d height = %d mines = %d\n", w, h, m);
- new_game(2, 2, 1);
+ new_game(w, h, m);
}
return 1;
}
diff --git a/MainWindow.h b/MainWindow.h
index 4c53ba6..38b8bd6 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -74,7 +74,7 @@ class MainWindow : public FXMainWindow
FXHorizontalFrame *width_input_frame;
FXHorizontalFrame *height_input_frame;
FXHorizontalFrame *mine_input_frame;
- std::vector<std::shared_ptr<FXButton>> tile_buttons;
+ std::vector<std::unique_ptr<FXButton>> tile_buttons;
/* icons */
FXIcon *bomb_icon;
FXIcon *flag_icon;