X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70d26c3f4ffb24d50457d405c9595fd23f9e5b7c..4fa0a5b44341885a0886f2ae6723d2441bd1f62f:/demos/bombs/bombs1.cpp diff --git a/demos/bombs/bombs1.cpp b/demos/bombs/bombs1.cpp index 0b77417dcc..173bce2383 100644 --- a/demos/bombs/bombs1.cpp +++ b/demos/bombs/bombs1.cpp @@ -164,6 +164,41 @@ void BombsCanvasClass::Refresh(int xc1, int yc1, int xc2, int yc2) } } +// Called when uncovering a cell. +void BombsCanvasClass::Uncover(int x, int y) +{ + wxGetApp().Game.Unhide(x,y); + Refresh(x, y, x, y); + if (wxGetApp().Game.IsBomb(x,y) || wxGetApp().Game.GetRemainingCells()==0) + { wxBell(); + if (!wxGetApp().Game.IsBomb(x,y)) + { wxMessageBox("Nice! You found all the bombs!", "wxWin Bombs", + wxOK|wxCENTRE, wxGetApp().BombsFrame); + } + else // x,y is a bomb + { wxGetApp().Game.Explode(x, y); + } + for(x=0; x 0 ) ? x-1 : 0; + int right = ( x < wxGetApp().Game.GetWidth() - 1 )? + x+1 : wxGetApp().Game.GetWidth() - 1; + int top = ( y > 0 ) ? y-1 : 0; + int bottom = ( y < wxGetApp().Game.GetHeight() - 1 )? + y+1 : wxGetApp().Game.GetHeight() - 1; + int i,j; + for (j = top; j <= bottom; j++) + for (i=left; i <= right; i++) + if ((i != x || j != y) && wxGetApp().Game.IsHidden(i,j) + && !wxGetApp().Game.IsMarked(i,j)) + Uncover(i,j); + } +} + // Called when the canvas receives a mouse event. void BombsCanvasClass::OnEvent(wxMouseEvent& event) { @@ -181,23 +216,8 @@ void BombsCanvasClass::OnEvent(wxMouseEvent& event) } else if (event.LeftDown() && wxGetApp().Game.IsHidden(x,y) && !wxGetApp().Game.IsMarked(x,y)) - { wxGetApp().Game.Unhide(x,y); - Refresh(x, y, x, y); - if (wxGetApp().Game.IsBomb(x,y) || wxGetApp().Game.GetRemainingCells()==0) - { wxBell(); - if (!wxGetApp().Game.IsBomb(x,y)) - { wxMessageBox("Nice! You found all the bombs!", "wxWin Bombs", - wxOK|wxCENTRE, wxGetApp().BombsFrame); - } - else // x,y is a bomb - { wxGetApp().Game.Explode(x, y); - } - for(x=0; x