X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c65afdb458fcb63936fd3db8a2b83ea89a9ef10..3384e744dd5e405c2b4652054aebc7a6b80839f4:/demos/bombs/bombs.cpp diff --git a/demos/bombs/bombs.cpp b/demos/bombs/bombs.cpp index 846f692072..83e4652fca 100644 --- a/demos/bombs/bombs.cpp +++ b/demos/bombs/bombs.cpp @@ -2,17 +2,13 @@ // Name: bombs.cpp // Purpose: Bombs game // Author: P. Foggia 1996 -// Modified by: Wlodzimierz Skiba (ABX) 2003 +// Modified by: Wlodzimierz Skiba (ABX) since 2003 // Created: 1996 // RCS-ID: $Id$ // Copyright: (c) 1996 P. Foggia // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -# pragma implementation -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -23,6 +19,8 @@ # include "wx/wx.h" #endif //precompiled headers +#include "wx/stockitem.h" + #include "bombs.h" #include @@ -53,17 +51,19 @@ bool BombsApp::OnInit() m_frame = new BombsFrame(&m_game); - m_frame->NewGame(bombsID_EASY); + m_frame->NewGame(bombsID_EASY, false); return true; } 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(wxID_NEW, BombsFrame::OnNewGame) + EVT_MENU(bombsID_EASY, BombsFrame::OnEasyGame) + EVT_MENU(bombsID_MEDIUM, BombsFrame::OnMediumGame) + EVT_MENU(bombsID_HARD, BombsFrame::OnHardGame) + 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) @@ -71,6 +71,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)); @@ -86,11 +88,12 @@ BombsFrame::BombsFrame(BombsGame *game) menuLevel->AppendRadioItem(bombsID_MEDIUM, wxT("&Medium (15x15)\tCtrl-2")); menuLevel->AppendRadioItem(bombsID_HARD, wxT("&Hard (25x20)\tCtrl-3")); - menuFile->Append(bombsID_NEWGAME, wxT("&New Game"), - menuLevel, wxT("Starts a new game")); + menuFile->Append(wxID_NEW, wxT("&New game\tCtrl-N")); + menuFile->Append(bombsID_LEVEL, wxT("&Level"),menuLevel, wxT("Starts a new game")); + menuFile->AppendCheckItem(bombsID_EASYCORNER, wxT("&Easy corner")); menuFile->AppendSeparator(); - menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application")); + menuFile->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT), wxT("Quits the application")); menuBar->Append(menuFile, wxT("&File")); @@ -121,10 +124,21 @@ void BombsFrame::OnExit(wxCommandEvent& WXUNUSED(event)) Close(); } -void BombsFrame::NewGame(int level) +void BombsFrame::NewGame(int level, bool query) { + if(query) + { + int ok = wxMessageBox( + wxT("Start new game regardless previous board?"), + wxT("Confirm"), + wxYES_NO | wxICON_QUESTION, + this + ); + if(ok!=wxYES)return; + } int numHorzCells = 20, numVertCells = 20; + m_lastLevel = level; switch(level) { @@ -145,7 +159,7 @@ void BombsFrame::NewGame(int level) break; } - m_game->Init(numHorzCells, numVertCells); + m_game->Init(numHorzCells, numVertCells, m_easyCorner); GetMenuBar()->Check(level, true); @@ -160,19 +174,48 @@ void BombsFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxT("About wxBombs") ); } -void BombsFrame::OnNewEasyGame(wxCommandEvent& WXUNUSED(event)) +void BombsFrame::OnNewGame(wxCommandEvent& WXUNUSED(event)) +{ + NewGame(m_lastLevel, true); +} + +void BombsFrame::OnEasyGame(wxCommandEvent& WXUNUSED(event)) +{ + NewGame(bombsID_EASY, true); +} + +void BombsFrame::OnMediumGame(wxCommandEvent& WXUNUSED(event)) { - NewGame(bombsID_EASY); + NewGame(bombsID_MEDIUM, true); } -void BombsFrame::OnNewMediumGame(wxCommandEvent& WXUNUSED(event)) +void BombsFrame::OnHardGame(wxCommandEvent& WXUNUSED(event)) { - NewGame(bombsID_MEDIUM); + NewGame(bombsID_HARD, true); } -void BombsFrame::OnNewHardGame(wxCommandEvent& WXUNUSED(event)) +void BombsFrame::OnEasyCorner(wxCommandEvent& WXUNUSED(event)) { - NewGame(bombsID_HARD); + 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) @@ -190,7 +233,7 @@ BombsCanvas::BombsCanvas(wxFrame *parent, BombsGame *game) wxFont font= BOMBS_FONT; dc.SetFont(font); - long chw, chh; + wxCoord chw, chh; wxString buf = wxT("M"); dc.GetTextExtent(buf, &chw, &chh); @@ -272,7 +315,7 @@ void BombsCanvas::UpdateGridSize() delete m_bmp; m_bmp = NULL; } - + SetSize(GetGridSizeInPixels()); Refresh(); }