public void RunAllRovers() { MarsRover[] marsRovers = new MarsRover[this.MarsRovers.Values.Count]; this.MarsRovers.Values.CopyTo(marsRovers, 0); foreach (MarsRover marsRover in marsRovers) { marsRover.Run(marsRover.InitialCommandInstructions); } }
private void CreateInstanceofRoversAndAddToMarshPlateu() { foreach (MarsRoverInstructions roverCommand in MarsRoversCommands) { MarsRover marsRover = MarsRover.CreateRover(roverCommand.RoverPosition, this.marsPlateu); marsRover.InitialCommandInstructions = roverCommand.CommandInstructions; this.marsPlateu.AddRover(marsRover); } }
public static MarsRover CreateRover(MarsRoverPosition roverPostion, MarsPlateu marsPlateu) { MarsRover marsRover = new MarsRover(); marsRover.MarsPlateu = marsPlateu; marsRover.CurrentPositionXCoOridante = roverPostion.CurrentPositionXCoOridante; marsRover.CurrentPositionYCoOrdinate = roverPostion.CurrentPositionYCoOrdinate; marsRover.CurrentDirectionOfRover = roverPostion.CurrentDirectionOfRover; marsRover.PreviousPositionXCoOridante = marsRover.CurrentPositionXCoOridante; marsRover.PreviousPositionYCoOrdinate = marsRover.CurrentPositionYCoOrdinate; marsRover.PrevioustDirectionOfRover = marsRover.CurrentDirectionOfRover; return(marsRover); }
public void Run(IList <RoverCommand> commands) { foreach (var command in commands) { switch (command) { case RoverCommand.Left: this.TurnLeft(); break; case RoverCommand.Right: this.TurnRight(); break; case RoverCommand.Move: this.MoveRover(); break; } } if (!this.MarsPlateu.MarsRovers.ContainsKey(this.CurrentPostionToString())) { this.MarsPlateu.MarsRovers.Add(this.CurrentPostionToString(), this); this.MarsPlateu.MarsRovers.Remove(this.CurrentPostionToString()); } else { MarsRover existingMarsRoverInPlateu = this.MarsPlateu.MarsRovers[this.CurrentPostionToString()]; if (existingMarsRoverInPlateu.PreviousPostionAndDirectionToString() != this.PreviousPostionAndDirectionToString()) { this.CurrentPositionXCoOridante = this.PreviousPositionXCoOridante; this.CurrentPositionYCoOrdinate = this.PreviousPositionYCoOrdinate; this.CurrentDirectionOfRover = this.PrevioustDirectionOfRover; } } }
public void AddRover(MarsRover marsRover) { this.MarsRovers.Add(marsRover.CurrentPostionToString(), marsRover); }