|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is my version of an old, well known game and a contribution to the CodeProject Mobile Developer competition. This is my second .NET Compact Framework based application (The first was of course a HelloWorld.) and this is also my first CodeProject article. One thing I always missed on my PocketPC was our old sweet Minesweeper. So I have decided to invest a couple evenings to play with Visual Studio .NET. After one week I had a normal single player version. The second step was a multiplayer modification of this game (like MinsweeperFlags from MSN Messenger). A hot seat version (both players on the same Pocket PC) was ready very soon, but my goal was a game over a Network or an IrDA. I have written the network layer and ... that's where I am staying now. Game rulesSingle player Everyone knows simple rules of Minesweeper. My single player mode works the same
way.
Because MinesweeperFlags is not so well known as the classical Minesweeper I'd like to say some words about its rules. There are two players Red and Blue one. Game objective is to find and flag mines that are concealed on the board. The first player to flag more than half of the mines wins. Click your left mouse button on a square to see if a mine is there. If a mine is there it will be revealed and your colored flag will be planted on it. You will then get another turn. If the square does not contain a mine, your turn will be over. Each player receives one point for each mine they flagged.
Using the code
In fact the whole Program can be divided into three layers.
I use events to simplify the intaraction between layers. For example public class SinglePlayerGame: GameBase
{
public SinglePlayerGame(byte aWidth, byte aHeight,
byte aBombCount): base(aWidth, aHeight, aBombCount)
{
}
public override void ClickCell(byte x, byte y)
{
// Open a cell and open all neigbors whenn needed.
// This all is implemented in our base class.
base.ClickCell(x,y);
// The condition to loose, because it is game version secific.
if (_field.Bombs[x,y]==Field.ISBOMB) GameOver(Player.None);
// The condition to win, because it is game version secific.
if (ClosedCount==_field.BombCount ) GameOver(CurrentPlayer);
}
// The SetFlag behavior is different in both versions
// that is why it must be implemented here.
public override void SetFlag(byte x, byte y)
{
// When cell is already opened do nothing
if (_field.CellStates[x,y]==CellState.Open) return;
// remember cell state before changes are made
CellState BeforeState = _field.CellStates[x,y];
// Unmark when already marked
if (_field.CellStates[x,y]==GetFlagColorOfCurrentPlayer())
_field.CellStates[x,y]=CellState.Closed;
// Mark when not marked
else _field.CellStates[x,y]=GetFlagColorOfCurrentPlayer();
// Inform others that this cell was modified.
CellChanged(x,y, BeforeState, _field.CellStates[x,y]);
}
}
Points of InterestThere are some interesting issues I'd like to share with you.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||