Update gtk141
This commit is contained in:
parent
aeaa8a71d8
commit
1fa1fbfc53
|
@ -76,6 +76,7 @@ MineSweeper::~MineSweeper(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void MineSweeper::new_game(){
|
void MineSweeper::new_game(){
|
||||||
|
// New game = reset game
|
||||||
reset_game();
|
reset_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ void MineSweeper::reset_game(int width, int height, int mines)
|
||||||
delete[] cell;
|
delete[] cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell = new MineCell[49];
|
cell = new MineCell[width * height];
|
||||||
// Reset timer
|
// Reset timer
|
||||||
mytimer.disconnect();
|
mytimer.disconnect();
|
||||||
timer_count = 0;
|
timer_count = 0;
|
||||||
|
@ -114,7 +115,7 @@ void MineSweeper::reset_game(int width, int height, int mines)
|
||||||
// Reset mines
|
// Reset mines
|
||||||
while (mine_count < mines)
|
while (mine_count < mines)
|
||||||
{
|
{
|
||||||
int index = g_random_int_range(0, 49);
|
int index = g_random_int_range(0, width * height);
|
||||||
if (!(cell[index].has_mine))
|
if (!(cell[index].has_mine))
|
||||||
{
|
{
|
||||||
cell[index].has_mine = true;
|
cell[index].has_mine = true;
|
||||||
|
@ -129,18 +130,18 @@ void MineSweeper::reset_game(int width, int height, int mines)
|
||||||
calc_mines();
|
calc_mines();
|
||||||
|
|
||||||
// Append buttons to grid
|
// Append buttons to grid
|
||||||
for (int i = 0; i < 7; i++)
|
for (int i = 0; i < height; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 7; j++)
|
for (int j = 0; j < width; j++)
|
||||||
{
|
{
|
||||||
// cell[i * 7 + j].set_label("?");
|
// cell[i * 7 + j].set_label("?");
|
||||||
cell[i * 7 + j].signal_clicked().connect(sigc::bind(
|
cell[i * width + j].signal_clicked().connect(sigc::bind(
|
||||||
sigc::mem_fun(*this, &MineSweeper::cell_clicked), &cell[i * 7 + j]));
|
sigc::mem_fun(*this, &MineSweeper::cell_clicked), &cell[i * width + j]));
|
||||||
mine_grid.attach(cell[i * 7 + j], j, i);
|
mine_grid.attach(cell[i * width + j], j, i);
|
||||||
cell[i * 7 + j].set_relief(Gtk::RELIEF_HALF);
|
cell[i * width + j].set_relief(Gtk::RELIEF_HALF);
|
||||||
cell[i * 7 + j].x = j;
|
cell[i * width + j].x = j;
|
||||||
cell[i * 7 + j].y = i;
|
cell[i * width + j].y = i;
|
||||||
cell[i * 7 + j].cleared = false;
|
cell[i * width + j].cleared = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,11 @@ private:
|
||||||
Gtk::Label status_label;
|
Gtk::Label status_label;
|
||||||
Gtk::Box main_box, btn_box;
|
Gtk::Box main_box, btn_box;
|
||||||
Gtk::Button btnstart, btnshow, btnexit;
|
Gtk::Button btnstart, btnshow, btnexit;
|
||||||
|
|
||||||
|
// The cell to place mines
|
||||||
MineCell *cell;
|
MineCell *cell;
|
||||||
bool winned, game_ended;
|
bool winned, game_ended; // The status of game(win/end)
|
||||||
int mines_clear, mine_count;
|
int mines_clear, mine_count; // Whether the mine is cleared
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
Glib::RefPtr<Gtk::Builder> menu_builder;
|
Glib::RefPtr<Gtk::Builder> menu_builder;
|
||||||
|
|
Loading…
Reference in New Issue