public void Zone_SeralizeDeserialize() { IZone zone = new Objects.Zone.Zone(); IRoom room = new Objects.Room.Room(); IItem item = new Objects.Item.Item(); INonPlayerCharacter npc = new Objects.Mob.NonPlayerCharacter(); IPlayerCharacter pc = new Objects.Mob.PlayerCharacter(); GlobalReference.GlobalValues.Initilize(); zone.Id = 0; room.Id = 0; item.Level = 3; zone.Rooms.Add(0, room); room.Items.Add(item); room.AddMobileObjectToRoom(npc); room.AddMobileObjectToRoom(pc); npc.Items.Add(item); npc.Level = 1; pc.Items.Add(item); pc.Level = 1; GlobalReference.GlobalValues.World.Zones.Add(0, zone); string serializedZone = GlobalReference.GlobalValues.Serialization.Serialize(zone); IZone zone2 = GlobalReference.GlobalValues.Serialization.Deserialize <Objects.Zone.Zone>(serializedZone); //temp work around room being added 2x IRoom room2; zone2.Rooms.TryGetValue(0, out room2); room2.KeyWords.RemoveAt(0); string serializedZone2 = GlobalReference.GlobalValues.Serialization.Serialize(zone2); Assert.AreEqual(serializedZone, serializedZone2); }
public IZone ConvertToZone(int zoneId) { Zone zone = new Zone(); zone.Id = zoneId; Dictionary <string, IRoom> roomPositionToRoomMap = new Dictionary <string, IRoom>(); for (int y = 0; y < rooms.GetLength(1); y++) { for (int x = 0; x < rooms.GetLength(0); x++) { if (rooms[x, y] != null) { IRoom room = new Objects.Room.Room(); room.Id = roomPositionToRoomMap.Keys.Count() + 1; room.Zone = zoneId; roomPositionToRoomMap.Add($"{x},{y}", room); zone.Rooms.Add(room.Id, room); } } } using (TextWriter tw = new StreamWriter(@"C:\temp\zone.csv")) { for (int y = 0; y < rooms.GetLength(1); y++) { for (int x = 0; x < rooms.GetLength(0); x++) { if (rooms[x, y] != null) { tw.Write(rooms[x, y]); } tw.Write(","); } tw.WriteLine(); } } for (int y = 0; y < rooms.GetLength(1); y++) { for (int x = 0; x < rooms.GetLength(0); x++) { if (rooms[x, y] != null) { Room room = rooms[x, y]; if (room != null) { IRoom zoneRoom = roomPositionToRoomMap[$"{x},{y}"]; IRoom zoneNextRoom = null; if (room.ToString().Contains("E")) { roomPositionToRoomMap.TryGetValue($"{x + 1},{y }", out zoneNextRoom); if (zoneNextRoom != null) { ZoneHelper.ConnectRoom(zoneRoom, Objects.Global.Direction.Directions.Direction.East, zoneNextRoom); } } if (room.ToString().Contains("S")) { roomPositionToRoomMap.TryGetValue($"{x },{y + 1}", out zoneNextRoom); if (zoneNextRoom != null) { ZoneHelper.ConnectRoom(zoneRoom, Objects.Global.Direction.Directions.Direction.South, zoneNextRoom); } } } } } } return(zone); }
public void Setup() { room = new Objects.Room.Room(); room.Zone = 1; }
public void Setup() { GlobalReference.GlobalValues = new GlobalValues(); fileIO = new Mock <IFileIO>(); item = new Mock <IItem>(); serializer = new Mock <ISerialization>(); settings = new Mock <ISettings>(); tagWrapper = new Mock <ITagWrapper>(); loadableItem = new Mock <ILoadableItems>(); loadPercentage = new Mock <ILoadPercentage>(); npc = new Mock <INonPlayerCharacter>(); pc = new Mock <IPlayerCharacter>(); mob = new Mock <IMobileObject>(); world = new Mock <IWorld>(); zone = new Mock <IZone>(); evnt = new Mock <IEvent>(); engine = new Mock <IEngine>(); guard = new Mock <IGuard>(); notify = new Mock <INotify>(); stringManipulator = new Mock <IStringManipulator>(); settings.Setup(e => e.VaultDirectory).Returns("vault"); serializer.Setup(e => e.Serialize(It.IsAny <List <IItem> >())).Returns("serializedList"); tagWrapper.Setup(e => e.WrapInTag(It.IsAny <string>(), TagType.Info)).Returns((string x, TagType y) => (x)); loadPercentage.Setup(e => e.Load).Returns(true); loadPercentage.Setup(e => e.Object).Returns(item.Object); npc.Setup(e => e.Stamina).Returns(10); npc.Setup(e => e.Personalities).Returns(new List <IPersonality>() { guard.Object }); npc.Setup(e => e.SentenceDescription).Returns("npc"); pc.Setup(e => e.Stamina).Returns(10); pc.Setup(e => e.KeyWords).Returns(new List <string>() { "PC" }); pc.Setup(e => e.SentenceDescription).Returns("pc"); mob.Setup(e => e.Stamina).Returns(10); mob.Setup(e => e.SentenceDescription).Returns("mob"); engine.Setup(e => e.Event).Returns(evnt.Object); guard.Setup(e => e.GuardDirections).Returns(new HashSet <Direction>() { Direction.North }); guard.Setup(e => e.BlockLeaveMessage).Returns("You can not leave."); stringManipulator.Setup(e => e.CapitalizeFirstLetter("npc")).Returns("Npc"); stringManipulator.Setup(e => e.CapitalizeFirstLetter("pc")).Returns("Pc"); stringManipulator.Setup(e => e.CapitalizeFirstLetter("mob")).Returns("Mob"); GlobalReference.GlobalValues.FileIO = fileIO.Object; GlobalReference.GlobalValues.Serialization = serializer.Object; GlobalReference.GlobalValues.Settings = settings.Object; GlobalReference.GlobalValues.TagWrapper = tagWrapper.Object; GlobalReference.GlobalValues.Engine = engine.Object; GlobalReference.GlobalValues.Notify = notify.Object; GlobalReference.GlobalValues.StringManipulator = stringManipulator.Object; room = new Objects.Room.Room(); room.Zone = 1; room.Id = 2; room.MovementCost = 1; FieldInfo fieldInfo = room.GetType().GetField("_nonPlayerCharacters", BindingFlags.Instance | BindingFlags.NonPublic); lNpc = (List <INonPlayerCharacter>)fieldInfo.GetValue(room); fieldInfo = room.GetType().GetField("_playerCharacters", BindingFlags.Instance | BindingFlags.NonPublic); lPc = (List <IPlayerCharacter>)fieldInfo.GetValue(room); fieldInfo = room.GetType().GetField("_otherMobs", BindingFlags.Instance | BindingFlags.NonPublic); lOtherMob = (List <IMobileObject>)fieldInfo.GetValue(room); fieldInfo = room.GetType().GetField("_items", BindingFlags.Instance | BindingFlags.NonPublic); lItems = (List <IItem>)fieldInfo.GetValue(room); SetupWeather(); npc.Setup(e => e.Room).Returns(room); pc.Setup(e => e.Room).Returns(room); mob.Setup(e => e.Room).Returns(room); }