コード例 #1
0
ファイル: CellGenerator.cs プロジェクト: Notloc/Intersections
    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++;
        }
    }