]>
git.saurik.com Git - wxWidgets.git/blob - demos/bombs/game.cpp
9790ed67a6fde666bc7d752e57f3f92c7a2dce8e
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation of the class BombsGame
4 // Author: P. Foggia 1996
5 // Modified by: Wlodzimierz Skiba (ABX) since 2003
8 // Copyright: (c) 1996 P. Foggia
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 # pragma implementation
16 #include "wx/wxprec.h"
33 # define RAND_MAX INT_MAX
37 BombsGame::~BombsGame()
45 // Initialize the play field. Returns false on failure
46 bool BombsGame::Init(int aWidth
, int aHeight
, bool easyCorner
)
48 m_gridFocusX
= m_gridFocusY
= -1;
58 m_field
= new short[aWidth
*aHeight
];
61 m_width
= m_height
= 0;
68 for(x
=0; x
<m_width
; x
++)
70 for(y
=0; y
<m_height
; y
++)
72 m_field
[x
+y
*m_width
] = ((float)rand()/RAND_MAX
<PROB
)
78 /* Force (0,0) not to have a bomb for those that don't want to have
79 to guess on the first move. Better would be to for the MS rule that
80 whatever is picked first isn't a bomb.
84 m_field
[0] = BG_HIDDEN
;
88 for(x
=0; x
<m_width
; x
++)
89 for(y
=0; y
<m_height
; y
++)
90 if (m_field
[x
+y
*m_width
] & BG_BOMB
)
94 for(xx
=x
-1; xx
<=x
+1; xx
++)
95 if (xx
>=0 && xx
<m_width
)
96 for(yy
=y
-1; yy
<=y
+1; yy
++)
97 if (yy
>=0 && yy
<m_height
&& (yy
!=y
|| xx
!=x
))
98 m_field
[xx
+yy
*m_width
]++;
101 m_numRemainingCells
= m_height
*m_width
-m_numBombCells
;
102 m_numMarkedCells
= 0;
107 void BombsGame::Mark(int x
, int y
)
109 m_field
[x
+y
*m_width
] ^= BG_MARKED
;
116 void BombsGame::Unhide(int x
, int y
, bool b_selected
)
124 m_field
[x
+y
*m_width
] |= BG_SELECTED
;
126 m_field
[x
+y
*m_width
] &= ~BG_HIDDEN
;
130 m_numRemainingCells
--;
135 void BombsGame::Explode(int x
, int y
)
137 m_field
[x
+y
*m_width
] |= BG_EXPLODED
;