Exemplo n.º 1
0
        public static void PrintChessBoard(ChessBoard chessBoard, ChessPosition origin)
        {
            Console.Clear();

            for (int l = 0; l < ChessBoard.Lines; l++)
            {
                PrintChessBoardVerticalLabel(l);

                for (int c = 0; c < ChessBoard.Columns; c++)
                {
                    var currentPosition = new Position(l, c);
                    bool[,] possibleMovements = chessBoard.GetPiece(origin.ToPosition()).PossibleMovements();

                    if (possibleMovements[l, c])
                    {
                        PrintChessBoardPiece(chessBoard.GetPiece(currentPosition), true);
                    }
                    else
                    {
                        PrintChessBoardPiece(chessBoard.GetPiece(currentPosition));
                    }
                }
                Console.WriteLine();
            }

            PrintChessBoardHorizontalLabel();

            Console.Write("\n\n");
        }
Exemplo n.º 2
0
 public ChessPiece(kSides side, kPieceTypes pieceType, ChessPosition position)
 {
     this.side = side;
     this.pieceType = pieceType;
     this.isActive = true;
     this.isSelected = false;
     this.position = position;
     this.initTexture();
 }
Exemplo n.º 3
0
 public ChessPiece(kSides side, kPieceTypes pieceType, ChessPosition position)
 {
     this.side       = side;
     this.pieceType  = pieceType;
     this.isActive   = true;
     this.isSelected = false;
     this.position   = position;
     this.initTexture();
 }
Exemplo n.º 4
0
        public void HandleMouseClick(Vector2 mousePosition)
        {
            //get the previously selected piece!
            ChessPiece selectedPiece = GetSelectedPiece();

            if (selectedPiece != null)
            {
                //no need to keep it selected any more. either it will be moved, or unselected
                selectedPiece.IsSelected = false;
            }

            char row    = 'A';
            int  column = 1;

            if (mousePosition.X < 25 || mousePosition.X > (float)(25 + 31.5 * 8) ||
                mousePosition.Y > 275 || mousePosition.Y < (float)(275 - 31.5 * 8))
            {
                Console.WriteLine("Out of bounds!!!!");
                return;
            }

            #region get row and column
            //get the row
            int difference = (int)((mousePosition.X - 25) / 31.5);
            switch (difference)
            {
            case 0:
                row = 'A';
                break;

            case 1:
                row = 'B';
                break;

            case 2:
                row = 'C';
                break;

            case 3:
                row = 'D';
                break;

            case 4:
                row = 'E';
                break;

            case 5:
                row = 'F';
                break;

            case 6:
                row = 'G';
                break;

            case 7:
                row = 'H';
                break;
            }
            //get the column
            column = (int)((275 - mousePosition.Y) / 31.5) + 1;
            #endregion

            ChessPosition mouseBoardPosition = new ChessPosition(row, column);

            if (selectedPiece != null && ChessUtils.IsMoveCompatible(selectedPiece, mouseBoardPosition))
            {
                selectedPiece.MovePiece(mouseBoardPosition);
            }
            else
            {
                foreach (kSides side in sides.Keys)
                {
                    foreach (ChessPiece piece in sides[side])
                    {
                        if (piece.Position == mouseBoardPosition)
                        {
                            piece.IsSelected = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void MovePiece(ChessPosition newPosition)
 {
     this.position = newPosition;
 }
Exemplo n.º 6
0
 //TODO
 public static bool IsMoveCompatible(ChessPiece piece, ChessPosition position)
 {
     return true;
 }
Exemplo n.º 7
0
 //TODO
 public static bool IsMoveCompatible(ChessPiece piece, ChessPosition position)
 {
     return(true);
 }
Exemplo n.º 8
0
        public void HandleMouseClick(Vector2 mousePosition)
        {
            //get the previously selected piece!
            ChessPiece selectedPiece = GetSelectedPiece();
            
            if (selectedPiece != null)
                //no need to keep it selected any more. either it will be moved, or unselected
                selectedPiece.IsSelected = false;

            char row = 'A';
            int column = 1;

            if (mousePosition.X < 25 || mousePosition.X > (float)(25 + 31.5 * 8) ||
                mousePosition.Y > 275 || mousePosition.Y < (float)(275 - 31.5 * 8))
            {
                Console.WriteLine("Out of bounds!!!!");
                return;
            }

            #region get row and column
            //get the row
            int difference = (int)((mousePosition.X - 25) / 31.5);
            switch (difference)
            {
                case 0:
                    row = 'A';
                    break;
                case 1:
                    row = 'B';
                    break;
                case 2:
                    row = 'C';
                    break;
                case 3:
                    row = 'D';
                    break;
                case 4:
                    row = 'E';
                    break;
                case 5:
                    row = 'F';
                    break;
                case 6:
                    row = 'G';
                    break;
                case 7:
                    row = 'H';
                    break;
            }
            //get the column
            column = (int)((275-mousePosition.Y) / 31.5) + 1;
            #endregion

            ChessPosition mouseBoardPosition = new ChessPosition(row, column);

            if (selectedPiece != null && ChessUtils.IsMoveCompatible(selectedPiece, mouseBoardPosition))
            {
                selectedPiece.MovePiece(mouseBoardPosition);
            }
            else
            {
                foreach (kSides side in sides.Keys)
                {
                    foreach (ChessPiece piece in sides[side])
                    {
                        if (piece.Position == mouseBoardPosition)
                        {
                            piece.IsSelected = true;
                        }
                    }
                }
            }
            
        }
Exemplo n.º 9
0
 public void MovePiece(ChessPosition newPosition)
 {
     this.position = newPosition;
 }