]>
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) 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
)
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
)
79 for(x
=0; x
<m_width
; x
++)
80 for(y
=0; y
<m_height
; y
++)
81 if (m_field
[x
+y
*m_width
] & BG_BOMB
)
85 for(xx
=x
-1; xx
<=x
+1; xx
++)
86 if (xx
>=0 && xx
<m_width
)
87 for(yy
=y
-1; yy
<=y
+1; yy
++)
88 if (yy
>=0 && yy
<m_height
&& (yy
!=y
|| xx
!=x
))
89 m_field
[xx
+yy
*m_width
]++;
92 m_numRemainingCells
= m_height
*m_width
-m_numBombCells
;
97 void BombsGame::Mark(int x
, int y
)
99 m_field
[x
+y
*m_width
] ^= BG_MARKED
;
102 void BombsGame::Unhide(int x
, int y
)
109 m_field
[x
+y
*m_width
] &= ~BG_HIDDEN
;
113 m_numRemainingCells
--;
118 void BombsGame::Explode(int x
, int y
)
120 m_field
[x
+y
*m_width
] |= BG_EXPLODED
;