public void SwapPieces(Move_new move)
    {
        GameObject[] objects = GameObject.FindGameObjectsWithTag("Highlight");
        foreach (GameObject o in objects)
        {
            Destroy(o);
        }

        Tile_new firstTile  = move.firstPosition;
        Tile_new secondTile = move.secondPosition;

        firstTile.CurrentPiece.MovePiece(new Vector3(-move.secondPosition.Position.x, 0, move.secondPosition.Position.y));

        if (secondTile.CurrentPiece != null)
        {
            if (secondTile.CurrentPiece.Type == Piece_new.pieceType.KING)
            {
                _kingDead = true;
            }
            Destroy(secondTile.CurrentPiece.gameObject);
        }


        secondTile.CurrentPiece          = move.pieceMoved;
        firstTile.CurrentPiece           = null;
        secondTile.CurrentPiece.position = secondTile.Position;
        secondTile.CurrentPiece.HasMoved = true;

        playerTurn = !playerTurn;
    }
Пример #2
0
    void _GetPawnMoves()
    {
        if (_piece.Player == Piece_new.playerColor.BLACK)
        {
            int limit = _piece.HasMoved ? 2 : 3;
            _GenerateMove(limit, new Vector2(0, 1));

            Vector2  diagLeft  = new Vector2(_position.x - 1, _position.y + 1);
            Vector2  diagRight = new Vector2(_position.x + 1, _position.y + 1);
            Tile_new dl        = null;
            Tile_new dr        = null;
            if (_IsOnBoard(diagLeft))
            {
                dl = _board.GetTileFromBoard(diagLeft);
            }
            if (_IsOnBoard(diagRight))
            {
                dr = _board.GetTileFromBoard(diagRight);
            }

            if (dl != null && _ContainsPiece(dl) && _IsEnemy(dl))
            {
                _CheckAndStoreMove(diagLeft);
            }
            if (dr != null && _ContainsPiece(dr) && _IsEnemy(dr))
            {
                _CheckAndStoreMove(diagRight);
            }
        }
        else
        {
            int limit = _piece.HasMoved ? 2 : 3;
            _GenerateMove(limit, new Vector2(0, -1));

            Vector2  diagLeft  = new Vector2(_position.x - 1, _position.y - 1);
            Vector2  diagRight = new Vector2(_position.x + 1, _position.y - 1);
            Tile_new dl        = null;
            Tile_new dr        = null;
            if (_IsOnBoard(diagLeft))
            {
                dl = _board.GetTileFromBoard(diagLeft);
            }
            if (_IsOnBoard(diagRight))
            {
                dr = _board.GetTileFromBoard(diagRight);
            }

            if (dl != null && _ContainsPiece(dl) && _IsEnemy(dl))
            {
                _CheckAndStoreMove(diagLeft);
            }
            if (dr != null && _ContainsPiece(dr) && _IsEnemy(dr))
            {
                _CheckAndStoreMove(diagRight);
            }
        }
    }
 public void SetupBoard()
 {
     for (int y = 0; y < 8; y++)
     {
         for (int x = 0; x < 8; x++)
         {
             _board[x, y] = new Tile_new(x, y);
         }
     }
 }
Пример #4
0
 bool _IsEnemy(Tile_new tile)
 {
     if (_player != tile.CurrentPiece.Player)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #5
0
    Move_new _CreateMove(Tile_new tile, Tile_new move)
    {
        Move_new tempMove = new Move_new();

        tempMove.firstPosition  = tile;
        tempMove.pieceMoved     = tile.CurrentPiece;
        tempMove.secondPosition = move;

        if (move.CurrentPiece != null)
        {
            tempMove.pieceKilled = move.CurrentPiece;
        }

        return(tempMove);
    }
    void _DoAIMove(Move_new move)
    {
        Tile_new firstPosition  = move.firstPosition;
        Tile_new secondPosition = move.secondPosition;

        if (secondPosition.CurrentPiece && secondPosition.CurrentPiece.Type == Piece_new.pieceType.KING)
        {
            SwapPieces(move);
            _kingDead = true;
        }
        else
        {
            SwapPieces(move);
        }
    }
Пример #7
0
    bool _ContainsPiece(Tile_new tile)
    {
        if (!_IsOnBoard(tile.Position))
        {
            return(false);
        }

        if (tile.CurrentPiece != null)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #8
0
    void _UndoFakeMove()
    {
        Move_new  tempMove    = moveStack.Pop();
        Tile_new  movedTo     = tempMove.secondPosition;
        Tile_new  movedFrom   = tempMove.firstPosition;
        Piece_new pieceKilled = tempMove.pieceKilled;
        Piece_new pieceMoved  = tempMove.pieceMoved;

        movedFrom.CurrentPiece = movedTo.CurrentPiece;

        if (pieceKilled != null)
        {
            movedTo.CurrentPiece = pieceKilled;
        }
        else
        {
            movedTo.CurrentPiece = null;
        }
    }
Пример #9
0
 void _DoFakeMove(Tile_new currentTile, Tile_new targetTile)
 {
     targetTile.SwapFakePieces(currentTile.CurrentPiece);
     currentTile.CurrentPiece = null;
 }