From: Włodzimierz Skiba Date: Fri, 6 May 2005 18:07:14 +0000 (+0000) Subject: Easy corner for new wxBombers (as requested in patch #1178276). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/43c3922bb01aacbb1e2e85c0cd7009618c83434a?hp=4377d3abc8cee8f0ac3cd432e653b33be2dca7ea Easy corner for new wxBombers (as requested in patch #1178276). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33972 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/demos/bombs/bombs.cpp b/demos/bombs/bombs.cpp index 471c848a7f..f1d0883bb8 100644 --- a/demos/bombs/bombs.cpp +++ b/demos/bombs/bombs.cpp @@ -61,11 +61,12 @@ bool BombsApp::OnInit() } BEGIN_EVENT_TABLE(BombsFrame, wxFrame) - EVT_MENU(bombsID_EASY, BombsFrame::OnNewEasyGame) - EVT_MENU(bombsID_MEDIUM, BombsFrame::OnNewMediumGame) - EVT_MENU(bombsID_HARD, BombsFrame::OnNewHardGame) - EVT_MENU(wxID_EXIT, BombsFrame::OnExit) - EVT_MENU(wxID_ABOUT, BombsFrame::OnAbout) + EVT_MENU(bombsID_EASY, BombsFrame::OnNewEasyGame) + EVT_MENU(bombsID_MEDIUM, BombsFrame::OnNewMediumGame) + EVT_MENU(bombsID_HARD, BombsFrame::OnNewHardGame) + EVT_MENU(bombsID_EASYCORNER, BombsFrame::OnEasyCorner) + EVT_MENU(wxID_EXIT, BombsFrame::OnExit) + EVT_MENU(wxID_ABOUT, BombsFrame::OnAbout) END_EVENT_TABLE() BombsFrame::BombsFrame(BombsGame *game) @@ -73,6 +74,8 @@ BombsFrame::BombsFrame(BombsGame *game) wxSize(300, 300), wxDEFAULT_DIALOG_STYLE|wxMINIMIZE_BOX) { m_game = game; + m_easyCorner = false; + m_lastLevel = bombsID_EASY; SetIcon(wxICON(bombs)); @@ -90,6 +93,7 @@ BombsFrame::BombsFrame(BombsGame *game) menuFile->Append(bombsID_NEWGAME, wxT("&New Game"), menuLevel, wxT("Starts a new game")); + menuFile->AppendCheckItem(bombsID_EASYCORNER, wxT("&Easy corner")); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT), wxT("Quits the application")); @@ -137,6 +141,7 @@ void BombsFrame::NewGame(int level, bool query) } int numHorzCells = 20, numVertCells = 20; + m_lastLevel = level; switch(level) { @@ -157,7 +162,7 @@ void BombsFrame::NewGame(int level, bool query) break; } - m_game->Init(numHorzCells, numVertCells); + m_game->Init(numHorzCells, numVertCells, m_easyCorner); GetMenuBar()->Check(level, true); @@ -187,6 +192,30 @@ void BombsFrame::OnNewHardGame(wxCommandEvent& WXUNUSED(event)) NewGame(bombsID_HARD, true); } +void BombsFrame::OnEasyCorner(wxCommandEvent& WXUNUSED(event)) +{ + wxString msg; + if(m_easyCorner) + msg = wxT("enable"); + else + msg = wxT("disable"); + + msg = wxT("Do you really want to ") + msg + wxT(" having\ntop left corner always empty for easier start?"); + + int ok = wxMessageBox( + msg, + wxT("Confirm"), + wxYES_NO | wxICON_QUESTION, + this + ); + + if(ok!=wxYES)return; + + m_easyCorner = !m_easyCorner; + + NewGame(m_lastLevel, true); +} + BEGIN_EVENT_TABLE(BombsCanvas, wxPanel) EVT_PAINT(BombsCanvas::OnPaint) EVT_MOUSE_EVENTS(BombsCanvas::OnMouseEvent) diff --git a/demos/bombs/bombs.h b/demos/bombs/bombs.h index c3923151fd..dbe4a30725 100644 --- a/demos/bombs/bombs.h +++ b/demos/bombs/bombs.h @@ -49,11 +49,15 @@ private: void OnNewMediumGame(wxCommandEvent& event); void OnNewHardGame(wxCommandEvent& event); + void OnEasyCorner(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); BombsGame *m_game; + bool m_easyCorner; + int m_lastLevel; // Subwindows for reference within the program. BombsCanvas *m_canvas; @@ -67,7 +71,8 @@ enum bombsID_NEWGAME = wxID_HIGHEST, bombsID_EASY, bombsID_MEDIUM, - bombsID_HARD + bombsID_HARD, + bombsID_EASYCORNER }; class BombsCanvas : public wxPanel diff --git a/demos/bombs/game.cpp b/demos/bombs/game.cpp index 3778780869..eed0dc622c 100644 --- a/demos/bombs/game.cpp +++ b/demos/bombs/game.cpp @@ -43,7 +43,7 @@ BombsGame::~BombsGame() } // Initialize the play field. Returns false on failure -bool BombsGame::Init(int aWidth, int aHeight) +bool BombsGame::Init(int aWidth, int aHeight, bool easyCorner) { m_gridFocusX = m_gridFocusY = -1; @@ -75,6 +75,15 @@ bool BombsGame::Init(int aWidth, int aHeight) } } + /* Force (0,0) not to have a bomb for those that don't want to have + to guess on the first move. Better would be to for the MS rule that + whatever is picked first isn't a bomb. + */ + if(easyCorner) + { + m_field[0] = BG_HIDDEN; + } + m_numBombCells = 0; for(x=0; x