]>
git.saurik.com Git - wxWidgets.git/blob - demos/bombs/game.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation of the class BombsGame
4 // Author: P. Foggia 1996
5 // Modified by: Wlodzimierz Skiba (ABX) since 2003
7 // Copyright: (c) 1996 P. Foggia
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
28 # define RAND_MAX INT_MAX
32 BombsGame::~BombsGame()
40 // Initialize the play field. Returns false on failure
41 bool BombsGame::Init(int aWidth
, int aHeight
, bool easyCorner
)
43 m_gridFocusX
= m_gridFocusY
= -1;
53 m_field
= new short[aWidth
*aHeight
];
56 m_width
= m_height
= 0;
63 for(x
=0; x
<m_width
; x
++)
65 for(y
=0; y
<m_height
; y
++)
67 m_field
[x
+y
*m_width
] = ((float)rand()/RAND_MAX
<PROB
)
73 /* Force (0,0) not to have a bomb for those that don't want to have
74 to guess on the first move. Better would be to for the MS rule that
75 whatever is picked first isn't a bomb.
79 m_field
[0] = BG_HIDDEN
;
83 for(x
=0; x
<m_width
; x
++)
84 for(y
=0; y
<m_height
; y
++)
85 if (m_field
[x
+y
*m_width
] & BG_BOMB
)
89 for(xx
=x
-1; xx
<=x
+1; xx
++)
90 if (xx
>=0 && xx
<m_width
)
91 for(yy
=y
-1; yy
<=y
+1; yy
++)
92 if (yy
>=0 && yy
<m_height
&& (yy
!=y
|| xx
!=x
))
93 m_field
[xx
+yy
*m_width
]++;
96 m_numRemainingCells
= m_height
*m_width
-m_numBombCells
;
102 void BombsGame::Mark(int x
, int y
)
104 m_field
[x
+y
*m_width
] ^= BG_MARKED
;
111 void BombsGame::Unhide(int x
, int y
, bool b_selected
)
119 m_field
[x
+y
*m_width
] |= BG_SELECTED
;
121 m_field
[x
+y
*m_width
] &= ~BG_HIDDEN
;
125 m_numRemainingCells
--;
130 void BombsGame::Explode(int x
, int y
)
132 m_field
[x
+y
*m_width
] |= BG_EXPLODED
;