コード例 #1
0
ファイル: Knight.cs プロジェクト: JoeyAtkinson/PlayChess
 private void checkMove(ref List<Coor> coors, Coor coor)
 {
     if (hasPiece(coor))
     {
         if (!isFriendly(coor))
         {
             coors.Add(coor);
         }
     }
     else
     {
         coors.Add(coor);
     }
 }
コード例 #2
0
ファイル: MoveBlock.cs プロジェクト: JoeyAtkinson/PlayChess
        public MoveBlockOpption(Piece piece, Coor coor, Canvas canvas)
        {
            this._coor = coor;
            this._piece = piece;

            _rect.Width = BoardGame.INCREMENT;
            _rect.Height = BoardGame.INCREMENT;
            _rect.Opacity = .5;
            _rect.Fill = (SolidColorBrush)(new BrushConverter().ConvertFrom("#A82129"));

            canvas.Children.Add(_rect);

            Canvas.SetLeft(_rect, coor.x * BoardGame.INCREMENT);
            Canvas.SetTop(_rect, coor.y * BoardGame.INCREMENT);
        }
コード例 #3
0
ファイル: Pawn.cs プロジェクト: JoeyAtkinson/PlayChess
        public override void move(Coor coor)
        {
            BoardGame boardGame = BoardGame.getInstance();

            base.move(coor);
            hasMove = true;

            if (_side == Side.black)
            {
                if (coor.y == BoardGame.BOARDSIZE - 1)
                    boardGame.mainWindow.MainGrid.Children.Add(new PieceSelection(this));
            }
            else
            {
                if (coor.y == 0)
                    boardGame.mainWindow.MainGrid.Children.Add(new PieceSelection(this));
            }
        }
コード例 #4
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
        /// <summary> Using the current Piece location as origin, checks if a single spot has a piece and is unfriendly</summary>
        protected Boolean isSpotTaken(Direction direction, int NumberOfSpacesOut)
        {
            int xMod = angleMods[(int)direction, 0];
            int yMod = angleMods[(int)direction, 1];

            Coor currentCoor = getCurrentCoor();

            Coor coor = new Coor(currentCoor.x + NumberOfSpacesOut * xMod, currentCoor.y + NumberOfSpacesOut * yMod);

            if (!coor.isValid)
                return false;

            if (hasPiece(coor) && !isFriendly(coor))
                return true;
            else
                return false;
        }
コード例 #5
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
        protected Boolean isFriendly(Coor coor)
        {
            if (coor.isValid)
            {
                BoardGame boardGame = BoardGame.getInstance();

                Piece target = boardGame.board[coor.y, coor.x];

                if (target == null)
                    return true;

                if (this._side == target._side)
                    return true;
                else
                    return false;
            }
            else
            {
                return false;
            }
        }
コード例 #6
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
        protected Boolean hasPiece(Coor coor)
        {
            if (coor.isValid)
            {
                BoardGame boardGame = BoardGame.getInstance();

                Piece target = boardGame.board[coor.y, coor.x];

                if (target == null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }
        }
コード例 #7
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
        /// <summary>Checks a single angle starting from Piece location</summary>
        /// <param name="coors">Populates reference list with all found spots</param>
        /// <param name="NumberOfSpaces">How far out it checks</param>
        protected void checkAngle(ref List<Coor> coors, int NumberOfSpaces, Direction direction)
        {
            int xMod = angleMods[(int)direction, 0];
            int yMod = angleMods[(int)direction, 1];

            Coor currentCoor = getCurrentCoor();

            for (int i = 0; i < NumberOfSpaces; i++)
            {
                Coor coor = new Coor(currentCoor.x + (i + 1) * xMod, currentCoor.y + (i + 1) * yMod); /*+1 because zero is the piece itself*/

                if (!coor.isValid) /*So i dont add any unnessary movements*/
                    break;

                if (hasPiece(coor))
                {
                    if (!isFriendly(coor))
                        coors.Add(coor);

                    break;
                }
                coors.Add(coor);
            }
        }
コード例 #8
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
 /// <summary>Postions Piece on its current canvas</summary>
 public void setCoorOnCanvas(Coor coor)
 {
     Canvas.SetLeft(rect, coor.x * BoardGame.INCREMENT);
     Canvas.SetTop(rect, coor.y * BoardGame.INCREMENT);
 }
コード例 #9
0
ファイル: Piece.cs プロジェクト: JoeyAtkinson/PlayChess
        public virtual void move(Coor coor)
        {
            Coor currentLocation = getCurrentCoor();

            BoardGame boardGame = BoardGame.getInstance();

            Piece PieceInSpot = boardGame.board[coor.y, coor.x];

            if (PieceInSpot != null)
            {
                boardGame.gameBoard.Children.Remove(PieceInSpot.rect);
            }

            setCoorOnCanvas(coor);

            boardGame.board[currentLocation.y, currentLocation.x] = null;
            boardGame.board[coor.y, coor.x] = this;

            boardGame.moves.Children.Clear();
        }