Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Checkers for Pocket PC using a Recursive Min-Max Tree

, 19 Jun 2008 CPOL
Checkers/Draughts game for Pocket PC, using the recursive Min-Max tree to calculate moves, coded with C# over the .NET Compact Framework
checkers20_cab.zip
GamesPackage
GamesPackage.csdproj
GamesPackage.csdproj.user
GamesPackage.csproj.user
GamesPackage.resharperoptions
GamesPackage.suo
SoundPPCLibrary
SoundPPCLibrary.csdproj
SoundPPCLibrary.csdproj.user
SoundPPCLibrary.csproj.user
SoundPPCLibrary.resharperoptions
SoundPPCLibrary.suo
BoardEngine
BoardEngine.csdproj
BoardEngine.csdproj.user
BoardEngine.csproj.user
Checkers
001_select_checker_0.wav
002_select_destination_0.wav
003_player_move_0.wav
004_eat_a_player_0.wav
005_end_of_the_board_0.wav
006_game_over_0.wav
007_win_game_0.wav
CHECKER.ico
Checkers.csdproj
Checkers.csdproj.user
Checkers.csproj.user
Checkers.resharper.user
Checkers.resharperoptions
Checkers.suo
checkersico.ico
Thumbs.db
checkers_source.zip
Checkers.csdproj
Checkers.csdproj.user
Checkers.csproj.user
checkersico.ico
001_select_checker_0.wav
002_select_destination_0.wav
003_player_move_0.wav
004_eat_a_player_0.wav
005_end_of_the_board_0.wav
006_game_over_0.wav
007_win_game_0.wav
CHECKER.ico
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using BoardEngine;

namespace Checkers
{
	/// <summary>
	/// Summary description for BoardDrawe.
	/// </summary>
	public class BoardDrawer
	{
		

		private Pen SelectionPen ;
		protected Color _SelectionColor;
		public Color SelectionColor 
		{
			get 
			{
				return _SelectionColor;
			}
			set 
			{
				_SelectionColor = value;
			}
		}

		protected CheckersBoard _Board;

	
		public bool[,] Selected = new bool[8,8];

		protected ImageList _BlackImages;
		public ImageList BlackImages
		{
			get 
			{
				return _BlackImages;
			}
			set 
			{
				if (value!=null) _BlackImages = value;
			}
		}

		protected ImageList _WhiteImages;

		public ImageList WhiteImages
		{
			get 
			{
				return _WhiteImages;
			}
			set 
			{
				if (value!=null) _WhiteImages = value;
			}
		}

		protected Image _BlackCellImage;
		public Image BlackCellImage 
		{
			get 
			{
				return _BlackCellImage;
			}
			set 
			{
				if (value!=null) _BlackCellImage = value;
			}
		}

		

		protected Image _WhiteCellImage;

		public Image WhiteCellImage
		{
			get 
			{
				return _WhiteCellImage;
			}
			set 
			{
				if (value!=null) _WhiteCellImage = value;
			}
		}
		


		public BoardDrawer(CheckersBoard board) 
		{
			this._Board = board;
			this.SelectionColor = Color.Red;
			this.SelectionPen = new Pen(SelectionColor);
		}

		public virtual Image GetImageForPiece(CheckersPiece piece) 
		{
			ImageList list = WhiteImages;
			if (piece.Color == PieceColor.Black) list = BlackImages;

			if (piece is Pawn) return list.Images[0];
			else if (piece is Queen) return list.Images[1];
			else return null;
			
		}



		/// <summary>
		/// Paints the board over the current graphics
		/// </summary>
		/// <param name="g"></param>
		public virtual void PaintBoard(Graphics g,int startx,int starty,int width,int height) 
		{
			int cellWidth = width/8;
			int cellHeight = height/8;

            Rectangle originalRect = new Rectangle(0,0,32,32);
			bool White = false;
			Image cellimage = null;
			Image PieceImage = null;
						
			for(int i=0;i<8;i++)
			{				
				for(int j=0;j<8;j++)
				{
					//draw the cell
					if (White) cellimage = WhiteCellImage;
					else cellimage = BlackCellImage;
					g.DrawImage(cellimage,new Rectangle(cellWidth*i+startx,cellHeight*j+starty,cellWidth,cellHeight),originalRect,GraphicsUnit.Pixel);

					//now draw the piece
					CheckersPiece piece = (CheckersPiece)this._Board.GetPieceAt(i,j);
					if (piece!=null) //if there is a piece there
					{
						PieceImage = GetImageForPiece(piece);
						try 
						{
							Color transp = ((Bitmap)PieceImage).GetPixel (0,0);
							ImageAttributes attr = new ImageAttributes();
							attr.SetColorKey(transp, transp);
							//attr.SetColorKey(Color.FromArgb(248,248,240),Color.FromArgb(248,248,240));
							g.DrawImage(PieceImage,new Rectangle(cellWidth*i+startx,cellHeight*j+starty,cellWidth,cellHeight),0,0,32,32,GraphicsUnit.Pixel, attr);
						}
						catch(Exception ex) 
						{
							MessageBox.Show(ex.Message);
						}
					}

					if (Selected[i,j])
					{
						g.DrawRectangle(SelectionPen,cellWidth*i+startx+2,cellHeight*j+starty+2,cellWidth-4,cellHeight-4);
						g.DrawRectangle(SelectionPen,cellWidth*i+startx+1,cellHeight*j+starty+1,cellWidth-2,cellHeight-2);

					}

					White=!White;
				}
				White=!White;
			}
		}

		public void ClearSelection() 
		{
			for(int i=0;i<8;i++)
			{				
				for(int j=0;j<8;j++)
				{
					Selected[i,j] = false;
				}
			}
		}

	}
}

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)

Share

About the Author

Leonardo Paneque
Team Leader
United States United States
Leonardo loves to code with C# and thinks .NET platforms rocks.
He has a Master degree in Computer Sciences and likes to share code and ideas.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 20 Jun 2008
Article Copyright 2008 by Leonardo Paneque
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid