Exemplo n.º 1
0
        public static Room GetDestinationLocation(Player player, MovementPath movementPath)
        {
            var playerOrigin = GetPlayerOriginFromContext();
            var location     = new Room {
                Coordinates = playerOrigin.Coordinates, RoomExits = playerOrigin.RoomExits
            };

            foreach (var step in movementPath.Steps)
            {
                switch (step.Key)
                {
                case "N":
                    location = location.GetRoomInDirectionOf(ExitTemplate.North);
                    break;

                case "S":
                    location = location.GetRoomInDirectionOf(ExitTemplate.South);
                    break;

                case "E":
                    location = location.GetRoomInDirectionOf(ExitTemplate.East);
                    break;

                case "W":
                    location = location.GetRoomInDirectionOf(ExitTemplate.West);
                    break;
                }
            }

            return(location);
        }
Exemplo n.º 2
0
        public static MovementPath ParseMovement(string expectedMovement)
        {
            var steps = expectedMovement.Split(new[] { '|' }, 2);
            var path  = new MovementPath();

            foreach (var step in steps)
            {
                var direction = step.Substring(0, 1);
                var distance  = Convert.ToInt32(step.Substring(1, 1));
                path.Steps.Add(new KeyValuePair <string, int>(direction, distance));
            }

            return(path);
        }