public RandomLocks() { int NumberOfLocks = 8; // Generate eight locks while (NumberOfLocks > 0) { Lock randomLock = new Lock(); // 1, 2 or 3 Challenges per Lock int NumberOfChallenges = (RNoGen.Next() % 3) + 1; while (NumberOfChallenges > 0) { List <string> Conditions = new List <string>(); // 1, 2 or 3 Conditions per Challenge int NumberOfConditions = (RNoGen.Next() % 3) + 1; while (NumberOfConditions > 0) { Conditions.Add(GetRandomCondition()); NumberOfConditions--; } randomLock.AddChallenge(Conditions); NumberOfChallenges--; } Locks.Add(randomLock); NumberOfLocks--; } }
public void RegenerateNewLocks(PuzzleDifficulty difficulty) { NumbersOrder = NumbersOrder.OrderBy(x => RandomValuesGenerator.GetRandomInt()).ToList(); Locks.Clear(); for (int i = 0; i < 10; i++) { switch (difficulty) { case PuzzleDifficulty.Easy: Locks.Add( new EasyPuzzleLockPreset( number: NumbersOrder[i], color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4)), lowerRange: 0, upperRange: 9) { NumberCypherType = PuzzleNumberCypherType.ReverseInRange, ColorCypherType = PuzzleColorCypherType.TextShuffle }); break; case PuzzleDifficulty.Normal: Locks.Add( new NormalPuzzleLockPreset( lockNumber: NumbersOrder[i], color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4)), caesarShift: RandomValuesGenerator.GetInt(1, 100)) { NumberCypherType = PuzzleNumberCypherType.Caesar, ColorCypherType = PuzzleColorCypherType.RGB }); break; case PuzzleDifficulty.Hard: Locks.Add( new HardPuzzleLockPreset( lockNumber: NumbersOrder[i], color: (PuzzleColors)Enum.GetValues(typeof(PuzzleColors)).GetValue(RandomValuesGenerator.GetInt(0, 4))) { NumberCypherType = PuzzleNumberCypherType.Binary, ColorCypherType = PuzzleColorCypherType.Hex }); break; } } PreviousLockNumber = null; CurrentLockNumber = null; NextLockNumber = null; CurrentOrderIndex = 0; CurrentLockNumber = NumbersOrder[CurrentOrderIndex]; NextLockNumber = NumbersOrder[CurrentOrderIndex + 1]; }
public ILock GetLock() { lock (sync) { if (lockID != Guid.Empty) { throw new InvalidOperationException("This instance is " + "already locked."); } lockID = Guid.NewGuid(); Locks.Add(lockID, SlotMarker); return(new ThreadGuardLock(this)); } }