// Name: bombs1.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
* class BombsCanvas
*/
-#ifdef __GNUG__
-# pragma implementation
-#endif
-
#include "wx/wxprec.h"
#ifdef __BORLANDC__
wxString buf;
long chw, chh;
- wxColour wxBlack = wxTheColourDatabase->Find(wxT("BLACK"));
- wxColour wxWhite = wxTheColourDatabase->Find(wxT("WHITE"));
- wxColour wxRed = wxTheColourDatabase->Find(wxT("RED"));
- wxColour wxBlue = wxTheColourDatabase->Find(wxT("BLUE"));
- wxColour wxGrey = wxTheColourDatabase->Find(wxT("LIGHT GREY"));
+ wxColour wxYellow = wxTheColourDatabase->Find(wxT("YELLOW"));
wxColour wxFocused = wxTheColourDatabase->Find(wxT("GREY"));
- wxColour wxGreen = wxTheColourDatabase->Find(wxT("GREEN"));
- wxPen *blackPen = wxThePenList->FindOrCreatePen(wxBlack, 1, wxSOLID);
- wxPen *redPen = wxThePenList->FindOrCreatePen(wxRed, 1, wxSOLID);
- wxPen *bluePen = wxThePenList->FindOrCreatePen(wxBlue, 1, wxSOLID);
- wxBrush *whiteBrush = wxTheBrushList->FindOrCreateBrush(wxWhite, wxSOLID);
- wxBrush *greyBrush = wxTheBrushList->FindOrCreateBrush(wxGrey, wxSOLID);
+ wxPen *bluePen = wxThePenList->FindOrCreatePen(*wxBLUE, 1, wxSOLID);
+
wxBrush *focusedBrush = wxTheBrushList->FindOrCreateBrush(wxFocused, wxSOLID);
- wxBrush *redBrush = wxTheBrushList->FindOrCreateBrush(wxRed, wxSOLID);
+ wxBrush *yellowBrush = wxTheBrushList->FindOrCreateBrush(wxYellow, wxSOLID);
- dc->SetPen(* blackPen);
+ dc->SetPen(*wxBLACK_PEN);
int x, y;
int xMax = this->GetGridSizeInPixels().GetWidth();
wxFont font= BOMBS_FONT;
- dc->SetFont(font);
+ dc->SetFont(font);
for(x=xc1; x<=xc2; x++)
for(y=yc1; y<=yc2; y++)
{
if (m_game->IsMarked(x,y))
{
- dc->SetPen(* blackPen);
+ dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y))
- dc->SetBrush(* focusedBrush);
+ dc->SetBrush(*focusedBrush);
else
- dc->SetBrush(* greyBrush);
+ dc->SetBrush(*wxLIGHT_GREY_BRUSH);
dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
buf = wxT("M");
if (!m_game->IsHidden(x,y) && m_game->IsBomb(x,y))
- dc->SetTextForeground(wxBlue);
+ dc->SetTextForeground(*wxBLUE);
else
- dc->SetTextForeground(wxRed);
+ dc->SetTextForeground(*wxRED);
- dc->SetTextBackground(wxGrey);
+ dc->SetTextBackground(*wxLIGHT_GREY);
dc->GetTextExtent(buf, &chw, &chh);
dc->DrawText( buf,
x*m_cellWidth*X_UNIT + (m_cellWidth*X_UNIT-chw)/2,
if (!m_game->IsHidden(x,y) && m_game->IsBomb(x,y))
{
- dc->SetPen(*redPen);
+ dc->SetPen(*wxRED_PEN);
dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
(x+1)*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT);
dc->DrawLine(x*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT,
}
else if (m_game->IsHidden(x,y))
{
- dc->SetPen(*blackPen);
+ dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y))
- dc->SetBrush(* focusedBrush);
+ dc->SetBrush(*focusedBrush);
else
- dc->SetBrush(*greyBrush);
+ dc->SetBrush(*wxLIGHT_GREY_BRUSH);
dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
}
else if (m_game->IsBomb(x,y))
{
- dc->SetPen(* blackPen);
- dc->SetBrush(* redBrush);
+ dc->SetPen(*wxBLACK_PEN);
+ dc->SetBrush(*wxRED_BRUSH);
dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
buf = wxT("B");
- dc->SetTextForeground(wxBlack);
- dc->SetTextBackground(wxRed);
+ dc->SetTextForeground(*wxBLACK);
+ dc->SetTextBackground(*wxRED);
dc->GetTextExtent(buf, &chw, &chh);
dc->DrawText( buf,
x*m_cellWidth*X_UNIT + (m_cellWidth*X_UNIT-chw)/2,
y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2);
if (m_game->IsExploded(x,y))
{
- dc->SetPen(* bluePen);
+ dc->SetPen(*bluePen);
dc->DrawLine(x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
(x+1)*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT);
dc->DrawLine(x*m_cellWidth*X_UNIT, (y+1)*m_cellHeight*Y_UNIT,
}
else // Display a digit
{
- dc->SetPen(* blackPen);
+ dc->SetPen(*wxBLACK_PEN);
if (m_game->IsFocussed(x, y))
- dc->SetBrush(* focusedBrush);
- else
- dc->SetBrush(* whiteBrush);
+ dc->SetBrush(*focusedBrush);
+ else if (m_game->IsSelected(x,y))
+ dc->SetBrush(*wxWHITE_BRUSH);
+ else
+ dc->SetBrush(*yellowBrush);
dc->DrawRectangle( x*m_cellWidth*X_UNIT, y*m_cellHeight*Y_UNIT,
m_cellWidth*X_UNIT+1, m_cellHeight*Y_UNIT+1);
{
case 0:
buf = wxT("0");
- dc->SetTextForeground(wxGreen);
+ dc->SetTextForeground(*wxGREEN);
break;
- case 1:
+ case 1:
buf = wxT("1");
- dc->SetTextForeground(wxBlue);
+ dc->SetTextForeground(*wxBLUE);
break;
default:
buf.Printf(wxT("%d"),digit_value);
- dc->SetTextForeground(wxBlack);
+ dc->SetTextForeground(*wxBLACK);
break;
}
dc->GetTextExtent(buf, &chw, &chh);
- dc->SetTextBackground(wxWhite);
+ dc->SetTextBackground(*wxWHITE);
dc->DrawText( buf,
x*m_cellWidth*X_UNIT + (m_cellWidth*X_UNIT-chw)/2,
y*m_cellHeight*Y_UNIT + (m_cellHeight*Y_UNIT-chh)/2);
}
dc->SetFont(wxNullFont);
-#if wxUSE_LOG
- wxLogStatus(wxT("%d bombs %d remaining cells"),
- m_game->GetNumBombs(), m_game->GetNumRemainingCells() );
+ wxString msg;
+ msg.Printf(wxT("%d bombs, %u marked, %d remaining cells"),
+ m_game->GetNumBombs(), m_game->GetNumMarkedCells(),
+ m_game->GetNumRemainingCells() );
+
+#if wxUSE_LOG && wxUSE_STATUSBAR
+ wxLogStatus(msg);
+#else
+ this->GetParent()->SetTitle(msg);
#endif
}
// Called when uncovering a cell.
void BombsCanvas::Uncover(int x, int y)
{
- m_game->Unhide(x,y);
+ m_game->Unhide(x,y,true);
RefreshField(x, y, x, y);
const int gridWidth = m_game->GetWidth();
for(x=0; x<gridWidth; x++)
for(y=0; y<gridHeight; y++)
- m_game->Unhide(x,y);
- RefreshField(0, 0, gridWidth-1, gridHeight-1);
+ m_game->Unhide(x,y,false);
+
+ RefreshField(0, 0, gridWidth-1, gridHeight-1);
}
- else if (!m_game->Get(x, y))
+ else if (0 == (m_game->Get(x, y) & BG_MASK))
{
int left = ( x > 0 ) ? x-1 : 0;
int right = ( x < gridWidth - 1 )
if ( (event.RightDown() || (event.LeftDown() && event.ShiftDown()))
&& (m_game->IsHidden(x,y)
|| !m_game->GetNumRemainingCells() ) )
- {
+ {
// store previous and current field
int prevFocusX = m_game->m_gridFocusX;
int prevFocusY = m_game->m_gridFocusY;
if ((prevGridFocusX != m_game->m_gridFocusX)
|| (prevGridFocusY != m_game->m_gridFocusY))
{
+ // cause focused field to be visible after first key hit after launching new game
+ if( m_game->m_gridFocusX < 0 ) m_game->m_gridFocusX = 0;
+ if( m_game->m_gridFocusY < 0 ) m_game->m_gridFocusY = 0;
+
// refresh previous field and focused field
RefreshField(prevGridFocusX, prevGridFocusY,
prevGridFocusX, prevGridFocusY);