Exemplo n.º 1
0
 protected virtual void OnDestroy()
 {
     if (Instance == this)
     {
         Instance = null;
     }
 }
Exemplo n.º 2
0
    //Gets a unit from a space on the grid without dealing with the tile.
    public static Unit GetUnitFromGrid(this GridCS GridScript, Vector2 Position, int LayerNumber)
    {
        Tile ThisTile = GetTile(GridScript, Position, LayerNumber);
        Unit ThisUnit = GetUnitFromTile(ThisTile);

        return(ThisUnit);
    }
Exemplo n.º 3
0
    //Erases a particular type of ability within range of the desired position.
    public static void EraseRange(this GridCS GridScript, Vector2 Position, Tile.OverlayType DesiredErase, int MaxRange, int LayerNumber)
    {
        int MinPosX = ((int)Position.x) - MaxRange;
        int MinPosZ = ((int)Position.y) - MaxRange;

        for (int thisPositionX = 0; thisPositionX <= 2 * MaxRange + 1; thisPositionX++)
        {
            for (int thisPositionZ = 0; thisPositionZ <= 2 * MaxRange + 1; thisPositionZ++)
            {
                for (int layer = 0; layer <= GridCS.Instance.grid.GetLength(2) - 1; layer++)
                {
                    Vector2 TileLocation = new Vector2(MinPosX + thisPositionX, MinPosZ + thisPositionZ);
                    if (CheckIfRangeIsInBounds(GridScript, TileLocation, layer))
                    {
                        Tile ThisTile = GetTile(GridScript, TileLocation, layer);
                        if (ThisTile != null)
                        {
                            if (ThisTile.TileSelectionType == DesiredErase)
                            {
                                ThisTile.TileSelectionType = Tile.OverlayType.Unselected;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
 void Start()
 {
     //Find and assign script variables
     pauseMenu   = gameObject.GetComponent <GUIPauseMenu> ();
     optionsMenu = gameObject.GetComponent <GUIOptionsMenu> ();
     gridScript  = (GameObject.Find("Grid Controller")).GetComponent <GridCS> ();
     gridScript.CreateGrid();
     //Tell the grid to spawn
     //GridCS.Instance.CreateGrid ();
     //Set the currently loaded layer to the one designated by the grid script
     LayerSwitcher.Instance.CurrentLayer = GridCS.coreLayer;
     for (int layer = 0; layer <= GridCS.layerCount; layer++)
     {
         if (layer != GridCS.coreLayer)
         {
             LayerSwitcher.Instance.HideLayer(layer);
         }
     }
     //Go and find the main camera
     MainCamera = GameObject.Find("Main Camera").GetComponent <Camera> ();
     //Assign states, enter into the Insert phase
     turnState = TurnStates.InsertPhase;
     menuState = MenuStates.NullState;
     _EnterInsertPhase();
     //Put the Layer Switcher button into the main GUI
     guiFunction += LayerSwitcher.Instance.GUIFunction;
 }
Exemplo n.º 5
0
 public static void MoveRangeNext(this GridCS GridScript, Tile ThisTile, int MoveValue, int LayerNumber)
 {
     if (ThisTile.LoadedUnitScript == null)
     {
         ThisTile.TileSelectionType = Tile.OverlayType.MoveAvailable;
         MoveRangeAdvance(GridScript, ThisTile, MoveValue - 1, LayerNumber);
     }
 }
Exemplo n.º 6
0
 void Awake()
 {
     Instance             = this;
     UnitChoiceScript     = this.GetComponent <UnitChoice> ();
     Player1Script        = GameObject.Find("Player1(Clone)").GetComponent <Player> ();
     Player2Script        = GameObject.Find("Player2(Clone)").GetComponent <Player> ();
     gameControllerScript = gameObject.GetComponent <GameManager> ();
     GameController       = GameObject.Find("GameControl");
     gridScript           = (GameObject.Find("Grid Controller")).GetComponent <GridCS> ();
 }
Exemplo n.º 7
0
    //Calculates if a position is inside of the grid, returns a boolean.
    public static bool CheckIfRangeIsInBounds(this GridCS GridScript, Vector2 Position, int LayerNumber)
    {
        bool IsInBounds;

        if (Position.x >= 0 && Position.x < GridCS.GRIDSIZEX && Position.y >= 0 && Position.y < GridCS.GRIDSIZEZ)
        {
            IsInBounds = true;
        }
        else
        {
            IsInBounds = false;
        }
        return(IsInBounds);
    }
Exemplo n.º 8
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////                 *work on making this only call after move has been resolved*                 /////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Puts a unit in a place on the grid, selects that place.
    public static void PlaceUnitInGrid(this GridCS GridScript, Unit ThisUnit, Vector2 InitiatorPosition, int InitialLayerNumber, Vector2 TargetPosition, int TargetLayerNumber)
    {
        Tile ThisTile = GetTile(GridScript, InitiatorPosition, InitialLayerNumber);

        ThisTile.prevLoadedUnitScript = ThisUnit;
        ThisTile.LoadedUnitScript     = null;
        ThisTile = GetTile(GridScript, TargetPosition, TargetLayerNumber);
        ThisTile.LoadedUnitScript       = ThisUnit;
        ThisTile.LoadedUnitScript.layer = (int)ThisTile.layerNumber.x;
        ThisUnit.transform.Translate(new Vector3(TargetPosition.x - InitiatorPosition.x, ThisTile.transform.position.y + Tile.UNITLOADDISTANCE - ThisUnit.transform.position.y, TargetPosition.y - InitiatorPosition.y), Space.World);
        GameObject      GameController = GameObject.Find("GameControl");
        CursorSelection Cursor         = GameController.GetComponent <CursorSelection> ();

        Cursor.selectedTile = ThisTile;
    }
Exemplo n.º 9
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Finds all enemies in a circular range of a space, sets the tiles to be selectable in the desired way.
    public static void CalculateCircularRange(this GridCS GridScript, Vector2 Position, Tile.OverlayType DesiredOverlay, int MinRange, int MaxRange, GridCS.PlayerNumber CurrentPlayer, bool FindEnemies, bool findAllies, bool findEmptyTiles, int LayerNumber)
    {
        int MinPosX = ((int)Position.x) - MaxRange;
        int MinPosZ = ((int)Position.y) - MaxRange;

        for (int thisPositionX = 0; thisPositionX <= 2 * MaxRange + 1; thisPositionX++)
        {
            for (int thisPositionZ = 0; thisPositionZ <= 2 * MaxRange + 1; thisPositionZ++)
            {
                Vector2 ThisPosition = new Vector2(MinPosX + thisPositionX, MinPosZ + thisPositionZ);
                double  hypotenuse   = CalculateTwoDiminsionalDistance(Position, ThisPosition);
                if (hypotenuse <= MaxRange && hypotenuse >= MinRange)
                {
                    if (CheckIfRangeIsInBounds(GridScript, ThisPosition, LayerNumber))
                    {
                        Tile ThisTile = GetTile(GridScript, ThisPosition, LayerNumber);
                        if (ThisTile != null)
                        {
                            if (FindEnemies)
                            {
                                if (ThisTile.LoadedUnitScript != null && ThisTile.LoadedUnitScript.Owner != CurrentPlayer)
                                {
                                    ThisTile.TileSelectionType = DesiredOverlay;
                                }
                            }
                            else if (findAllies)
                            {
                                if (ThisTile.LoadedUnitScript != null && ThisTile.LoadedUnitScript.Owner == CurrentPlayer)
                                {
                                    ThisTile.TileSelectionType = DesiredOverlay;
                                }
                            }
                            else if (findEmptyTiles)
                            {
                                ThisTile.TileSelectionType = DesiredOverlay;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
    public virtual void CreateGrid()
    {
        Instance = this;
        grid     = new Tile[GRIDSIZEX, GRIDSIZEZ, layerCount];
        GameObject   GameController = GameObject.Find("GameControl");
        SwitchButton SwitchScript   = GameController.GetComponent <SwitchButton> ();
        //Go down the grid on the X plane, setting up parameters for each tile on the Z plane
        Player Player1Script = GameObject.Find("Player1(Clone)").GetComponent <Player> ();
        Player Player2Script = GameObject.Find("Player2(Clone)").GetComponent <Player> ();
        int    unitcounter   = 0;

        foreach (string unittype in Player1Script.genreScript.UnitTypes)
        {
            if (unittype == "King")
            {
                Player1King = Player1Script.genreScript.UnitsList[unitcounter].GetComponent <Unit>();
                break;
            }
            else
            {
                unitcounter++;
            }
        }
        unitcounter = 0;
        foreach (string unittype in Player1Script.genreScript.UnitTypes)
        {
            if (unittype == "Wall")
            {
                Player1Wall = Player1Script.genreScript.UnitsList[unitcounter].GetComponent <Unit>();
                break;
            }
            else
            {
                unitcounter++;
            }
        }
        unitcounter = 0;
        foreach (string unittype in Player2Script.genreScript.UnitTypes)
        {
            if (unittype == "King")
            {
                Player2King = Player2Script.genreScript.UnitsList[unitcounter].GetComponent <Unit>();
                break;
            }
            else
            {
                unitcounter++;
            }
        }
        unitcounter = 0;
        foreach (string unittype in Player2Script.genreScript.UnitTypes)
        {
            if (unittype == "Wall")
            {
                Player2Wall = Player2Script.genreScript.UnitsList[unitcounter].GetComponent <Unit>();
                break;
            }
            else
            {
                unitcounter++;
            }
        }
        for (int xposition = 0; xposition < GRIDSIZEX; xposition++)
        {
            for (int zposition = 0; zposition < GRIDSIZEZ; zposition++)
            {
                //Instantiate a tile as a GameObject, pull the Tile component from it, set it to the "tile" variable
                Object     tileObject     = Instantiate(tilePrefab.gameObject, new Vector3(xposition, 0, zposition), Quaternion.identity);
                GameObject tileGameObject = tileObject as GameObject;
                Tile       thisTile       = tileGameObject.GetComponent <Tile>();
                //Reset the tile edited counter
                int tileEdited = 0;
                //Set the position in the grid to be the tile class
                grid[xposition, zposition, 0] = thisTile;
                thisTile.xcoord        = xposition;
                thisTile.zcoord        = zposition;
                thisTile.layerNumber.x = 0;
                //The following nested if statement checks if the tile is in a position that needs to be a king or wall. If it does not, then it sets the tile to be an ordinary tile.
                if (xposition <= KINGPLAYER1MAXX)
                {
                    if (zposition == KINGMINZ - 1 || zposition == KINGMAXZ + 1)
                    {
                        InsertUnit(thisTile, Player1Wall, SwitchScript.Player1Script);
                        thisTile.type = Tile.Type.Player1Wall;
                        tileEdited    = 1;
                    }
                    else if (zposition == KINGMINZ || zposition == KINGMAXZ)
                    {
                        if (!Player1Script.KingHasSpawned)
                        {
                            Player1Script.KingHasSpawned = true;
                            InsertUnit(thisTile, Player1King, SwitchScript.Player1Script);
                        }
                        thisTile.LoadedUnitScript = Player1King;
                        thisTile.type             = Tile.Type.Player1King;
                        tileEdited = 1;
                    }
                }
                else if (xposition == KINGPLAYER1MAXX + 1)
                {
                    if (KINGMINZ - 1 <= zposition && zposition <= KINGMAXZ + 1)
                    {
                        InsertUnit(thisTile, Player1Wall, SwitchScript.Player1Script);
                        thisTile.type = Tile.Type.Player1Wall;
                        tileEdited    = 1;
                    }
                }
                else if (xposition >= KINGPLAYER2MINX)
                {
                    if (zposition == KINGMINZ - 1 || zposition == KINGMAXZ + 1)
                    {
                        InsertUnit(thisTile, Player2Wall, SwitchScript.Player2Script);
                        thisTile.type = Tile.Type.Player2Wall;
                        tileEdited    = 1;
                    }
                    else if (zposition == KINGMINZ || zposition == KINGMAXZ)
                    {
                        if (!Player2Script.KingHasSpawned)
                        {
                            Player2Script.KingHasSpawned = true;
                            InsertUnit(thisTile, Player2King, SwitchScript.Player2Script);
                        }
                        thisTile.LoadedUnitScript = Player2King;
                        thisTile.type             = Tile.Type.Player2King;
                        tileEdited = 1;
                    }
                }
                else if (xposition == KINGPLAYER2MINX - 1)
                {
                    if (KINGMINZ - 1 <= zposition && zposition <= KINGMAXZ + 1)
                    {
                        InsertUnit(thisTile, Player2Wall, SwitchScript.Player2Script);
                        thisTile.type = Tile.Type.Player2Wall;
                        tileEdited    = 1;
                    }
                }
                if (tileEdited == 0)
                {
                    thisTile.unit       = UnitType.None;
                    thisTile.player     = PlayerNumber.None;
                    thisTile.tempUnit   = UnitType.None;
                    thisTile.tempPlayer = PlayerNumber.None;
                    if (xposition <= PLAYER1PLACEABLEAREA)
                    {
                        thisTile.type = Tile.Type.Player1;
                    }
                    else if (xposition >= PLAYER2PLACEABLEAREA)
                    {
                        thisTile.type = Tile.Type.Player2;
                    }
                    else
                    {
                        int randomNumber = Random.Range(-1, PLAYER2PLACEABLEAREA - PLAYER1PLACEABLEAREA) + (xposition - PLAYER1PLACEABLEAREA);
                        if (randomNumber < PLAYER2PLACEABLEAREA - PLAYER1PLACEABLEAREA - 1)
                        {
                            thisTile.type = Tile.Type.Player1;
                        }
                        else
                        {
                            thisTile.type = Tile.Type.Player2;
                        }
                    }
                }
                //The if/elif statement sets all tiles within the units placeable area of each player to be placeable for them.
                if (xposition <= PLAYER1PLACEABLEAREA)
                {
                    thisTile.playerThatCanPlaceUnits = PlayerNumber.Player1;
                }
                else if (xposition >= PLAYER2PLACEABLEAREA)
                {
                    thisTile.playerThatCanPlaceUnits = PlayerNumber.Player2;
                }
            }
        }
        //SwitchScript.EnableSpawnableArea ();
    }
Exemplo n.º 11
0
 protected virtual void Awake()
 {
     Instance = this;
     DontDestroyOnLoad(this);
 }
Exemplo n.º 12
0
    public static void MoveRangeAdvance(this GridCS GridScript, Tile aTile, int MoveValue, int LayerNumber)
    {
        if (MoveValue > 0)
        {
            Tile ThisTile;
            int  TargetLayer = LayerNumber;
            if (aTile.movedirections == "n")
            {
                if (aTile.zcoord + 1 < GridCS.GRIDSIZEZ)
                {
                    ThisTile = GridScript.grid [aTile.xcoord, aTile.zcoord + 1, TargetLayer];
                    if (ThisTile != null)
                    {
                        MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                    }
                }
                if (aTile.zcoord - 1 >= 0)
                {
                    ThisTile = GridScript.grid [aTile.xcoord, aTile.zcoord - 1, TargetLayer];
                    if (ThisTile != null)
                    {
                        MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                    }
                }
                if (aTile.xcoord + 1 < GridCS.GRIDSIZEX)
                {
                    ThisTile = GridScript.grid [aTile.xcoord + 1, aTile.zcoord, TargetLayer];
                    if (ThisTile != null)
                    {
                        MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                    }
                }
                if (aTile.xcoord - 1 >= 0)
                {
                    ThisTile = GridScript.grid [aTile.xcoord - 1, aTile.zcoord, TargetLayer];
                    if (ThisTile != null)
                    {
                        MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                    }
                }
            }
            else
            {
                string[] moveoptions = aTile.movedirections.Split(new char[] { '_' }, System.StringSplitOptions.RemoveEmptyEntries);
                foreach (string moveoption in moveoptions)
                {
                    string[] levelconnector = moveoption.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);
                    if (levelconnector.Length == 2)
                    {
                        TargetLayer = System.Convert.ToInt32(levelconnector[1]);
                    }
                    switch (levelconnector [0])
                    {
                    case "+z":
                        if (aTile.zcoord + 1 < GridCS.GRIDSIZEZ)
                        {
                            ThisTile = GridScript.grid [aTile.xcoord, aTile.zcoord + 1, TargetLayer];
                            if (ThisTile != null)
                            {
                                MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                            }
                        }
                        break;

                    case "-z":
                        if (aTile.zcoord - 1 >= 0)
                        {
                            ThisTile = GridScript.grid [aTile.xcoord, aTile.zcoord - 1, TargetLayer];
                            if (ThisTile != null)
                            {
                                MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                            }
                        }
                        break;

                    case "+x":
                        if (aTile.xcoord + 1 < GridCS.GRIDSIZEX)
                        {
                            ThisTile = GridScript.grid [aTile.xcoord + 1, aTile.zcoord, TargetLayer];
                            if (ThisTile != null)
                            {
                                MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                            }
                        }
                        break;

                    case "-x":
                        if (aTile.xcoord - 1 >= 0)
                        {
                            ThisTile = GridScript.grid [aTile.xcoord - 1, aTile.zcoord, TargetLayer];
                            if (ThisTile != null)
                            {
                                MoveRangeNext(GridScript, ThisTile, MoveValue, TargetLayer);
                            }
                        }
                        break;
                    }
                    TargetLayer = LayerNumber;
                }
            }
        }
    }
Exemplo n.º 13
0
    //Finds the tile associated with a place on the grid.
    public static Tile GetTile(this GridCS GridScript, Vector2 Position, int LayerNumber)
    {
        Tile ThisTile = GridScript.grid[(int)Position.x, (int)Position.y, LayerNumber];

        return(ThisTile);
    }