fix random puzzle order

This commit is contained in:
2022-12-14 17:50:19 +01:00
parent e24d9b86a9
commit 65b4cecd9b
3 changed files with 11 additions and 5 deletions

View File

@@ -86,8 +86,7 @@ namespace EscapeRoomEngine.Engine.Runtime
Space space;
Passage exit = null;
var puzzle = _puzzles[0];
_puzzles.RemoveAt(0);
var puzzle = _puzzles.PopRandomElement();
do
{

View File

@@ -27,7 +27,14 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
public static int RandomInclusive(int from, int to) => Random.Range(from, to + 1);
public static T RandomElement<T>(this List<T> list) => list[Random.Range(0, list.Count)];
public static T RandomElement<T>(this HashSet<T> set) => set.ElementAt(Random.Range(0, set.Count));
public static T PopRandomElement<T>(this List<T> list)
{
var index = Random.Range(0, list.Count);
var element = list[index];
list.RemoveAt(index);
return element;
}
#endregion
}