private void UnlockDoor(Door door) { if (door.State == DoorState.Unlocking) { door.State = DoorState.Unlocked; _doors.Remove(door.WorldIndex); Door value; // Left if (_doors.TryGetValue(door.WorldIndex - Vector2i.UnitX, out value)) { if (value.State != DoorState.Unlocked) { _nextDoorsToCheck.Enqueue(_doors[door.WorldIndex - Vector2i.UnitX]); } } // Right if (_doors.TryGetValue(door.WorldIndex + Vector2i.UnitX, out value)) { if (value.State != DoorState.Unlocked) { _nextDoorsToCheck.Enqueue(_doors[door.WorldIndex + Vector2i.UnitX]); } } // Up if (_doors.TryGetValue(door.WorldIndex - Vector2i.UnitY, out value)) { if (value.State != DoorState.Unlocked) { _nextDoorsToCheck.Enqueue(_doors[door.WorldIndex - Vector2i.UnitY]); } } // Down if (_doors.TryGetValue(door.WorldIndex + Vector2i.UnitY, out value)) { if (value.State != DoorState.Unlocked) { _nextDoorsToCheck.Enqueue(_doors[door.WorldIndex + Vector2i.UnitY]); } } } }
public void StartUnlocking(Door unlockingStartingDoor) { if (!_isUnlocking) { _isUnlocking = true; foreach (Door door in _doors.Values) { if (door.State != DoorState.Locked) { throw new ArgumentException("Door is already unlocked!"); } door.State = DoorState.Unlocking; } _nextDoorsToCheck.Enqueue(unlockingStartingDoor); } }