Exemplo n.º 1
0
    public void Select(GameObject obj)
    {
        if (obj == null)
        {
            return;
        }
        if (SelectedObject == obj.transform.root.gameObject)
        {
            ClearSelection();
            return;
        }
        if (SelectedObject != null)
        {
            int[] ObCoord      = TileOps.GetCoordFromVector(obj.transform.root.gameObject.transform.position, ActiveBoard);
            Tile  objTile      = ActiveBoard.board.Tiles[ObCoord[0], ObCoord[1]];
            int[] selCoord     = TileOps.GetCoordFromVector(SelectedObject.transform.position, ActiveBoard);
            Tile  selectedTile = ActiveBoard.board.Tiles[selCoord[0], selCoord[1]];
            if (objTile.TrackerType == 2 || objTile.TrackerType == 3)
            {
                MovePiece(ObCoord, objTile, selectedTile);
                return;
            }
            else
            {
                ClearSelection();
            }
        }
        SelectedObject = obj.transform.root.gameObject;
        int[]   Coord = TileOps.GetCoordFromVector(SelectedObject.transform.position, ActiveBoard);
        Vector3 pos   = SelectedObject.transform.position;

        FindPossibleMoves(Coord[0], Coord[1]);
    }
Exemplo n.º 2
0
    private void MovePiece(int[] VictimCoord, Tile Victim, Tile Attacker)
    {
        BoardSO myboard = ActiveBoard.board;

        Attacker.Occupied.PieceObj.transform.position = Victim.TileObj.transform.position;
        int[] AttackerCoord = TileOps.GetCoordFromVector(Attacker.TileObj.transform.position, ActiveBoard);
        if (Victim.Occupied != null)
        {
            Destroy(Victim.Occupied.PieceObj);
        }
        Victim.Occupied = Attacker.Occupied;
        myboard.Pieces[VictimCoord[0], VictimCoord[1]]     = Attacker.Occupied;
        myboard.Pieces[AttackerCoord[0], AttackerCoord[1]] = null;
        Attacker.Occupied = null;

        int Facing = myboard.Pieces[VictimCoord[0], VictimCoord[1]].Facing;

        int X1 = AttackerCoord[0];
        int Y1 = AttackerCoord[1];
        int X2 = VictimCoord[0];
        int Y2 = VictimCoord[1];

        if (Y2 > Y1 && X2 == X1)
        {
            Facing = 0;                      // Moved North
        }
        if (Y2 < Y1 && X2 == X1)
        {
            Facing = 4;                      // Moved South
        }
        if (Y2 == Y1 && X2 > X1)
        {
            Facing = 2;                      // Moved East
        }
        if (Y2 == Y1 && X2 < X1)
        {
            Facing = 6;                      // Moved West
        }
        if (Y2 > Y1 && X2 > X1)
        {
            Facing = 1;                     // Moved North East
        }
        if (Y2 > Y1 && X2 < X1)
        {
            Facing = 7;                     // Moved North West
        }
        if (Y2 < Y1 && X2 > X1)
        {
            Facing = 3;                     // Moved South East
        }
        if (Y2 < Y1 && X2 < X1)
        {
            Facing = 5;                     // Moved South West
        }
        myboard.Pieces[VictimCoord[0], VictimCoord[1]].Facing = Facing;
        Destroy(Victim.Occupied.PieceObj);

        GameObject[] PieceToSpawn = new GameObject[8];
        if (Victim.Occupied.PieceType == "Pawn")
        {
            PieceToSpawn = board.Pawn;
        }
        if (Victim.Occupied.PieceType == "Queen")
        {
            PieceToSpawn = board.Queen;
        }
        if (Victim.Occupied.PieceType == "Bishop")
        {
            PieceToSpawn = board.Bishop;
        }
        if (Victim.Occupied.PieceType == "Rook")
        {
            PieceToSpawn = board.Rook;
        }
        if (Victim.Occupied.PieceType == "King")
        {
            PieceToSpawn = board.King;
        }
        if (Victim.Occupied.PieceType == "Knight")
        {
            PieceToSpawn = board.Knight;
        }

        GameObject tempPiece = Instantiate(PieceToSpawn[Build.SetDirection(board.currentView, Victim.Occupied.Facing)], Victim.TileObj.transform.position, Quaternion.identity);

        Victim.Occupied.PieceObj = tempPiece;
        Build.SetPieceColor(tempPiece, Victim.Occupied.PlayerColor, ActiveBoard);
        ClearSelection();
        return;
    }