Exemplo n.º 1
0
        /// <summary>
        /// Handles the player's input for choosing which piece to move.
        /// </summary>
        public static void HandleChoice()
        {
            if(SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                Grid grid = MouseToGrid ();
                if (grid.Piece == null)
                {
                    return;
                }

                if (_state == GameState.WhiteChoose)
                {
                    if (grid.Piece.Player == "W")
                    {
                        _currentPiece = grid.Piece;
                        _state = GameState.WhiteMove;
                        return;
                    }
                }
                else
                {
                    if (grid.Piece.Player == "B")
                    {
                        _currentPiece = grid.Piece;
                        _state = GameState.BlackMove;
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the player's input for moving the chosen piece.
        /// </summary>
        public static void HandleMovement()
        {
            _board.HighlightPath (_currentPiece);
            _currentPiece.IsHighlighted = true;

            if (SwinGame.MouseClicked (MouseButton.LeftButton))
            {
                Grid grid = MouseToGrid ();
                string result = _currentPiece.MovePiece (grid, _board);

                if (result == null)
                {
                    if (_state == GameState.WhiteMove)
                    {
                        _board.RemovePathHighLight ();
                        _currentPiece.IsHighlighted = false;
                        _currentPiece = null;
                        _state = GameState.BlackChoose;
                        return;
                    }
                    else
                    {
                        _board.RemovePathHighLight ();
                        _currentPiece.IsHighlighted = false;
                        _currentPiece = null;
                        _state = GameState.WhiteChoose;
                        return;
                    }
                }
            }

            //Removes piece selection and returns to the Choosing phase
            if (SwinGame.MouseClicked (MouseButton.RightButton))
            {
                if (_state == GameState.WhiteMove)
                {
                    _board.RemovePathHighLight ();
                    _currentPiece.IsHighlighted = false;
                    _currentPiece = null;
                    _state = GameState.WhiteChoose;
                    return;
                }
                else
                {
                    _board.RemovePathHighLight ();
                    _currentPiece.IsHighlighted = false;
                    _currentPiece = null;
                    _state = GameState.BlackChoose;
                    return;
                }
            }
        }
Exemplo n.º 3
0
 //TODO
 public static bool IsMoveCompatible(ChessPiece piece, ChessPosition position)
 {
     return true;
 }
Exemplo n.º 4
0
        /// <summary>
        /// identifies squares between a king and the piece that has it in check that would block "check"
        /// </summary>
        /// <returns></returns>
        List<Point> canBlockCheck_IdentifyBlockingSquares(List<Point> allAllyMoves, Point kingLocation, ChessPiece checkPiece)
        {
            List<Point> returnList = new List<Point>();
            int directionVar = 0;
            Point tempPoint = checkPiece.pieceBoardLocation;

            // check piece type for the below pieces
            /*
                pieces who's "check" cannot be "blocked":
                -knights
                -pawns
            */

            // compare piece location that has king in check and king location
            Point checkerLocation = checkPiece.pieceBoardLocation;

            // determine the direction check is coming from I.E. "diagonal up left" or just "right" (direction is from the perspective of piece putting king in check)

                // check up
            if(checkerLocation.Y == kingLocation.Y && checkerLocation.X > kingLocation.X)
            {
                directionVar = 0;
            }

            // check up diag right
            else if (checkerLocation.Y < kingLocation.Y && checkerLocation.X > kingLocation.X)
            {
                directionVar = 1;
            }

            // check right
            else if (checkerLocation.Y < kingLocation.Y && checkerLocation.X == kingLocation.X)
            {
                directionVar = 2;
            }

            // check down diag right
            else if (checkerLocation.Y < kingLocation.Y && checkerLocation.X < kingLocation.X)
            {
                directionVar = 3;
            }

            // check down
            else if (checkerLocation.Y == kingLocation.Y && checkerLocation.X < kingLocation.X)
            {
                directionVar = 4;
            }

            // check down diag left
            else if (checkerLocation.Y > kingLocation.Y && checkerLocation.X < kingLocation.X)
            {
                directionVar = 5;
            }

            // check left
            else if (checkerLocation.Y > kingLocation.Y && checkerLocation.X == kingLocation.X)
            {
                directionVar = 6;
            }

            // check up diag left
            else if (checkerLocation.Y > kingLocation.Y && checkerLocation.X > kingLocation.X)
            {
                directionVar = 7;
            }

            // count from piece that has king in check back to the king

            while(tempPoint != kingLocation)
            {
                // pass in the directionVar to determine which direction we count back to kingpiece
                switch(directionVar)
                {
                    // up
                    case 0:
                        tempPoint.X -= 1;
                        break;
                    // up diag right
                    case 1:
                        tempPoint.X -= 1;
                        tempPoint.Y += 1;
                        break;
                    // right
                    case 2:
                        tempPoint.Y += 1;
                        break;
                    // down diag right
                    case 3:
                        tempPoint.X += 1;
                        tempPoint.Y += 1;
                        break;
                    // down
                    case 4:
                        tempPoint.X += 1;
                        break;
                    // down diag left
                    case 5:
                        tempPoint.X += 1;
                        tempPoint.Y -= 1;
                        break;
                    // left
                    case 6:
                        tempPoint.Y -= 1;
                        break;
                    // up diag left
                    case 7:
                        tempPoint.X -= 1;
                        tempPoint.Y -= 1;
                        break;
                }
                // add the squares in between to a list and return them
                returnList.Add(tempPoint);
            }

            return returnList;
        }
Exemplo n.º 5
0
        public void placePiece(int col, int row, ChessPiece chessPiece)
        {
            // if the chesspiece is null don't do anything
            //if (chessPiece == null)
            //{
            //    return;
            //}

            // set square's image box = chessPiece's image
            chessboardSquareArray[col, row].Image = chessPiece.chesspieceImage;

            //center image in picturebox
            chessboardSquareArray[col, row].SizeMode = PictureBoxSizeMode.CenterImage;

            // set the piece's board location property to the square it is being placed
            chessPiece.pieceBoardLocation = new Point(col, row);

            //set Square's chessPiece property to the passed in chessPiece
            chessboardSquareArray[col, row].squareChessPiece = chessPiece;
        }
Exemplo n.º 6
0
 public void clear()
 {
     Piece = null;
 }
Exemplo n.º 7
0
 //TODO
 public static bool IsMoveCompatible(ChessPiece piece, ChessPosition position)
 {
     return(true);
 }
Exemplo n.º 8
0
 public BoardSquare(SquareColor color)
 {
     Color = color;
     Piece = null;
 }
Exemplo n.º 9
0
 public BoardSquare(SquareColor color, ref ChessPiece piece)
 {
     Color = color;
     Piece = piece;
 }
Exemplo n.º 10
0
 public void SetBoardPiece(int row, int col, ChessPiece piece)
 {
     board[row, col] = piece;
 }
Exemplo n.º 11
0
 public void addPiece(ChessPiece piece, columns column, int linha)
 {
     board[linha - 1, int.Parse(column.ToString())].Piece = piece;
 }
Exemplo n.º 12
0
        public void SelectTile(int row, int col)
        {
            var piece = GetPiece(row, col);

            selectedPiece = piece;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Highlights the path possible for a chess piece.
 /// </summary>
 /// <param name="piece">The chess piece whose path needs to be highlighted</param>
 public void HighlightPath(ChessPiece piece)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (piece.CheckMovementRule(_grids[i,j], this))
                 _grids [i, j].IsHighlighted = true;
         }
     }
 }
Exemplo n.º 14
0
 public ChessSquare(ChessPiece p, int row, int column)
 {
     m_piece  = p;
     m_row    = row;
     m_column = column;
 }
Exemplo n.º 15
0
 public ChessSquare(ChessPiece p)
 {
     m_piece = p;
 }
Exemplo n.º 16
0
 public void SetChessPiece(ChessPiece p)
 {
     m_piece = p;
 }