예제 #1
0
파일: Knight.cs 프로젝트: Comingdonut/Chess
 public bool CheckSquare(ChessPiece[,] board, int[] end)
 {
     bool isValid = false;
     if (board[end[0], end[1]].GetType() == typeof(Space))
     {
         isValid = true;
     }
     else if (board[end[0], end[1]].Color != Color)
     {
         isValid = true;
     }
     return isValid;
 }
예제 #2
0
파일: Knight.cs 프로젝트: Comingdonut/Chess
 public bool IsAvailable(ChessPiece[,] board, int row, int column, int index)
 {
     bool canMove = true;
     if (board[row, column].Color == Color)
     {
         canMove = false;
     }
     if (this.canMove[index] == true)
     {
         this.canMove[index] = canMove;
     }
     return canMove;
 }
예제 #3
0
파일: Knight.cs 프로젝트: Comingdonut/Chess
 public bool CheckMovement(ChessPiece[,] board, int[] start, int[] end)
 {
     bool isValid = false;
     List<int[]> available = RestrictMovement(board, start);
     for (int x = 0; x < available.Count; ++x)
     {
         if (available[x][0] == end[0] && available[x][1] == end[1])
         {
             isValid = true;
         }
     }
     return isValid;
 }
예제 #4
0
파일: Print.cs 프로젝트: Comingdonut/Chess
 /// <summary>
 /// Prints out 24 array values before moving on to the next set of 24 values.
 /// </summary>
 /// <param name="boardSqaures">Represents a board. Required size for the 2-D array is 8 rows and 24 columns.</param>
 public void PrintBoard(ChessPiece[,] boardSqaures)
 {
     for (int x = 0; x < 8; ++x)
     {
         for (int y = 0; y < 8; y++)
         {
             if (x % 2 == 0)
             {
                 if (y % 2 == 0)
                 {
                     Console.BackgroundColor = ConsoleColor.DarkMagenta;
                 }
                 else
                 {
                     Console.BackgroundColor = ConsoleColor.DarkGreen;
                 }
             }
             else
             {
                 if (y % 2 == 0)
                 {
                     Console.BackgroundColor = ConsoleColor.DarkGreen;
                 }
                 else
                 {
                     Console.BackgroundColor = ConsoleColor.DarkMagenta;
                 }
             }
             if (boardSqaures[x, y].Color == 'l')
             {
                 Console.ForegroundColor = ConsoleColor.White;
             }
             else if(boardSqaures[x, y].Color == 'd')
             {
                 Console.ForegroundColor = ConsoleColor.Cyan;
             }
             Console.Write(" " + boardSqaures[x, y].Symbol + " ");
         }
         Console.WriteLine();
     }
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Gray;
 }
예제 #5
0
파일: Bishop.cs 프로젝트: Comingdonut/Chess
 public List<int[]> RestrictMovement(ChessPiece[,] board, int[] start)
 {
     List<int[]> available = new List<int[]>();
     bool isAvailable = false;
     for (int x = 1; x < 8; ++x)
     {
         if (start[0] + x < 8 && start[1] - x >= 0)//down Left
         {
             isAvailable = IsAvailable(board, start[0] + x, start[1] - x, 0);
             if (isAvailable == true)
             {
                 if (canMove[0] == true)
                 {
                     available.Add(new int[] { start[0] + x, start[1] - x });
                 }
             }
         }
         if (start[0] + x < 8 && start[1] + x < 8)//down right
         {
             isAvailable = IsAvailable(board, start[0] + x, start[1] + x, 1);
             if (isAvailable == true)
             {
                 if (canMove[1] == true)
                 {
                     available.Add(new int[] { start[0] + x, start[1] + x });
                 }
             }
         }
         if (start[0] - x >= 0 && start[1] - x >= 0)//up left
         {
             isAvailable = IsAvailable(board, start[0] - x, start[1] - x, 2);
             if (isAvailable == true)
             {
                 if (canMove[2] == true)
                 {
                     available.Add(new int[] { start[0] - x, start[1] - x });
                 }
             }
         }
         if (start[0] - x >= 0 && start[1] + x < 8)//up right
         {
             isAvailable = IsAvailable(board, start[0] - x, start[1] + x, 3);
             if (isAvailable == true)
             {
                 if (canMove[3] == true)
                 {
                     available.Add(new int[] { start[0] - x, start[1] + x });
                 }
             }
         }
     }
     return available;
 }
예제 #6
0
        private void Button_PromoteHandler(object sender, RoutedEventArgs e)
        {
            Button b = (Button)sender;
            if (b.Name == "Queen")
            {
                _promotion = 1;
            }
            else if (b.Name == "Bishop")
            {
                _promotion = 2;
            }
            else if (b.Name == "Rook")
            {
                _promotion = 3;
            }
            else if (b.Name == "Knight")
            {
                _promotion = 4;
            }

            if (_promotion == 1)
            {
                newPiece = new Queen(pawnColor);
            }
            else if (_promotion == 2)
            {
                newPiece = new Bishop(pawnColor);
            }
            else if (_promotion == 3)
            {
                newPiece = new Rook(pawnColor);
            }
            else if (_promotion == 4)
            {
                newPiece = new Knight(pawnColor);
            }

            if (newPiece != null)
            {
                BitmapImage source = new BitmapImage();
                source.BeginInit();
                source.UriSource = new Uri("Images/" + newPiece.ToString(), UriKind.RelativeOrAbsolute);
                source.EndInit();

                Image img = new Image();
                img.Source = source;

                ((Square)g.Children[((square[0] * 8) + square[1])]).Panel.Children.Clear();
                ((Square)g.Children[((square[0] * 8) + square[1])]).Panel.Children.Add(img);
                ((Square)g.Children[((square[0] * 8) + square[1])]).Pic = img;
                Board.Squares[square[0], square[1]].Piece = newPiece;
            }
            for (int x = 0; x < 5; ++x)
            {
                g2.Children[x].Visibility = Visibility.Hidden;
            }
            g.IsEnabled = true;
        }
예제 #7
0
파일: Pawn.cs 프로젝트: Comingdonut/Chess
        public List<int[]> RestrictMovement(ChessPiece[,] board, int[] start)
        {
            List<int[]> available = new List<int[]>();

            return available;
        }
예제 #8
0
파일: Space.cs 프로젝트: Comingdonut/Chess
 public bool IsAvailable(ChessPiece[,] board, int row, int column, int index)
 {
     return false;
 }
예제 #9
0
파일: Pawn.cs 프로젝트: Comingdonut/Chess
 public bool CheckMovement(ChessPiece[,] board, int[] start, int[] end)
 {
     ResetMovement();
     return false;
 }
예제 #10
0
파일: Pawn.cs 프로젝트: Comingdonut/Chess
 public bool CheckSquare(ChessPiece[,] board, int[] end)
 {
     return false;
 }
예제 #11
0
파일: King.cs 프로젝트: Comingdonut/Chess
 public List<int[]> RestrictMovement(ChessPiece[,] board, int[] start)
 {
     List<int[]> available = new List<int[]>();
     bool isAvailable = false;
     if (start[0] + 1 < 8)//down 1
     {
         isAvailable = IsAvailable(board, start[0] + 1, start[1], 0);
         if (isAvailable == true)
         {
             if(canMove[0] == true)
             {
                 available.Add(new int[] { start[0] + 1, start[1] });
             }
         }
     }
     if (start[0] + 1 < 8 && start[1] - 1 >= 0)//down Left 1
     {
         isAvailable = IsAvailable(board, start[0] + 1, start[1] - 1, 1);
         if (isAvailable == true)
         {
             if (canMove[1] == true)
             {
                 available.Add(new int[] { start[0] + 1, start[1] - 1 });
             }
         }
     }
     if (start[0] + 1 < 8 && start[1] + 1 < 8)//down right 1
     {
         isAvailable = IsAvailable(board, start[0] + 1, start[1] + 1, 2);
         if (isAvailable == true)
         {
             if (canMove[2] == true)
             {
                 available.Add(new int[] { start[0] + 1, start[1] + 1 });
             }
         }
     }
     if (start[1] + 1 < 8)//right 1
     {
         isAvailable = IsAvailable(board, start[0], start[1] + 1, 3);
         if (isAvailable == true)
         {
             if (canMove[3] == true)
             {
                 available.Add(new int[] { start[0], start[1] + 1 });
             }
         }
     }
     if (start[0] - 1 >= 0)//up 1
     {
         isAvailable = IsAvailable(board, start[0] - 1, start[1], 4);
         if (isAvailable == true)
         {
             if (canMove[4] == true)
             {
                 available.Add(new int[] { start[0] - 1, start[1] });
             }
         }
     }
     if (start[0] - 1  >= 0 && start[1] - 1 >= 0)//up left 1
     {
         isAvailable = IsAvailable(board, start[0] - 1, start[1] - 1, 5);
         if (isAvailable == true)
         {
             if (canMove[5] == true)
             {
                 available.Add(new int[] { start[0] - 1, start[1] - 1 });
             }
         }
     }
     if (start[0] - 1 >= 0 && start[1] + 1 < 8)//up right 1
     {
         isAvailable = IsAvailable(board, start[0] - 1, start[1] + 1, 6);
         if (isAvailable == true)
         {
             if (canMove[6] == true)
             {
                 available.Add(new int[] { start[0] - 1, start[1] + 1 });
             }
         }
     }
     if (start[1] - 1 >= 0)//left 1
     {
         isAvailable = IsAvailable(board, start[0], start[1] - 1, 7);
         if (isAvailable == true)
         {
             if (canMove[7] == true)
             {
                 available.Add(new int[] { start[0], start[1] - 1 });
             }
         }
     }
     return available;
 }
예제 #12
0
파일: Space.cs 프로젝트: Comingdonut/Chess
 public List<int[]> RestrictMovement(ChessPiece[,] board, int[] start)
 {
     return new List<int[]>();
 }
예제 #13
0
파일: Space.cs 프로젝트: Comingdonut/Chess
 public void MovePiece(ChessPiece[,] board, int[] start, int[] end)
 {
 }
예제 #14
0
파일: Knight.cs 프로젝트: Comingdonut/Chess
 public void MovePiece(ChessPiece[,] board, int[] start, int[] end)
 {
     board[end[0], end[1]] = board[start[0], start[1]];
     board[start[0], start[1]] = new Space();
 }
예제 #15
0
 /// <summary>
 /// Checks the parameter if it represents a board piece.
 /// If it does, then it sets _pieceHolder to a the board piece.
 /// </summary>
 /// <param name="piece">
 /// K = King
 /// Q = Queen
 /// B = Bishop
 /// N = Knight
 /// R = Rook
 /// P = Pawn
 /// </param>
 /// <returns>Returns the name of a board piece</returns>
 public string CheckPiece(string piece)
 {
     string name;
     switch (piece)
     {
         case "K":
             _pieceHolder = new King(' ');
             name = _pieceHolder.Piece;
             break;
         case "Q":
             _pieceHolder = new Queen(' ');
             name = _pieceHolder.Piece;
             break;
         case "B":
             _pieceHolder = new Bishop(' ');
             name = _pieceHolder.Piece;
             break;
         case "N":
             _pieceHolder = new Knight(' ');
             name = _pieceHolder.Piece;
             break;
         case "R":
             _pieceHolder = new Rook(' ');
             name = _pieceHolder.Piece;
             break;
         case "P":
             _pieceHolder = new Pawn(' ');
             name = _pieceHolder.Piece;
             break;
         default:
             Console.Error.WriteLine("Invalid Piece");
             name = null;
             break;
     }
     return name;
 }
예제 #16
0
파일: Knight.cs 프로젝트: Comingdonut/Chess
        public List<int[]> RestrictMovement(ChessPiece[,] board, int[] start)
        {
            List<int[]> available = new List<int[]>();

            if (start[0] - 2 >= 0 && start[1] - 1 >= 0)//up 2 left 1
            {
                available.Add(new int[] { start[0] - 2, start[1] - 1 });
            }
            if (start[0] - 2 >= 0 && start[1] + 1 < 8)//up 2 right 1
            {
                available.Add(new int[] { start[0] - 2, start[1] + 1 });
            }
            if (start[0] - 1 >= 0 && start[1] - 2 >= 0)//up 1 left 2
            {
                available.Add(new int[] { start[0] - 1, start[1] - 2 });
            }
            if (start[0] - 1 >= 0 && start[1] + 2 < 8)//up 1 right 2
            {
                available.Add(new int[] { start[0] - 1, start[1] + 2 });
            }
            if (start[0] + 2 < 8 && start[1] - 1 >= 0 )//down 2 Left 1
            {
                available.Add(new int[] { start[0] + 2, start[1] - 1 });
            }
            if (start[0] + 2 < 8 && start[1] + 1 < 8)//down 2 right 1
            {
                available.Add(new int[] { start[0] + 2, start[1] + 1 });
            }
            if (start[0] + 1 < 8 && start[1] - 2 >= 0)//down 1 Left 2
            {
                available.Add(new int[] { start[0] + 1, start[1] - 2 });
            }
            if (start[0] + 1 < 8 && start[1] + 2 < 8)//down 1 right 2
            {
                available.Add(new int[] { start[0] + 1, start[1] + 2 });
            }
            return available;
        }
예제 #17
0
 /// <summary>
 /// Checks the parameter if it represents a board piece.
 /// If it does, then it sets _pieceHolder to the board piece.
 /// </summary>
 /// <param name="piece">
 /// K = King
 /// Q = Queen
 /// B = Bishop
 /// N = Knight
 /// R = Rook
 /// P = Pawn
 /// </param>
 public void CheckPiece(string piece)
 {
     switch (piece)
     {
         case "K":
             _pieceHolder = new King();
             break;
         case "Q":
             _pieceHolder = new Queen();
             break;
         case "B":
             _pieceHolder = new Bishop();
             break;
         case "N":
             _pieceHolder = new Knight();
             break;
         case "R":
             _pieceHolder = new Rook();
             break;
         case "P":
             _pieceHolder = new Pawn();
             break;
         default:
             Console.Error.WriteLine("Invalid Piece");
             break;
     }
 }