Chess Piece

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C:\Users\ttt\Downloads\chess game\chess game\ChessPiece.

cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace chess_game
9 {
10 public enum PieceColor
11 {
12 White, Black
13 }
14
15 public enum PieceType
16 {
17 Pawn, Rook, Knight, Bishop, Queen, King
18 }
19
20 public enum MoveType
21 {
22 regular, Capture, Enpassant, Castling, Promotion
23 }
24
25 //enum is used to assign constant names to a group.
26 //for the Piece Color, there only two colors exist, white and black
27 //for the Piece Type, there are 6 types, include pawn, rook, knight,
bishop,queen and king
28 //for the move type, I split them into 5 categories:
29 //regular just mean regular move
30 //capture, enpassant, castling and promotion
31
32 internal class ChessPiece
33 {
34 public PieceColor Color { get; set; } //the property holds the
color of the chess piece (either white or black)
35 public PieceType Type { get; set; }//the property holds the type
of the chess piece (include pawn, rook, etc)
36
37 public ChessPiece() //the default constructor
38 {
39 Color = PieceColor.White;
40 Type = PieceType.Pawn;
41 //initially the piece as a white pawn with no movement
42 //the default initialization is done to provide default
valures for a newly created ChessPiece object
43 }
44
45 public ChessPiece(PieceColor color, PieceType type)
46 {
47 Color = color;
48 Type = type;
49 HasMoved = false;
C:\Users\ttt\Downloads\chess game\chess game\ChessPiece.cs 2
50 }
51 //this parameterized constructor allow to create a chess piece
with a specified color and type
52 //HasMoved is initialized as false.
53
54 public bool HasMoved { get; set; } //indicate whether the chess
piece has moved during the game
55
56 public int Row { get; set; }
57 public int Column { get; set; }
58 // these properties store the current row and column position of
the chess piece on the board
59 }
60
61 }
62

You might also like