private FloorLayout GenerateFloor(int floorNum, System.Random randomGen)
    {
        var floorSize         = SetFloorRoomSize(floorNum);
        var floorRecipeLength = SetRecipeLength(floorNum);
        var floorTheme        = SetVisualTheme(floorNum);
        var roomDifficulty    = SetRoomDifficulty(floorNum);
        var recipeName        = GetRecipe();

        var layout = new FloorLayout {
            floorRoomSize = floorSize
        };

        DungeonResult results = Program.GenerateDungeon(recipeLength: floorRecipeLength, randomGen: randomGen,
                                                        recipeName: recipeName);

        if (results.layoutMap == null)
        {
            Debug.Log("Generated layout was invalid.");
            Application.Quit();
        }
        else
        {
            Cell[,] cellGrid = results.layoutMap.Get2DMap();
            if (debug)
            {
                Debug.Log(results.layoutMap.ToString());
            }

            layout.floorLayout = new RoomDefinition[cellGrid.GetLength(0), cellGrid.GetLength(1)];

            for (int i = 0; i < cellGrid.GetLength(0); i++)
            {
                for (int j = 0; j < cellGrid.GetLength(1); j++)
                {
                    if (cellGrid[i, j] != null)
                    {
                        if (cellGrid[i, j].type == CellType.Connection)
                        {
                            cellGrid[i, j].node = new Node(0, 0, NodeType.Connection);
                        }
                        layout.floorLayout[i, j] =
                            templateGenerator.GenerateRoom(roomDifficulty, floorSize, cellGrid[i, j]);
                        layout.floorLayout[i, j].visualTheme = floorTheme;
                        layout.floorLayout[i, j].roomType    = cellGrid[i, j].node.type;
                    }
                }
            }

            layout.cellLayout = cellGrid;
        }

        SetSunProperties(ref layout);

        return(layout);
    }
        private void EvaluateDungeonResult()
        {
            StageResult stageResult = activeStage.EvaluationResult();

//				DLog.Log("stage result " + stageResult);
            if (stageResult == StageResult.Failed)
            {
                dungeonResult = DungeonResult.Failed;
                NotifyDungeonResult();
            }
            else if (stageResult == StageResult.Completed)
            {
                completedStagesCount++;
                if (IsLastStage())
                {
                    dungeonResult = DungeonResult.Completed;
                    int indexOfActiveStage = stages.IndexOf(activeStage);
                    NotifyStageCycle(indexOfActiveStage + 1, StageCycle.Clear);
                    //DLog.Log("Dungeon: result: " + dungeonResult);
                    NotifyDungeonResult();
                }
            }
        }
 public void ResetResult()
 {
     dungeonResult = DungeonResult.Undefined;
     activeStage.ResetResult();
 }