IEnumerator FlipHexes(bool FRestart)
    {
        Background_Right.SetActive(false);
        Background_Restart.SetActive(false);
        Background_Credits.SetActive(false);

        foreach (Transform CurrentColumn in Right.transform)
        {
            foreach (Transform CurrentTile in CurrentColumn)
            {
                CurrentTile.gameObject.SetActive(true);
                CurrentTile.GetComponent <Animator>().SetTrigger("Flip");
            }
            yield return(new WaitForSeconds(0.01f));
        }

        StartCoroutine(DelayedBackground(Background_Right, true));
        //Background_Right.SetActive(true);

        if (FRestart)
        {
            FailedText.SetActive(true);
            Reason.SetActive(true);

            foreach (Transform CurrentColumn in Restart.transform)
            {
                foreach (Transform CurrentTile in CurrentColumn)
                {
                    CurrentTile.gameObject.SetActive(true);
                    CurrentTile.GetComponent <Animator>().SetTrigger("Flip");
                }
                yield return(new WaitForSeconds(0.01f));
            }

            StartCoroutine(DelayedBackground(Background_Restart, true));
            //Background_Restart.SetActive(true);
        }
        else
        {
            foreach (Transform CurrentColumn in Credits.transform)
            {
                foreach (Transform CurrentTile in CurrentColumn)
                {
                    CurrentTile.gameObject.SetActive(true);
                    CurrentTile.GetComponent <Animator>().SetTrigger("Flip");
                }
                yield return(new WaitForSeconds(0.0001f));
            }

            StartCoroutine(DelayedBackground(Background_Credits, true));
            //Background_Credits.SetActive(true);
        }
    }
Exemple #2
0
    private void CreateBasicGrid()
    {
        float      YStep             = Mathf.Sqrt(HexRadius * HexRadius - HexRadius * HexRadius / 4);
        float      XStep             = HexRadius - Mathf.Sqrt(HexRadius * HexRadius - YStep * YStep) / 2;
        float      OddRowPush        = 0.0F;
        int        GridCorrector     = 0;
        Vector3    GlobalCoordinates = new Vector3(0.0F, 0.0F, 0.0F);
        GameObject CurrentTile;

        System.Random Rand = new System.Random();

        for (int GridX = 0; GridX < (int)GridSize.x; GridX++)
        {
            OddRowPush = (GridX % 2 == 1) ? (YStep / 2) : 0;
            for (int GridY = GridCorrector; GridY < (int)GridSize.y + GridCorrector; GridY++)
            {
                GlobalCoordinates.x = ((GridY - GridCorrector) * YStep) + OddRowPush;
                GlobalCoordinates.y = -GridX * XStep;

                //Instantiating a tile
                CurrentTile      = (GameObject)Instantiate(DefaultTile, new Vector3(GlobalCoordinates.x, 0, GlobalCoordinates.y), Quaternion.identity);
                CurrentTile.name = "[" + GridY + "," + GridX + "]";
                CurrentTile.transform.SetParent(this.transform);
                CurrentTile.AddComponent <HexTile>();
                HexTile currentHex = CurrentTile.GetComponent <HexTile>();
                currentHex.AxialCoordinates = new Vector2(GridX, GridY);
                currentHex.Type             = (TerrainType)Rand.Next(0, 5);
                TerrainProperty terrainProp = FindProperty(currentHex);
                CurrentTile.GetComponent <Renderer>().material.color = terrainProp.DebugColor;

                if (GridX == 0 && GridY == 0)
                {
                    PlayersTile = currentHex;
                }
            }

            if (GridX % 2 == 1)
            {
                GridCorrector--;
            }
        }
    }
    IEnumerator ReverseHexes(bool FRestart)
    {
        if (FRestart)
        {
            FailedText.SetActive(false);
            Reason.SetActive(false);
            Background_Restart.SetActive(false);
        }

        else
        {
            for (int loop = (Credits.transform.childCount - 1); loop >= 0; loop--)
            {
                foreach (Transform CurrentTile in Credits.transform.GetChild(loop))
                {
                    CurrentTile.GetComponent <Animator>().SetTrigger("Reset");
                }
                yield return(new WaitForSeconds(0.0001f));
            }

            for (int loop = (Right.transform.childCount - 1); loop >= 0; loop--)
            {
                foreach (Transform CurrentTile in Right.transform.GetChild(loop))
                {
                    CurrentTile.GetComponent <Animator>().SetTrigger("Reset");
                }
                yield return(new WaitForSeconds(0.0001f));
            }

            Background_Credits.SetActive(false);
        }

        Background_Right.SetActive(false);

        if (!FRestart)
        {
            yield return(new WaitForSeconds(0.6f));
        }

        DisableMe();
    }
Exemple #4
0
    void CreateMaze()
    {
        //The depth-first search algorithm of maze generation is frequently implemented using backtracking:

        //1. Make the initial cell the current cell and mark it as visited

        //2. While there are unvisited cells
        //1. If the current cell has any neighbours which have not been visited
        //1. Choose randomly one of the unvisited neighbours
        //2. Push the current cell to the stack
        //3. Remove the wall between the current cell and the chosen cell
        //4. Make the chosen cell the current cell and mark it as visited
        //2. Else if stack is not empty
        //1. Pop a cell from the stack
        //2. Make it the current cell

        List <Tile> TileStack = new List <Tile>();


        Tile CurrentTile;
        int  Count;

        Count       = 1;
        CurrentTile = Maze[0, 0].GetComponent <Tile>();
        Maze[0, 0].GetComponent <Tile>().Walls[3].gameObject.SetActive(false);
        CurrentTile.GetComponent <Tile>().Visited = true;

        while (Width * Height > Count)
        {
            Tile NextTile = SelectNeighbor(CurrentTile);
            if (NextTile != null)
            {
                TileStack.Add(CurrentTile);
                LowerWall(CurrentTile, NextTile);
                CurrentTile         = NextTile;
                CurrentTile.Visited = true;
                Count++;
            }
            else if (TileStack.Count != 0)
            {
                CurrentTile = TileStack[TileStack.Count - 1];
                TileStack.RemoveAt(TileStack.Count - 1);
            }
        }

        for (int i = 0; i < 10; i++)
        {
            int x = Random.Range(1, Width - 1);
            int y = Random.Range(1, Height - 1);

            List <Tile> ViableNextTile = new List <Tile>();

            foreach (Tile T in Maze[x, y].GetComponent <Tile>().Neighbor)
            {
                if (T == null)
                {
                    //no nothing
                }
                else if (CheckWall(Maze[x, y].GetComponent <Tile>(), T) == true)
                {
                    ViableNextTile.Add(T);
                }
            }

            if (ViableNextTile.Count == 0)
            {
                break;
            }
            else
            {
                int z = Random.Range(0, ViableNextTile.Count);
                LowerWall(Maze[x, y].GetComponent <Tile>(), Maze[x, y].GetComponent <Tile>().Neighbor[z]);
            }
        }

        int m = Random.Range(1, 3);


        if (m == 1)
        {
            int n = Random.Range(Width / 2, Width);
            Maze[n, Height - 1].GetComponent <Tile>().Walls[0].gameObject.SetActive(false);
        }
        else
        {
            int n = Random.Range(Height / 2, Height);
            Maze[Width - 1, n].GetComponent <Tile>().Walls[1].gameObject.SetActive(false);
        }

        for (int i = 0; i < Width; i++)
        {
            for (int j = 0; j < Height; j++)
            {
                Maze[i, j].GetComponent <Tile>().setSprite();
            }
        }
    }