Exemplo n.º 1
0
    /// <summary>
    /// Instantiates the given prefab on the given coordinate, only if its square is free
    /// <param name="coords">Coordinates suggested by the level requirements.
    /// Note that this must be converted to boards coordinates, since they may vary</param>
    /// </summary>
    public GameObject LocateElement(GameObject prefab, Coordinate levelCoords)
    {
        Coordinate           coords = levelCoords + boardOrigin;
        BoardSquareBehaviour square = GetBoardSquare(coords);

        if (square == null || !square.IsFree())
        {
            Debug.Log(String.Format(">>> Square at {0} is not free", coords.ToString()));
            return(null);
        }

        Vector3    coordsPosition = GetBoardSquare(coords).transform.position;
        GameObject elementObject  = Instantiate(prefab, coordsPosition, prefab.transform.rotation, transform);

        ElementBehaviour element = elementObject.GetComponent <ElementBehaviour>();

        if (element)
        {
            element.Location = coords;
        }

        square.SetElement(element);

        return(elementObject);
    }
Exemplo n.º 2
0
    public MovementResult MoveElement(ElementBehaviour element, Coordinate dest)
    {
        BoardSquareBehaviour square = GetBoardSquare(dest);

        if (square == null || !square.IsFree())
        {
            Debug.Log(">>> Could not move element from " + element.Location.ToString() + " to " + dest.ToString());
            return(MovementResult.Unaccomplished);
        }

        // Switch element's square
        BoardSquareBehaviour currentSquare = GetBoardSquare(element.Location);

        currentSquare.RemoveElement();
        square.SetElement(element);
        element.Location = dest;

        return(MovementResult.Success);
    }