private void Kill()
    {
        while (RouteStillAvailable(currentRow, currentColumn))
        {
            int direction = numberGenerator.GetNextNumber(1, 5);
            if (direction != lastNumber)
            {
                cells[currentRow, currentColumn].floor.tag = "Navigation";
            }
            lastNumber = direction;

            if (direction == 1 && CellIsAvailable(currentRow - 1, currentColumn))
            {
                // Nord
                DestroyWallIfItExists(cells[currentRow, currentColumn].northWall);
                DestroyWallIfItExists(cells[currentRow - 1, currentColumn].southWall);
                currentRow--;
            }
            else if (direction == 2 && CellIsAvailable(currentRow + 1, currentColumn))
            {
                // Sud
                DestroyWallIfItExists(cells[currentRow, currentColumn].southWall);
                DestroyWallIfItExists(cells[currentRow + 1, currentColumn].northWall);
                currentRow++;
            }
            else if (direction == 3 && CellIsAvailable(currentRow, currentColumn + 1))
            {
                // est
                DestroyWallIfItExists(cells[currentRow, currentColumn].eastWall);
                DestroyWallIfItExists(cells[currentRow, currentColumn + 1].westWall);
                currentColumn++;
            }
            else if (direction == 4 && CellIsAvailable(currentRow, currentColumn - 1))
            {
                // ouest
                DestroyWallIfItExists(cells[currentRow, currentColumn].westWall);
                DestroyWallIfItExists(cells[currentRow, currentColumn - 1].eastWall);
                currentColumn--;
            }

            cells[currentRow, currentColumn].visited = true;
        }
    }
Пример #2
0
    private void Initialize()
    {
        cells = new Cell[StaticGameStats.Rows, StaticGameStats.Columns];

        for (int r = 0; r < StaticGameStats.Rows; r++)
        {
            for (int c = 0; c < StaticGameStats.Columns; c++)
            {
                cells[r, c] = new Cell();

                cells[r, c].floor      = Instantiate(floor, new Vector3(r * size, -(1.3f), c * size), Quaternion.identity) as GameObject;
                cells[r, c].floor.name = "Floor " + r + "," + c;
                cells[r, c].floor.transform.Rotate(Vector3.right, 90f);


                if (c == 0)
                {
                    cells[r, c].westWall      = Instantiate(wall, new Vector3(r * size, 0, (c * size) - (size / 2f)), Quaternion.identity) as GameObject;
                    cells[r, c].westWall.name = "West Wall " + r + "," + c;
                }

                cells[r, c].eastWall      = Instantiate(wall, new Vector3(r * size, 0, (c * size) + (size / 2f)), Quaternion.identity) as GameObject;
                cells[r, c].eastWall.name = "East Wall " + r + "," + c;

                if (r == 0)
                {
                    cells[r, c].northWall      = Instantiate(wall, new Vector3((r * size) - (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                    cells[r, c].northWall.name = "North Wall " + r + "," + c;
                    cells[r, c].northWall.transform.Rotate(Vector3.up * 90f);
                }

                cells[r, c].southWall      = Instantiate(wall, new Vector3((r * size) + (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                cells[r, c].southWall.name = "South Wall " + r + "," + c;
                cells[r, c].southWall.transform.Rotate(Vector3.up * 90f);

                int propsSpawn = numberGenerator.GetNextNumber(1, 9);
                if (propsSpawn < 5)
                {
                    cells[r, c].props = Instantiate(GetProps(propsSpawn),
                                                    new Vector3((r * size) - Random.Range(-(size / 2f), size / 2f), -(1f), (c * size) - Random.Range(-(size / 2f), size / 2f)),
                                                    Quaternion.Euler(0.0f, Random.Range(0, 180), 0.0f)) as GameObject;
                    cells[r, c].props.name = "Props " + r + "," + c;
                    if (propsSpawn == 3)
                    {
                        cells[r, c].props.tag = "Patrol";
                        cells[r, c].props.transform.Translate(new Vector3(0, 0.4f, 0));
                        particleSystemPool.PlayParticleSystem(cells[r, c].props.transform);
                    }
                }
            }
        }
    }