/// <summary> /// Called when the user moves from one room to another. This simply verifies that the new room /// is what we expect it to be. /// </summary> /// <param name="lastSeenRoom"></param> /// <param name="movingDirection"></param> /// <param name="room"></param> private void VerifyNewRoom(SeenRoom lastSeenRoom, Direction movingDirection, SeenRoom room, Player player) { FindPotentialRoomMatch(room, player); if (room.PotentialMatches.Count == 1) { // only one match for the current room. Go ahead and set it. SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); return; } if (room.PotentialMatches.Count == 0) { // no matches, not sure what to do. SetCurrentRoom(RoomDetectionState.NoClue, null, player); return; } // ambiguous match found, so attempt to figure out what room we're in by following the // exit that the user used. var exitData = lastSeenRoom.Match.GetExits().SingleOrDefault(x => x.Direction == movingDirection); Room matchedRoom = null; if (exitData != null) { matchedRoom = room.GetMatch(exitData.AdjacentRoomNumber); } if (matchedRoom == null) { // no match. Dunno what happened. User possibly teleported into an ambiguous room. SetCurrentRoom(RoomDetectionState.HaveMatches, room, player); } else { // we have a match. Remove all candidates that aren't the matched room room.PotentialMatches.RemoveAll(x => x != matchedRoom); SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); } }