Esempio n. 1
0
        public static void CreateConnection(JObject jConnection, IReadOnlyDictionary <int, IRoom> rooms,
                                            out IConnection conn1, out IConnection conn2, out int roomId1, out int roomId2)
        {
            var convertLocation = new Dictionary <string, Direction>
            {
                { "NORTH", Direction.North },
                { "EAST", Direction.East },
                { "SOUTH", Direction.South },
                { "WEST", Direction.West }
            };

            var actualConnections = jConnection.Properties()
                                    .Where(jp => convertLocation.ContainsKey(jp.Name)).ToArray();

            roomId1 = actualConnections[0].Value.Value <int>();
            var location1 = convertLocation[actualConnections[0].Name];

            roomId2 = actualConnections[1].Value.Value <int>();
            var location2 = convertLocation[actualConnections[1].Name];

            IDoor connectionDoor = null;

            if (jConnection.ContainsKey("door"))
            {
                connectionDoor = DoorFactory.CreateDoor(jConnection["door"]);
            }

            conn1 = new Connection(location1, rooms[roomId1], connectionDoor);
            conn2 = new Connection(location2, rooms[roomId2], connectionDoor);
        }
Esempio n. 2
0
        private static IDoor GetConnectionDoor(JObject jConnection)
        {
            if (jConnection.ContainsKey("door"))
            {
                return(DoorFactory.CreateDoor(jConnection["door"]));
            }

            if (jConnection.ContainsKey("ladder"))
            {
                return(DoorFactory.CreateLadder());
            }

            return(null);
        }