示例#1
0
 private void checkMove(ref List<Coor> coors, Coor coor)
 {
     if (hasPiece(coor))
     {
         if (!isFriendly(coor))
         {
             coors.Add(coor);
         }
     }
     else
     {
         coors.Add(coor);
     }
 }
示例#2
0
        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
        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
        /// <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
        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
        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
        /// <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
 /// <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
        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();
        }