Esempio n. 1
0
		/// <summary>
		/// Do the drag and drop for a player making a move
		/// with a light piece
		/// </summary>
		/// <param name="square"></param>
		private void PlayerLightMove( DraughtsSquare square )
		{
			/// Light or red squares always start at the bottom and move up
			/// 

			bool bMustTake = game.CheckForMustTake( true );

			bCanStillTake = false;

			/// make sure there's no backwards movement
			/// 

			if( bsStartSquare.IsKing == false )
			{
				if( bsStartSquare != null 
					&& GetSquareAboveLeft( bsStartSquare.Identifier ) == square 
					|| GetSquareAboveRight( bsStartSquare.Identifier ) == square )
				{

					if( bMustTake == false )
					{
						square.DragDropImage = bitLightDrop;
						bAllowDrop = true;
					}
					else
					{
						square.DragDropImage = this.bitLightNoDrop;
						bAllowDrop = false;
					}

					return;
				}
			}
			else
			{
				if( bsStartSquare != null 
					&& GetSquareAboveLeft( bsStartSquare.Identifier ) == square 
					|| GetSquareAboveRight( bsStartSquare.Identifier ) == square
					|| GetSquareBelowLeft( bsStartSquare.Identifier ) == square 
					|| GetSquareBelowRight( bsStartSquare.Identifier ) == square )
				{
					if( bMustTake == false )
					{
						square.DragDropImage = bitLightKingDrop;
						bAllowDrop = true;
					}
					else
					{
						square.DragDropImage = bitLightKingNoDrop;
						bAllowDrop = false;
					}

					return;
				}
			}																		

			bPlayerTakesPiece = false;
								
			/// now the tricky bit
			/// Get the square to the upper left of the start square
			/// 
			if( bsStartSquare != null && bsStartSquare.Identifier[ 0 ] > square.Identifier[ 0 ] 
				|| bsStartSquare != null && bsStartSquare.Identifier[ 0 ] < square.Identifier[ 0 ] )
			{
				BasicSquare squareNext = GetSquareAboveLeft( bsStartSquare.Identifier );

				if( squareNext != null )
				{
					/// if the square above it is the current square
					/// 
					if( GetSquareAboveLeft( squareNext.Identifier ) == square )
					{
						/// if the square below right is a computer piece
						/// 
						if( squareNext.IsOccupied == true && squareNext.OccupyingName != bsStartSquare.OccupyingName )
						{
							if( bsStartSquare.IsKing == true )
								square.DragDropImage = bitLightKingDrop;
							else
								square.DragDropImage = bitLightDrop;

							bAllowDrop = true;
							bPlayerTakesPiece = true;
							strTakenPieceIdentifier = squareNext.Identifier;

							/// check to see if there is a continuing take
							/// 

							squareNext = GetSquareAboveLeft( square.Identifier );
 
							if( squareNext != null && squareNext.IsOccupied == true 
								&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								squareNext = GetSquareAboveLeft( squareNext.Identifier );

								if( squareNext != null && squareNext.IsOccupied == false )
								{
									bCanStillTake = true;
									strTakingPieceIdentifier = squareNext.Identifier;
								}
							}

							squareNext = GetSquareAboveRight( square.Identifier );

							if( squareNext != null && squareNext.IsOccupied == true 
								&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								squareNext = GetSquareAboveRight( squareNext.Identifier );

								if( squareNext != null && squareNext.IsOccupied == false )
								{
									bCanStillTake = true;
									strTakingPieceIdentifier = squareNext.Identifier;
								}
							}

							return;

						}
						else
						{
							if( bsStartSquare.IsKing == true )
								square.DragDropImage = bitLightKingNoDrop;
							else
								square.DragDropImage = bitLightNoDrop;

							bAllowDrop = false;
						}
					}
				}

				squareNext = GetSquareAboveRight( bsStartSquare.Identifier );

				if( squareNext != null )
				{

					if( GetSquareAboveRight( squareNext.Identifier ) == square )
					{
						if( squareNext.IsOccupied == true && squareNext.OccupyingName != bsStartSquare.OccupyingName )
						{
							if( bsStartSquare.IsKing == true )
								square.DragDropImage = bitLightKingDrop;
							else
								square.DragDropImage = bitLightDrop;

							bAllowDrop = true;
							bPlayerTakesPiece = true;
							strTakenPieceIdentifier = squareNext.Identifier;

							/// check to see if there is a continuing take
							/// 

							squareNext = GetSquareAboveLeft( square.Identifier );
 
							if( squareNext != null && squareNext.IsOccupied == true 
								&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								squareNext = GetSquareAboveLeft( squareNext.Identifier );

								if( squareNext != null && squareNext.IsOccupied == false )
									bCanStillTake = true;
							}

							squareNext = GetSquareAboveRight( square.Identifier );

							if( squareNext != null && squareNext.IsOccupied == true 
								&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								squareNext = GetSquareAboveRight( squareNext.Identifier );

								if( squareNext != null && squareNext.IsOccupied == false )
									bCanStillTake = true;
							}

							return;

						}
						else
						{
							if( bsStartSquare.IsKing == true )
								square.DragDropImage = bitLightKingNoDrop;
							else
								square.DragDropImage = bitLightNoDrop;

							bAllowDrop = false;
						}
					}
				}
			}


			/// now do the same for king only moves
			/// 

			if( bsStartSquare != null && bsStartSquare.IsKing == true )
			{
				if( bsStartSquare.Identifier[ 0 ] > square.Identifier[ 0 ] )
				{
					BasicSquare squareNext = GetSquareBelowLeft( bsStartSquare.Identifier );

					if( squareNext != null )
					{
						if( GetSquareBelowLeft( squareNext.Identifier ) == square )
						{
							if( squareNext.IsOccupied == true && squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								square.DragDropImage = bitLightKingDrop;

								bAllowDrop = true;
								bPlayerTakesPiece = true;
								strTakenPieceIdentifier = squareNext.Identifier;

								/// check to see if there is a continuing take
								/// 

								squareNext = GetSquareBelowLeft( square.Identifier );
 
								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareBelowLeft( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareBelowRight( square.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareBelowRight( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareAboveLeft( square.Identifier );
 
								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareAboveLeft( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareAboveRight( square.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareAboveRight( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}
							}
							else
							{
								square.DragDropImage = bitLightKingNoDrop;

								bAllowDrop = false;
							}

							Invalidate();
							Update();
							return;
						}
					}
				}

				if( bsStartSquare.Identifier[ 0 ] < square.Identifier[ 0 ] )
				{
					BasicSquare squareNext = GetSquareBelowRight( bsStartSquare.Identifier );

					if( squareNext != null )
					{
						if( GetSquareBelowRight( squareNext.Identifier ) == square )
						{
							if( squareNext.IsOccupied == true && squareNext.OccupyingName != bsStartSquare.OccupyingName )
							{
								square.DragDropImage = bitLightKingDrop;

								bAllowDrop = true;
								bPlayerTakesPiece = true;
								strTakenPieceIdentifier = squareNext.Identifier;

								/// check to see if there is a continuing take
								/// 

								squareNext = GetSquareBelowLeft( square.Identifier );
 
								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareBelowLeft( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareBelowRight( square.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareBelowRight( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareAboveLeft( square.Identifier );
 
								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareAboveLeft( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}

								squareNext = GetSquareAboveRight( square.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true 
									&& squareNext.OccupyingName != bsStartSquare.OccupyingName )
								{
									squareNext = GetSquareAboveRight( squareNext.Identifier );

									if( squareNext != null && squareNext.IsOccupied == false )
										bCanStillTake = true;
								}
							}
							else
							{
								square.DragDropImage = bitLightKingNoDrop;

								bAllowDrop = false;
							}

							Invalidate();
							Update();
							return;
						}
					}
				}
			}

			if( bsStartSquare.IsKing == true )
				square.DragDropImage = bitLightKingNoDrop;
			else
				square.DragDropImage = bitLightNoDrop;

			bAllowDrop = false;
		}
Esempio n. 2
0
		private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if( ImplementDragDrop == true )
			{
				DraughtsSquare square = ( DraughtsSquare )GetSquareAt( e.X, e.Y );

				if( square != null && square.IsOccupied == true )
				{
					if( square.OccupyingName == "COMPUTER" )
						return;

					if( square.PlayerIsOnSquare == false )
						return;

					if( DragDropImage != null )
					{
						DragDropEffects effects = DoDragDrop( DragDropImage, DragDropEffects.Copy );

						/// this code is triggered after the drop event
						/// and on the initial click
						///

						bStartDragDrop = false;

						if( bHasDropped == true
							|| bInvalidSquareDrop == true )
						{
							DragDropFrom = square;
							bHasDropped = false;
							Cursor = Cursors.Default;
						}

						if( bPlayerTakesPiece == true )
						{
							RemovePieceFromSquare( strTakenPieceIdentifier );
						}

						/// Fixes the incredible disappearing pieces bug.
						/// If a piece was taken by the player and then the computer
						/// moved onto that square then the above code would make the computer
						/// piece disappear later on because the variables below
						/// hadn't been reset
						/// Bastard!!
						/// 
						bPlayerTakesPiece = false;
						strTakenPieceIdentifier = null;

						if( bInvalidSquareDrop == true )
						{
							foreach( DictionaryEntry dicEnt in GetHashTable )
							{
								BasicSquare squareTemp = ( BasicSquare )dicEnt.Value;

								squareTemp.DrawDragDropImage = false;
							}
						}


						/// remove highlights
						/// 

						foreach( DictionaryEntry dicEnt in GetHashTable )
						{
							BasicSquare squareTemp = ( BasicSquare )dicEnt.Value;

							squareTemp.DrawHighlight = false;
						}

						if( bCanStillTake == true )
						{
							effects = DoDragDrop( DragDropImage, DragDropEffects.None );
							return;
						}

						/// do the computers move
						/// 

						if( bInvalidSquareDrop == false
							&& bCanStillTake == false
							&& bAllowComputerMove == true )
						{
							PlayersMove = false;
							if( PlayerIsLight == true )
								ComputersMove( false );
							else
								ComputersMove( true );

							bAllowComputerMove = false;
						}

						Invalidate();
						Update();

					}
					else
					{
						MessageBox.Show( "You've not set the drag drop image dumbass" );
					}
				} 
				else
				{
					DragDropEffects effects = DoDragDrop( DragDropImage, DragDropEffects.None );
					bsStartSquare = null;
				}
			}

		}
Esempio n. 3
0
		/// <summary>
		/// Initialize the board
		/// </summary>
		public void InitializeBoard()
		{
			HorizontalSquares = 8;
			VerticalSquares = 8;
			SquareWidth = 75;
			SquareHeight = 75;
			BoardWidth = HorizontalSquares * SquareWidth;
			BoardHeight = VerticalSquares * SquareHeight;

			/// create the board
			Clear();

			GetHashTable.Add( "AA", new DraughtsSquare( SquareWidth, SquareHeight, 0, 0, "AA" ) );
			GetHashTable.Add( "AB", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight, "AB" ) );
			GetHashTable.Add( "AC", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 2, "AC" ) );
			GetHashTable.Add( "AD", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 3, "AD" ) );
			GetHashTable.Add( "AE", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 4, "AE" ) );
			GetHashTable.Add( "AF", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 5, "AF" ) );
			GetHashTable.Add( "AG", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 6, "AG" ) );
			GetHashTable.Add( "AH", new DraughtsSquare( SquareWidth, SquareHeight, 0, SquareHeight * 7, "AH" ) );
			GetHashTable.Add( "BA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, 0, "BA" ) );
			GetHashTable.Add( "BB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight, "BB" ) );
			GetHashTable.Add( "BC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 2, "BC" ) );
			GetHashTable.Add( "BD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 3, "BD" ) );
			GetHashTable.Add( "BE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 4, "BE" ) );
			GetHashTable.Add( "BF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 5, "BF" ) );
			GetHashTable.Add( "BG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 6, "BG" ) );
			GetHashTable.Add( "BH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth, SquareHeight * 7, "BH" ) );
			GetHashTable.Add( "CA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, 0, "CA" ) );
			GetHashTable.Add( "CB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight, "CB" ) );
			GetHashTable.Add( "CC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 2, "CC" ) );
			GetHashTable.Add( "CD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 3, "CD" ) );
			GetHashTable.Add( "CE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 4, "CE" ) );
			GetHashTable.Add( "CF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 5, "CF" ) );
			GetHashTable.Add( "CG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 6, "CG" ) );
			GetHashTable.Add( "CH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 2, SquareHeight * 7, "CH" ) );
			GetHashTable.Add( "DA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, 0, "DA" ) );
			GetHashTable.Add( "DB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight, "DB" ) );
			GetHashTable.Add( "DC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 2, "DC" ) );
			GetHashTable.Add( "DD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 3, "DD" ) );
			GetHashTable.Add( "DE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 4, "DE" ) );
			GetHashTable.Add( "DF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 5, "DF" ) );
			GetHashTable.Add( "DG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 6, "DG" ) );
			GetHashTable.Add( "DH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 3, SquareHeight * 7, "DH" ) );
			GetHashTable.Add( "EA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, 0, "EA" ) );
			GetHashTable.Add( "EB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight, "EB" ) );
			GetHashTable.Add( "EC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 2, "EC" ) );
			GetHashTable.Add( "ED", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 3, "ED" ) );
			GetHashTable.Add( "EE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 4, "EE" ) );
			GetHashTable.Add( "EF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 5, "EF" ) );
			GetHashTable.Add( "EG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 6, "EG" ) );
			GetHashTable.Add( "EH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 4, SquareHeight * 7, "EH" ) );
			GetHashTable.Add( "FA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, 0, "FA" ) );
			GetHashTable.Add( "FB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight, "FB" ) );
			GetHashTable.Add( "FC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 2, "FC" ) );
			GetHashTable.Add( "FD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 3, "FD" ) );
			GetHashTable.Add( "FE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 4, "FE" ) );
			GetHashTable.Add( "FF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 5, "FF" ) );
			GetHashTable.Add( "FG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 6, "FG" ) );
			GetHashTable.Add( "FH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 5, SquareHeight * 7, "FH" ) );
			GetHashTable.Add( "GA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, 0, "GA" ) );
			GetHashTable.Add( "GB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight, "GB" ) );
			GetHashTable.Add( "GC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 2, "GC" ) );
			GetHashTable.Add( "GD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 3, "GD" ) );
			GetHashTable.Add( "GE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 4, "GE" ) );
			GetHashTable.Add( "GF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 5, "GF" ) );
			GetHashTable.Add( "GG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 6, "GG" ) );
			GetHashTable.Add( "GH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 6, SquareHeight * 7, "GH" ) );
			GetHashTable.Add( "HA", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, 0, "HA" ) );
			GetHashTable.Add( "HB", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight, "HB" ) );
			GetHashTable.Add( "HC", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 2, "HC" ) );
			GetHashTable.Add( "HD", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 3, "HD" ) );
			GetHashTable.Add( "HE", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 4, "HE" ) );
			GetHashTable.Add( "HF", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 5, "HF" ) );
			GetHashTable.Add( "HG", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 6, "HG" ) );
			GetHashTable.Add( "HH", new DraughtsSquare( SquareWidth, SquareHeight, SquareWidth * 7, SquareHeight * 7, "HH" ) );

			DrawLegend( true );

			LegendColor = DraughtsLegendColor;

			SetBackGroundColor( lightColor, darkColor );
			SetHighlightColor( highlightColor );

			SetDisplayMode( "APPLICATION" );

			if( Designing() == true ) 
				return;

			ImplementDragDrop = true;

			Testing = true;

			bitLightPiece = new Bitmap( "Light.bmp" );
			bitLightKingPiece = new Bitmap( "LightKing.bmp" );
			bitDarkPiece = new Bitmap( "Dark.bmp" );
			bitDarkKingPiece = new Bitmap( "DarkKing.bmp" );
			bitLightNoDrop = new Bitmap( "LightNoDrop.bmp" );
			bitDarkNoDrop = new Bitmap( "DarkNoDrop.bmp" );
			bitLightDrop = new Bitmap( "LightDrop.bmp" );
			bitDarkDrop = new Bitmap( "DarkDrop.bmp" );
			bitLightKingDrop = new Bitmap( "LightKingDrop.bmp" );
			bitLightKingNoDrop = new Bitmap( "LightKingNoDrop.bmp" );
			bitDarkKingDrop = new Bitmap( "DarkKingDrop.bmp" );
			bitDarkKingNoDrop = new Bitmap( "DarkKingNoDrop.bmp" );

			bitLightPiece.MakeTransparent( Color.Black );
			bitLightKingPiece.MakeTransparent( Color.Black );
			bitDarkPiece.MakeTransparent( Color.Black );
			bitDarkKingPiece.MakeTransparent( Color.Black );
			bitLightNoDrop.MakeTransparent( Color.Black );
			bitDarkNoDrop.MakeTransparent( Color.Black );
			bitLightDrop.MakeTransparent( Color.Black );
			bitDarkDrop.MakeTransparent( Color.Black );
			bitLightKingDrop.MakeTransparent( Color.Black );
			bitLightKingNoDrop.MakeTransparent( Color.Black );
			bitDarkKingDrop.MakeTransparent( Color.Black );
			bitDarkKingNoDrop.MakeTransparent( Color.Black );

			DragDropImage = bitLightPiece;

			SetupSquares();

			bHasDropped = true;
			bDroppedOnOccupiedSquare = false;
			bInvalidSquareDrop = false;
			bStartDragDrop = false;
			bsStartSquare = null;
			bAllowDrop = false;
			bPlayerTakesPiece = false;
			strTakenPieceIdentifier = null;
			bCanStillTake = false;
			strTakingPieceIdentifier = null;
			nNumberOfMovesNoneTaken = 0;
			nNumberOfMovesWithoutTake = 20;
			bAllowComputerMove = false;
			game.InitializeGame();
		}
Esempio n. 4
0
		/// <summary>
		/// handle the player moving a piece with drag n drop
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnDragOver(object sender, System.Windows.Forms.DragEventArgs e)
		{
			if( ImplementDragDrop == true )
			{
				DraughtsSquare square = ( DraughtsSquare )GetSquareAt( e.X - this.Parent.Bounds.X - this.Bounds.X - LegendWidth, e.Y - this.Parent.Bounds.Y - this.Bounds.Y - 40 );


				if( bStartDragDrop == false )
				{
					if( square.IsOccupied == false )
						return;

					bStartDragDrop = true;
					bsStartSquare = square;

					if( square.PlayerIsOnSquare == false )
						return;
					
					if( DrawHighlight == true )
					{
						HighlightSquares( square );
					}
				}

				if( bsStartSquare == null )
					return;

				if( square != null && square.IsOccupied == false )
				{
					if( e.Data.GetDataPresent( DataFormats.Bitmap ) == true )
					{
						Cursor = Cursors.Hand;

						e.Effect = DragDropEffects.Copy;

						foreach( DictionaryEntry dicEnt in GetHashTable )
						{
							BasicSquare squareTemp = ( BasicSquare )dicEnt.Value;

							squareTemp.DrawDragDropImage = false;
						}

						square.DrawDragDropImage = true;

						
						if( PlayOnLightSquares == true )
						{
							if( PlayerIsLight == true )
							{
								PlayerLightMove( square );
							}
							else
							{
								PlayerDarkMove( square );
							}
						}
						else
						{
							if( PlayerIsLight == true )
							{
								PlayerLightMove( square );
							}
							else
							{
								PlayerDarkMove( square );
							}
						}


						Invalidate();
						Update();
					}
				}
				else if( square != null && square.IsOccupied == true )
				{
					if( e.Data.GetDataPresent( DataFormats.Bitmap ) == true )
					{
						Cursor = Cursors.Hand;

						e.Effect = DragDropEffects.Copy;

						foreach( DictionaryEntry dicEnt in GetHashTable )
						{
							BasicSquare squareTemp = ( BasicSquare )dicEnt.Value;

							squareTemp.DrawDragDropImage = false;
						}

						square.DrawDragDropImage = true;

						/// if the square contains a computer piece then 
						/// can't drop on it under any circumstances
						/// 

						if( square.OccupyingName == "COMPUTER" )
						{
							if( PlayerIsLight == true )
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitLightKingNoDrop;
								else
									square.DragDropImage = bitLightNoDrop;
							}
							else
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitDarkKingNoDrop;
								else
									square.DragDropImage = bitDarkNoDrop;
							}

							bAllowDrop = false;

							Invalidate();
							Update();

							return;
						}
						
						if( PlayerIsLight == true )
						{
							if( square.BackGroundColor == LightColor 
								&& square == bsStartSquare )
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitLightKingDrop;
								else
									square.DragDropImage = bitLightDrop;

								bAllowDrop = true;
							}
							else
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitLightKingNoDrop;
								else
									square.DragDropImage = bitLightNoDrop;

								bAllowDrop = false;
							}	
						}
						else 
						{
							if( square.BackGroundColor == DarkColor 
								&& square == bsStartSquare )
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitDarkKingDrop;
								else
									square.DragDropImage = bitDarkDrop;

								bAllowDrop = true;
							}
							else
							{
								if( bsStartSquare.IsKing == true )
									square.DragDropImage = bitDarkKingNoDrop;
								else
									square.DragDropImage = bitDarkNoDrop;
								
								bAllowDrop = false;
							}
						}

						square.IsValid = false;


						Invalidate();
						Update();
					}
				}
				else
				{
					if( square != null )
					{
						square.DrawDragDropImage = false;
					}

					bInvalidSquareDrop = true;
				}
			}
			else
			{
				Cursor = Cursors.Default;	
				bInvalidSquareDrop = true;
			}
		}
Esempio n. 5
0
		private void HighlightSquares( DraughtsSquare currentSquare )
		{
			bool bCanTake = false;

			if( PlayerIsLight == true )
			{
				BasicSquare square = GetSquareAboveLeft( currentSquare.Identifier );

				if( square != null && square.IsOccupied == true )
				{
					if( square.OccupyingName == "COMPUTER" )
					{
						BasicSquare squareTemp = GetSquareAboveLeft( square.Identifier );
						BasicSquare squareToMoveTo = null;

						if( squareTemp != null && squareTemp.IsOccupied == false )
						{
							squareTemp.DrawHighlight = true;
							bCanTake = true;

							bool bMultiSquares = true;

							/// check to see if it is more than a single jump
							/// 
							while( bMultiSquares == true )
							{
								bMultiSquares = false;

								squareToMoveTo = squareTemp;
								BasicSquare squareNext = GetSquareAboveLeft( squareTemp.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareAboveLeft( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}

								squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareAboveRight( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}
							}
						}
					}
				}

				square = GetSquareAboveRight( currentSquare.Identifier );

				if( square != null && square.IsOccupied == true )
				{
					if( square.OccupyingName == "COMPUTER" )
					{
						BasicSquare squareTemp = GetSquareAboveRight( square.Identifier );
						BasicSquare squareToMoveTo = null;

						if( squareTemp != null && squareTemp.IsOccupied == false )
						{
							squareTemp.DrawHighlight = true;
							bCanTake = true;

							bool bMultiSquares = true;

							/// check to see if it is more than a single jump
							/// 
							while( bMultiSquares == true )
							{
								bMultiSquares = false;
								squareToMoveTo = squareTemp;

								BasicSquare squareNext = GetSquareAboveLeft( squareTemp.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareAboveLeft( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}

								squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareAboveRight( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}
							}
						}
					}
				}

				/// _TODO the highlights for a player king piece here
				/// 

				if( currentSquare.IsKing == true )
				{
					square = GetSquareBelowRight( currentSquare.Identifier );

					if( square != null && square.IsOccupied == true )
					{
						if( square.OccupyingName == "COMPUTER" )
						{
							BasicSquare squareTemp = GetSquareBelowRight( square.Identifier );
							BasicSquare squareToMoveTo = null;

							if( squareTemp != null && squareTemp.IsOccupied == false )
							{
								squareTemp.DrawHighlight = true;
								bCanTake = true;

								bool bMultiSquares = true;

								/// check to see if it is more than a single jump
								/// 
								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}

								/// do this in two blocks or the temp square moves backwards and forwards
								/// 

								squareTemp = GetSquareBelowRight( square.Identifier );
								bMultiSquares = true;

								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}
							}
						}
					}

					square = GetSquareBelowLeft( currentSquare.Identifier );

					if( square != null && square.IsOccupied == true )
					{
						if( square.OccupyingName == "COMPUTER" )
						{
							BasicSquare squareTemp = GetSquareBelowLeft( square.Identifier );
							BasicSquare squareToMoveTo = null;

							if( squareTemp != null && squareTemp.IsOccupied == false )
							{
								squareTemp.DrawHighlight = true;
								bCanTake = true;

								bool bMultiSquares = true;

								/// check to see if it is more than a single jump
								/// 
								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}

								squareTemp = GetSquareBelowLeft( square.Identifier );
								bMultiSquares = true;

								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}
							}
						}
					}
				}

				if( bCanTake == false )
				{
					square = GetSquareAboveLeft( currentSquare.Identifier );

					if( square != null && square.IsOccupied == false )
					{
						square.DrawHighlight = true;
					}

					square = GetSquareAboveRight( currentSquare.Identifier );

					if( square != null && square.IsOccupied == false )
					{
						square.DrawHighlight = true;
					}

					if( currentSquare.IsKing == true )
					{
						square = GetSquareBelowRight( currentSquare.Identifier );

						if( square != null && square.IsOccupied == false )
						{
							square.DrawHighlight = true;
						}

						square = GetSquareBelowLeft( currentSquare.Identifier );

						if( square != null && square.IsOccupied == false )
						{
							if( bCanTake == false )
								square.DrawHighlight = true;
						}
					}

				}
			}
			else
			{
				BasicSquare square = GetSquareBelowLeft( currentSquare.Identifier );

				if( square != null && square.IsOccupied == true )
				{
					if( square.OccupyingName == "COMPUTER" )
					{
						BasicSquare squareTemp = GetSquareBelowLeft( square.Identifier );
						BasicSquare squareToMoveTo = null;

						if( squareTemp != null && squareTemp.IsOccupied == false )
						{
							squareTemp.DrawHighlight = true;
							bCanTake = true;

							bool bMultiSquares = true;

							/// check to see if it is more than a single jump
							/// 
							while( bMultiSquares == true )
							{
								bMultiSquares = false;

								squareToMoveTo = squareTemp;
								BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareBelowLeft( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}

								squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareBelowRight( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}
							}
						}
					}
				}

				square = GetSquareBelowRight( currentSquare.Identifier );

				if( square != null && square.IsOccupied == true )
				{
					if( square.OccupyingName == "COMPUTER" )
					{
						BasicSquare squareTemp = GetSquareBelowRight( square.Identifier );
						BasicSquare squareToMoveTo = null;

						if( squareTemp != null && squareTemp.IsOccupied == false )
						{
							squareTemp.DrawHighlight = true;
							bCanTake = true;

							bool bMultiSquares = true;

							/// check to see if it is more than a single jump
							/// 
							while( bMultiSquares == true )
							{
								bMultiSquares = false;
								squareToMoveTo = squareTemp;

								BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareBelowLeft( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}

								squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

								if( squareNext != null && squareNext.IsOccupied == true )
								{
									if( squareNext.OccupyingName == "COMPUTER" )
									{
										squareTemp = GetSquareBelowRight( squareNext.Identifier );

										if( squareTemp != null && squareTemp.IsOccupied == false )
										{
											squareTemp.DrawHighlight = true;
											bMultiSquares = true;
										}
									}
								}
							}
						}
					}
				}

				if( currentSquare.IsKing == true )
				{
					square = GetSquareAboveRight( currentSquare.Identifier );

					if( square != null && square.IsOccupied == true )
					{
						if( square.OccupyingName == "COMPUTER" )
						{
							BasicSquare squareTemp = GetSquareAboveRight( square.Identifier );
							BasicSquare squareToMoveTo = null;

							if( squareTemp != null && squareTemp.IsOccupied == false )
							{
								squareTemp.DrawHighlight = true;
								bCanTake = true;

								bool bMultiSquares = true;

								/// check to see if it is more than a single jump
								/// 
								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareAboveLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}

								squareTemp = GetSquareAboveRight( square.Identifier );
								bMultiSquares = true;

								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}								
							}
						}
					}

					square = GetSquareAboveLeft( currentSquare.Identifier );

					if( square != null && square.IsOccupied == true )
					{
						if( square.OccupyingName == "COMPUTER" )
						{
							BasicSquare squareTemp = GetSquareAboveLeft( square.Identifier );
							BasicSquare squareToMoveTo = null;

							if( squareTemp != null && squareTemp.IsOccupied == false )
							{
								squareTemp.DrawHighlight = true;
								bCanTake = true;

								bool bMultiSquares = true;

								/// check to see if it is more than a single jump
								/// 
								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareAboveLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareAboveRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareAboveRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}

								squareTemp = GetSquareAboveLeft( square.Identifier );
								bMultiSquares = true;

								while( bMultiSquares == true )
								{
									bMultiSquares = false;
									squareToMoveTo = squareTemp;

									BasicSquare squareNext = GetSquareBelowLeft( squareTemp.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowLeft( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}

									squareNext = GetSquareBelowRight( squareToMoveTo.Identifier );

									if( squareNext != null && squareNext.IsOccupied == true )
									{
										if( squareNext.OccupyingName == "COMPUTER" )
										{
											squareTemp = GetSquareBelowRight( squareNext.Identifier );

											if( squareTemp != null && squareTemp.IsOccupied == false )
											{
												squareTemp.DrawHighlight = true;
												bMultiSquares = true;
											}
										}
									}
								}

							}
						}
					}
			
				}

				if( bCanTake == false )
				{
					square = GetSquareBelowLeft( currentSquare.Identifier );

					if( square != null && square.IsOccupied == false )
					{
						square.DrawHighlight = true;
					}

					square = GetSquareBelowRight( currentSquare.Identifier );

					if( square != null && square.IsOccupied == false )
					{
						square.DrawHighlight = true;
					}

					if( currentSquare.IsKing == true )
					{
						square = GetSquareAboveRight( currentSquare.Identifier );

						if( square != null && square.IsOccupied == false )
						{
							square.DrawHighlight = true;
						}

						square = GetSquareAboveLeft( currentSquare.Identifier );

						if( square != null && square.IsOccupied == false )
						{
							square.DrawHighlight = true;
						}
					}

				}

			}
		}