]> git.saurik.com Git - wxWidgets.git/commitdiff
Easy corner for new wxBombers (as requested in patch #1178276).
authorWłodzimierz Skiba <abx@abx.art.pl>
Fri, 6 May 2005 18:07:14 +0000 (18:07 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Fri, 6 May 2005 18:07:14 +0000 (18:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33972 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

demos/bombs/bombs.cpp
demos/bombs/bombs.h
demos/bombs/game.cpp
demos/bombs/game.h

index 471c848a7fd516f4d3df3a1d7438c2e5d63e5181..f1d0883bb8149e7db4ac74161c09eee016a6da54 100644 (file)
@@ -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)
index c3923151fd1e0720a85000004022cf08f9ab8a65..dbe4a3072529a56242433209b513b036cf40eb97 100644 (file)
@@ -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
index 3778780869ebafe2d9fca0168d9cb25ac5e8e5d1..eed0dc622ccf99558ae95b75b0649f1f7f5c339d 100644 (file)
@@ -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<m_width; x++)
         for(y=0; y<m_height; y++)
index 00cc83ea058687d7b484a92a8974a7efe030fd4b..636d024e8e68065e6f9722cc93e6501c7c2318ac 100644 (file)
@@ -76,7 +76,7 @@ public:
 
 
 
-    bool Init(int width, int height);
+    bool Init(int width, int height, bool easyCorner = false);
 
 
     // Marks/unmarks a cell