X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70d26c3f4ffb24d50457d405c9595fd23f9e5b7c..88522554f8b99bd5ac2382ca21c1ad57ed876d30:/demos/bombs/bombs1.cpp diff --git a/demos/bombs/bombs1.cpp b/demos/bombs/bombs1.cpp index 0b77417dcc..e884888349 100644 --- a/demos/bombs/bombs1.cpp +++ b/demos/bombs/bombs1.cpp @@ -33,15 +33,15 @@ /*---------------------------------------------------------------------*/ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) { int x,y,xmax,ymax; - char buf[2]; + wxChar buf[2]; long chw, chh; - wxColour *wxBlack = wxTheColourDatabase->FindColour("BLACK"); - wxColour *wxWhite = wxTheColourDatabase->FindColour("WHITE"); - wxColour *wxRed = wxTheColourDatabase->FindColour("RED"); - wxColour *wxBlue = wxTheColourDatabase->FindColour("BLUE"); - wxColour *wxGrey = wxTheColourDatabase->FindColour("LIGHT GREY"); - wxColour *wxGreen = wxTheColourDatabase->FindColour("GREEN"); + wxColour *wxBlack = wxTheColourDatabase->FindColour(_T("BLACK")); + wxColour *wxWhite = wxTheColourDatabase->FindColour(_T("WHITE")); + wxColour *wxRed = wxTheColourDatabase->FindColour(_T("RED")); + wxColour *wxBlue = wxTheColourDatabase->FindColour(_T("BLUE")); + wxColour *wxGrey = wxTheColourDatabase->FindColour(_T("LIGHT GREY")); + wxColour *wxGreen = wxTheColourDatabase->FindColour(_T("GREEN")); wxPen *blackPen = wxThePenList->FindOrCreatePen(*wxBlack, 1, wxSOLID); wxPen *redPen = wxThePenList->FindOrCreatePen(*wxRed, 1, wxSOLID); @@ -64,7 +64,7 @@ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) wxFont font= BOMBS_FONT; dc->SetFont(font); - buf[1]='\0'; + buf[1]=_T('\0'); for(x=xc1; x<=xc2; x++) for(y=yc1; y<=yc2; y++) { if (wxGetApp().Game.IsMarked(x,y)) @@ -72,7 +72,7 @@ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) dc->SetBrush(* greyBrush); dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT, x_cell*X_UNIT+1, y_cell*Y_UNIT+1); - *buf='M'; + *buf=_T('M'); if (!wxGetApp().Game.IsHidden(x,y) && wxGetApp().Game.IsBomb(x,y)) dc->SetTextForeground(*wxBlue); else @@ -102,7 +102,7 @@ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) dc->SetBrush(* redBrush); dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT, x_cell*X_UNIT+1, y_cell*Y_UNIT+1); - *buf='B'; + *buf=_T('B'); dc->SetTextForeground(* wxBlack); dc->SetTextBackground(* wxRed); dc->GetTextExtent(buf, &chw, &chh); @@ -123,11 +123,11 @@ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) dc->SetBrush(* whiteBrush); dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT, x_cell*X_UNIT+1, y_cell*Y_UNIT+1); - *buf = (wxGetApp().Game.Get(x,y) & BG_MASK) + '0'; + *buf = (wxGetApp().Game.Get(x,y) & BG_MASK) + _T('0'); dc->GetTextExtent(buf, &chw, &chh); switch(*buf) - { case '0': dc->SetTextForeground(* wxGreen); break; - case '1': dc->SetTextForeground(* wxBlue); break; + { case _T('0'): dc->SetTextForeground(* wxGreen); break; + case _T('1'): dc->SetTextForeground(* wxBlue); break; default: dc->SetTextForeground(* wxBlack); break; } dc->SetTextBackground(* wxWhite); @@ -140,9 +140,10 @@ void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2) dc->SetFont(wxNullFont); if (wxGetApp().BombsFrame) - { char buf[80]; - sprintf(buf, "%d bombs %d remaining cells", - wxGetApp().Game.GetBombs(), wxGetApp().Game.GetRemainingCells()); + { wxString buf; + buf.Printf(_T("%d bombs %d remaining cells"), + wxGetApp().Game.GetBombs(), + wxGetApp().Game.GetRemainingCells()); wxGetApp().BombsFrame->SetStatusText(buf, 0); } } @@ -164,6 +165,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(_T("Nice! You found all the bombs!"), _T("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 +217,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