fix end space

This commit is contained in:
2022-12-15 23:40:55 +01:00
parent 4f57b57a00
commit 80435ff696
3 changed files with 25 additions and 34 deletions

View File

@@ -63,7 +63,15 @@ namespace EscapeRoomEngine.Engine.Runtime
var room = new Room(entrance);
_rooms.Add(room);
GenerateSpace(room, entrance);
if (_plannedPuzzles.Count > 0)
{
GeneratePuzzleSpace(room, entrance);
}
else
{
GenerateEndSpace(room, entrance);
GameControl.Instance.StopGame();
}
var roomId = _rooms.Count - 1;
room.InstantiateRoom(_playSpaceOrigin.transform, roomId * roomOffset, roomId.ToString());
@@ -77,15 +85,14 @@ namespace EscapeRoomEngine.Engine.Runtime
UpdateUI();
}
private void GenerateSpace(Room room, Passage entrance)
private void GeneratePuzzleSpace(Room room, Passage entrance)
{
var puzzlesAdded = 0;
var tries = 0;
Space space;
Passage exit = null;
Passage exit;
// choose the next puzzle
// PlanPuzzles();
var puzzle = ChoosePuzzle();
GameControl.Instance.CurrentPuzzle = puzzle;
@@ -98,17 +105,14 @@ namespace EscapeRoomEngine.Engine.Runtime
space = new Space(room, entrance);
// add exit
if (_plannedPuzzles.Count > 0)
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
if (!space.AddModuleWithRequirements(exitDoor))
{
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
if (!space.AddModuleWithRequirements(exitDoor))
{
throw new EngineException("Could not satisfy requirements for exit door.");
}
exit = new Passage(exitDoor);
throw new EngineException("Could not satisfy requirements for exit door.");
}
exit = new Passage(exitDoor);
// add puzzle
// add puzzle
if (space.AddModuleWithRequirements(Module.CreateModuleByType(space, puzzle)))
{
puzzlesAdded++;
@@ -123,6 +127,13 @@ namespace EscapeRoomEngine.Engine.Runtime
room.AddSpace(space, exit);
}
private void GenerateEndSpace(Room room, Passage entrance)
{
Logger.Log($"Generating end space...", LogType.RoomGeneration);
room.AddSpace(new Space(room, entrance), null);
}
private PuzzleModuleDescription ChoosePuzzle()
{
// choose a puzzle from the plan and remove it from both the plan and later available puzzles (so it is only chosen once)

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.UI;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
@@ -62,11 +61,7 @@ namespace EscapeRoomEngine.Engine.Runtime
{
Measure.Solve((PuzzleModuleDescription)puzzle.description);
if (LastRoom)
{
GameControl.Instance.StopGame();
}
else if (puzzles.All(p => p.PuzzleState.Solved))
if (puzzles.All(p => p.PuzzleState.Solved))
{
exit.fromOut.DoorState.Unlock();
}