From 7874bf5430d47317bebf5c68cd7d4a2d964dee95 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Oct 2000 17:06:43 +0000 Subject: [PATCH] applied patch to uncover cells next to 0 automatically git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- demos/bombs/bombs.h | 1 + demos/bombs/bombs1.cpp | 54 +++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/demos/bombs/bombs.h b/demos/bombs/bombs.h index 9684acac88..d1b8b8017b 100644 --- a/demos/bombs/bombs.h +++ b/demos/bombs/bombs.h @@ -95,6 +95,7 @@ class BombsCanvasClass: public wxWindow void OnPaint(wxPaintEvent& event); void DrawField(wxDC *, int xc1, int yc1, int xc2, int yc2); void Refresh(int xc1, int yc1, int xc2, int yc2); + void Uncover(int x, int y); void OnEvent(wxMouseEvent& event); void UpdateFieldSize(); 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