public void TestGetNonExistantAdjoiningRoom() { Room r = new Room("a", "b", "c"); AdjoiningRoom ar = r.GetAdjoiningRoom(Direction.South); Assert.Null(ar); }
public void TestAdjoiningRoomNoRequiredItem() { Room r = new Room("a", "b", "c"); r.AddAdjoiningRoom("west", "room-with-requirement"); AdjoiningRoom ar = r.GetAdjoiningRoom(Direction.West); Assert.Equal("", ar.RequiresId); }
public void TestAddAdjoiningRoom(string direction, Direction directionEnum, string id) { Room r = new Room("a", "b", "c"); r.AddAdjoiningRoom(direction, id); AdjoiningRoom ar = r.GetAdjoiningRoom(directionEnum); Assert.Equal(id, ar.Id); }
public string MovePeggy(string direction) { Direction d = Utils.GetDirectionFromString(direction); if (d == Direction.Invalid) { return($"{Utils.Capitalize(direction)}? What kind of bonkers direction is that?!\r\n"); } AdjoiningRoom ar = Peggy.CurrentRoom.GetAdjoiningRoom(d); if (ar == null) { return($"There is nothing to the {Utils.Capitalize(direction)}.\r\n"); } if (!_rooms.ContainsKey(ar.Id)) { throw new InvalidOperationException($"The adjoining room {ar.Id} is not in the list of rooms."); } // New room exists, get the new room object so we have access to all the properties. Room newRoom = _rooms[ar.Id]; if (!string.IsNullOrEmpty(ar.RequiresId)) { if (!Peggy.InventoryHasItem(ar.RequiresId)) { // TODO: we should print the Friendly name for the item, but iterating // through all rooms and items is a slow way. We could build a Dictionary // of item ID -> item Name mappings when we parse the map. return($"The {ar.RequiresId} is required to get into the {newRoom.FriendlyName}.\r\n"); } else { Item requiredItem = Peggy.GetItemFromInventoryWithoutRemoving(ar.RequiresId); ar.SatisfyRequiredItem(requiredItem); } } return(Peggy.SetCurrentRoom(newRoom)); }
// Usually this should return a portal, but be prepared for the situation that this returns null because in case of problems this might happen. public PortalInstance FindOppositePortal(Room room) { var adjoiningRoomArea = GetOppositePortalArea(Direction, Area) + (room.SectorPos - AdjoiningRoom.SectorPos); if (!new RectangleInt2(0, 0, AdjoiningRoom.NumXSectors, AdjoiningRoom.NumZSectors).Contains(adjoiningRoomArea.Start)) { return(null); } // Check sectors var sector = AdjoiningRoom.GetBlockTry(adjoiningRoomArea.Start); switch (Direction) { case PortalDirection.Floor: return(sector?.CeilingPortal); // A floor portal in this room is a ceiling portal in the adjoining room. case PortalDirection.Ceiling: return(sector?.FloorPortal); // A ceiling portal in this room is a floor portal in the adjoining room. default: return(sector?.WallPortal); } }