]>
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
8 // Copyright: (c) 1996 P. Foggia
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
29 # define RAND_MAX INT_MAX
33 BombsGame::~BombsGame()
41 // Initialize the play field. Returns false on failure
42 bool BombsGame::Init(int aWidth
, int aHeight
, bool easyCorner
)
44 m_gridFocusX
= m_gridFocusY
= -1;
54 m_field
= new short[aWidth
*aHeight
];
57 m_width
= m_height
= 0;
64 for(x
=0; x
<m_width
; x
++)
66 for(y
=0; y
<m_height
; y
++)
68 m_field
[x
+y
*m_width
] = ((float)rand()/RAND_MAX
<PROB
)
74 /* Force (0,0) not to have a bomb for those that don't want to have
75 to guess on the first move. Better would be to for the MS rule that
76 whatever is picked first isn't a bomb.
80 m_field
[0] = BG_HIDDEN
;
84 for(x
=0; x
<m_width
; x
++)
85 for(y
=0; y
<m_height
; y
++)
86 if (m_field
[x
+y
*m_width
] & BG_BOMB
)
90 for(xx
=x
-1; xx
<=x
+1; xx
++)
91 if (xx
>=0 && xx
<m_width
)
92 for(yy
=y
-1; yy
<=y
+1; yy
++)
93 if (yy
>=0 && yy
<m_height
&& (yy
!=y
|| xx
!=x
))
94 m_field
[xx
+yy
*m_width
]++;
97 m_numRemainingCells
= m_height
*m_width
-m_numBombCells
;
103 void BombsGame::Mark(int x
, int y
)
105 m_field
[x
+y
*m_width
] ^= BG_MARKED
;
112 void BombsGame::Unhide(int x
, int y
, bool b_selected
)
120 m_field
[x
+y
*m_width
] |= BG_SELECTED
;
122 m_field
[x
+y
*m_width
] &= ~BG_HIDDEN
;
126 m_numRemainingCells
--;
131 void BombsGame::Explode(int x
, int y
)
133 m_field
[x
+y
*m_width
] |= BG_EXPLODED
;