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
This commit is contained in:
Vadim Zeitlin 2000-10-30 17:06:43 +00:00
parent f469b27cac
commit 7874bf5430
2 changed files with 38 additions and 17 deletions

View File

@ -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();

View File

@ -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<field_width; x++)
for(y=0; y<field_height; y++)
wxGetApp().Game.Unhide(x,y);
Refresh(0, 0, field_width-1, field_height-1);
}
else if (!wxGetApp().Game.Get(x, y))
{ int left = ( 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<field_width; x++)
for(y=0; y<field_height; y++)
wxGetApp().Game.Unhide(x,y);
Refresh(0, 0, field_width-1, field_height-1);
}
return;
{ Uncover(x,y);
return;
}
}
}