Click here to Skip to main content
15,895,799 members
Articles / Mobile Apps

Minesweeper and MinsweeperFlags (a multiplayer version) in one for PocketPC

Rate me:
Please Sign up or sign in to vote.
4.00/5 (14 votes)
30 May 2004CPOL4 min read 63.9K   596   16  
Pocket PC .NET Compact Framework version of Minesweeper and MinsweeperFlags (multiplayer) game in one
using System;

namespace gma.Mobile.Mines
{

	public delegate void OnMovePassedEvent(Player aCurrentPalyer);

	/// <summary>
	/// Zusammenfassung f�r MultiPlayerGame.
	/// </summary>
	public class MultiPlayerGame: GameBase
	{

		public MultiPlayerGame(byte aWidth, byte aHeight, byte aBombCount): base(aWidth, aHeight, aBombCount)
		{
			_flagsToWin=(int)Math.Floor(_field.BombCount / 2 );
		}

		private int _flagsToWin=0;
		public int FlagsToWin
		{
			get {return _flagsToWin;}
		}

		public override void ClickCell(byte x, byte y)
		{
			if (_field.CellStates[x,y]!=CellState.Closed) return; 
			if (_field.Bombs[x,y]==Field.ISBOMB) SetFlagIntern( x,  y);
			else
			{
				base.ClickCell(x,y);
				PassMove();
			}
		}

		public override void SetFlag(byte x, byte y)
		{
			ClickCell(x,y);
		}

		private void SetFlagIntern(byte x, byte y)
		{
			if  (_field.CellStates[x,y]==CellState.FlagBlue || _field.CellStates[x,y]==CellState.FlagRed) return;

			if (_field.CellStates[x,y]==CellState.Open) return;

			CellState BeforeState = _field.CellStates[x,y];

			_field.CellStates[x,y]=GetFlagColorOfCurrentPlayer();

			// inform others that this cell was modified.
			CellChanged(x,y, BeforeState, _field.CellStates[x,y]);

			if (FlagCountRed > _flagsToWin) GameOver(Player.Red); 
			if (FlagCountBlue > _flagsToWin) GameOver(Player.Blue); 

		}


		public event OnMovePassedEvent OnMovePassed;

		public void PassMove()
		{
			switch (CurrentPlayer)
			{
				case Player.Blue:
					CurrentPlayer=Player.Red;
					break;

				case Player.Red:
					CurrentPlayer=Player.Blue;
					break;
			}
			if (OnMovePassed!=null) OnMovePassed(CurrentPlayer);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
Tweeter: @gmamaladze
Google+: gmamaladze
Blog: gmamaladze.wordpress.com

Comments and Discussions