From 971db58ef48db64151a31d4857104ede69475996 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 13 Jun 2020 17:00:52 +0930 Subject: make shared_ptr -> unique_ptr --- Board.cpp | 4 ++-- Board.h | 2 +- MainWindow.cpp | 15 ++++++++------- MainWindow.h | 2 +- 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 t(new Tile(x, y)); - tiles.push_back(t); + std::unique_ptr 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> tiles; + std::vector> 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 b(new FXButton(matrix, "", nullptr, this, UI_Tile)); - tile_buttons.push_back(b); - b->setIcon(empty_icon); + std::unique_ptr 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> tile_buttons; + std::vector> tile_buttons; /* icons */ FXIcon *bomb_icon; FXIcon *flag_icon; -- cgit v1.2.3