Example #1
0
        private void Move(string direction)
        {
            if (string.IsNullOrEmpty(direction))
            {
                throw new ArgumentException("Direction cannot be null of empty.");
            }

            if (direction.Equals("up"))
            {
                CurrentLocation = new DungeonPosition(CurrentLocation.X, CurrentLocation.Y + 1);
            }
            else if (direction.Equals("down"))
            {
                CurrentLocation = new DungeonPosition(CurrentLocation.X, CurrentLocation.Y - 1);
            }
            else if (direction.Equals("left"))
            {
                CurrentLocation = new DungeonPosition(CurrentLocation.X - 1, CurrentLocation.Y);
            }
            else if (direction.Equals("right"))
            {
                CurrentLocation = new DungeonPosition(CurrentLocation.X + 1, CurrentLocation.Y);
            }
            else
            {
                throw new ArgumentException("The string that was passed-in is not a direction.");
            }
        }
Example #2
0
        public override string DoAction()
        {
            DungeonPosition pos  = ((PlayerCharacter)(Character)).Room.Position;
            int             x    = pos.X;
            int             y    = pos.Y;
            DungeonRoom     room = Character.Dungeon.GetRoom(pos.X, pos.Y);
            DungeonRoom     NewRoom;

            //room.RemoveCharacter(Character);
            switch (direction)
            {
            case MapDirection.north:
                y -= 1;
                break;

            case MapDirection.south:
                y += 1;
                break;

            case MapDirection.east:
                x += 1;
                break;

            case MapDirection.west:
                x -= 1;
                break;
            }
            foreach (MudCharacter c in Character.Room.GetCharactersInRoom())
            {
                if (!(c is PlayerCharacter))
                {
                    return("Some sort of magic barrier prevents you from leaving a room with live evil minions");
                }
            }
            NewRoom = Character.Dungeon.GetRoom(x, y);
            if (NewRoom == null)
            {
                return(String.Format("{0} ran into the wall", Character.Name));
            }
            room.NotifyPlayers(Character.Name + " has left the room heading " + MoveAction.DirectionString[(int)direction]);
            room.RemoveCharacter(Character);
            NewRoom.AddCharacter(Character);
            return("");
        }