Пример #1
0
    private void GenerateIntersection(Cell cell)
    {
        int roadCount = Random.Range(3, 4);

        int  generateRoads = 0;
        uint width         = 2;

        ErrorCollector errors = new ErrorCollector();

        int tries = 0;

        // Create new paths
        while (generateRoads < roadCount && tries < 25)
        {
            errors.Clear();
            tries++;

            // Place entrance
            CellEntranceExit entrance = CellEntranceExit.Create(cell, width, errors);
            errors.GoBoom();

            // Place exit
            CellEntranceExit exit = null;
            int exitTries         = 0;
            while (exitTries < 5)
            {
                exitTries++;
                exit = CellEntranceExit.Create(cell, entrance, errors);
                errors.GoBoom();
                break;
                //if (errors.Count > 0)
                //{
                //  entrance.Remove(cell);
                //break;
                //}
            }
            errors.GoBoom();

            int roadTries = 0;
            while (roadTries < 20)
            {
                errors.Clear();
                roadTries++;
                CreateRoad(cell, entrance, exit, errors);
                errors.GoBoom();

                break;
            }

            generateRoads++;
        }
    }
Пример #2
0
    private void CreateRoad(Cell cell, CellEntranceExit entrance, CellEntranceExit exit, ErrorCollector errors)
    {
        Path path = PathGenerator.GeneratePath(cell, entrance, exit, errors);

        errors.GoBoom();

        Road road = new Road(path);

        cell.AddRoad(road);
    }