示例#1
0
        public static void Display(this Plateau plateau)
        {
            Contract.Requires <ArgumentNullException>(plateau != null, "plateau");

            "Plateau: {0,2} x {1,2}"
            .ApplyFormat(plateau.Size.Width, plateau.Size.Height)
            .Display(ConsoleColor.Yellow);

            plateau.Rovers.ForEach(Display);

            "Total {0} Rover(s)\r\n"
            .ApplyFormat(plateau.Rovers.Count)
            .Display(ConsoleColor.Yellow);
        }
示例#2
0
文件: Rover.cs 项目: timnew/MarsRover
 internal Rover(Plateau plateau, Point postion, Orientation orientation)
 {
     this.Plateau     = plateau;
     this.Orientation = orientation;
     this.Position    = postion;
 }
        public Plateau InitializeScenario(IObservable <TimeSlice> timer, Plateau target = null)
        {
            if (target == null)
            {
                target = new Plateau();
            }
            else
            {
                target.Reset();
            }

            var sizeTuple =
                UserInputHelper.Query
                (
                    UserInputHelper.CreateToTuple <int, int>(int.TryParse, int.TryParse),
                    "Input Plateau Size(width height): ",
                    input: InputSource
                );

            target.SetSize(sizeTuple.Item1, sizeTuple.Item2);

            var roverTupleFactory = UserInputHelper.CreateToTuple <int, int, char>(int.TryParse, int.TryParse, char.TryParse);

            int roverIndex = 0;

            while (true)
            {
                roverIndex++;

                var roverTulpe =
                    UserInputHelper.Query
                    (
                        roverTupleFactory,
                        "Initial State of Rover {0,2} (x y orientation): ".ApplyFormat(roverIndex),
                        true,
                        InputSource
                    );

                if (roverTulpe == null)
                {
                    break;
                }

                var roverInstructions =
                    UserInputHelper.QueryString
                    (
                        "Instructions for Rover {0,2} : ".ApplyFormat(roverIndex),
                        true,
                        InputSource
                    );

                if (roverInstructions == null)
                {
                    break;
                }

                target
                .DeployRover(roverTulpe.Item1, roverTulpe.Item2, roverTulpe.Item3)
                .SetInstruction(roverInstructions, timer);
            }

            return(target);
        }