예제 #1
0
        /// <summary>
        /// Add an exit to the list for a specified direction that leads to the room that is passed in.
        /// </summary>
        /// <param name="doorway">Doorway object that encapsulates the direction.</param>
        /// <param name="room">The room that the exit leads too.</param>
        /// <param name="locked">Specify if this exit is locked.</param>
        /// <param name="objectToUnlock">The name of the object that can unlock this exit.</param>
        /// <exception cref="ArgumentNullException">If the room is null, throw an ArgumentNullException.</exception>
        /// <exception cref="InvalidOperationException">If you try to map a room to the same direction twice an
        /// InvalidOperationException will be thrown.</exception>
        public void AddExit(DoorWay doorway, IRoom room, bool locked = false, string objectToUnlock = "")
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            if (!_roomMappings.ContainsKey(doorway))
            {
                _roomMappings.Add(doorway, room);
            }
            else
            {
                throw new InvalidOperationException("A room mapping already exists for the direction <" + doorway.Direction + ">.");
            }
        }
예제 #2
0
        /// <summary>
        /// Add an exit to the list for a specified direction that leads to the room that is passed in.
        /// </summary>
        /// <param name="direction">The direction to assign the exit too.</param>
        /// <param name="room">The room that the exit leads too.</param>
        /// <exception cref="ArgumentNullException">If the room is null, throw an ArgumentNullException.</exception>
        /// <exception cref="InvalidOperationException">If you try to map a room to the same direction twice an
        /// InvalidOperationException will be thrown.</exception>
        public void AddExit(Direction direction, IRoom room)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            var doorway = new DoorWay
            {
                Direction = direction,
                Locked    = false,
            };

            foreach (var entry in _roomMappings)
            {
                if (entry.Key.Direction == direction)
                {
                    throw new InvalidOperationException("A room mapping already exists for the direction <" + doorway.Direction + ">.");
                }
            }

            _roomMappings.Add(doorway, room);
        }