Update gtk142
This commit is contained in:
parent
cf1a3729fc
commit
2539baf345
|
@ -33,9 +33,11 @@ MineSweeper::MineSweeper()
|
|||
|
||||
// Buttons
|
||||
btnstart.set_label("Start/Reset");
|
||||
btnpause.set_label("Pause");
|
||||
btnshow.set_label("Show All");
|
||||
btnexit.set_label("Exit");
|
||||
btn_box.append(btnstart);
|
||||
btn_box.append(btnpause);
|
||||
btn_box.append(btnshow);
|
||||
btn_box.append(btnexit);
|
||||
btnstart.signal_clicked().connect(sigc::mem_fun(*this, &MineSweeper::new_game));
|
||||
|
@ -124,8 +126,9 @@ void MineSweeper::reset_game(int width, int height, int mines)
|
|||
}
|
||||
}
|
||||
// std::cout << mine_count << std::endl;
|
||||
game_ended = false;
|
||||
winned = true;
|
||||
// game_ended = false;
|
||||
// winned = true;
|
||||
game_status = GameStatus::Running;
|
||||
status_label.set_label(" ");
|
||||
calc_mines();
|
||||
|
||||
|
@ -148,6 +151,10 @@ void MineSweeper::reset_game(int width, int height, int mines)
|
|||
mine_grid.show();
|
||||
}
|
||||
|
||||
void MineSweeper::pause_game(){
|
||||
|
||||
}
|
||||
|
||||
void MineSweeper::calc_mines()
|
||||
{
|
||||
// Calculate the mines around a cell
|
||||
|
@ -212,21 +219,22 @@ bool MineSweeper::timer_func()
|
|||
void MineSweeper::cell_clicked(MineCell *cell1)
|
||||
{
|
||||
cell1->set_has_frame(false);
|
||||
if (!game_ended && !cell1->cleared)
|
||||
if (game_status == GameStatus::Running && !cell1->cleared)
|
||||
{
|
||||
//
|
||||
// If get mine, the game will end now
|
||||
if (cell1->has_mine)
|
||||
{
|
||||
// Set game to stop
|
||||
winned = false;
|
||||
// winned = false;
|
||||
game_status = GameStatus::Ended;
|
||||
cell1->cleared = true;
|
||||
cell1->set_image_from_icon_name("exploded", Gtk::IconSize::LARGE);
|
||||
|
||||
// End the game
|
||||
game_lost(cell1->y * 7 + cell1->x);
|
||||
status_label.set_label("You lost!");
|
||||
game_ended = true;
|
||||
// game_ended = true;
|
||||
mytimer.disconnect();
|
||||
mine_grid.set_sensitive(false);
|
||||
}
|
||||
|
@ -284,8 +292,7 @@ void MineSweeper::check_mines(int pos_x, int pos_y)
|
|||
{
|
||||
// Stop the game
|
||||
status_label.set_label("You winned!");
|
||||
winned = true;
|
||||
game_ended = true;
|
||||
game_status = GameStatus::Winned;
|
||||
mytimer.disconnect();
|
||||
|
||||
// Save the time of game
|
||||
|
|
|
@ -4,6 +4,17 @@
|
|||
#include "InputBox.hh"
|
||||
#include "ScoresWin.hh"
|
||||
|
||||
// The status of the minesweeper game
|
||||
enum class GameStatus
|
||||
{
|
||||
Running,
|
||||
Winned,
|
||||
Ended,
|
||||
Paused
|
||||
};
|
||||
|
||||
// The cell of the minesweeper game,
|
||||
// and the mines is under the cell
|
||||
class MineCell : public Gtk::Button
|
||||
{
|
||||
public:
|
||||
|
@ -18,6 +29,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
// Main class
|
||||
class MineSweeper : public Gtk::ApplicationWindow
|
||||
{
|
||||
public:
|
||||
|
@ -34,11 +46,12 @@ private:
|
|||
Gtk::Grid mine_grid;
|
||||
Gtk::Label status_label;
|
||||
Gtk::Box main_box, btn_box;
|
||||
Gtk::Button btnstart, btnshow, btnexit;
|
||||
Gtk::Button btnstart, btnpause, btnshow, btnexit;
|
||||
|
||||
// The cell to place mines
|
||||
MineCell *cell;
|
||||
bool winned, game_ended; // The status of game(win/end)
|
||||
GameStatus game_status; // Use enum class for the status of game
|
||||
// bool winned, game_ended; // The status of game(win/end)
|
||||
int mines_clear, mine_count; // Whether the mine is cleared
|
||||
|
||||
// Menu
|
||||
|
@ -57,6 +70,7 @@ private:
|
|||
// Signal Handlers
|
||||
void new_game(); // "New Game" handler
|
||||
void reset_game(int width = 7, int height = 7, int mines = 9); // Reset all mines
|
||||
void pause_game(); // Pause or continue the game
|
||||
void calc_mines(); // Get the mines around
|
||||
void show_mines(); // Show all mines
|
||||
void show_scores(); // Show all scores
|
||||
|
|
Loading…
Reference in New Issue