static void Main(string[] args) { // create planet int width = captureInt("input width of planet (any positive value):", 0); int height = captureInt("input height of planet (any positive value):", 0); var surface = new Grid(width, height); int deathCount = 0; while (true) { //create robot int x = captureInt("input x co-ordinate of robot landing site (positive value within the width):", 0, width); int y = captureInt("input y co-ordinate of robot landing site (positive value within the height):", 0, height); Bearing orientation = Bearing.North; switch (captureChar("Press n, s, e or w for facing direction of robot (North, South, East or West) - Case Sensitive:", new char[] {'n', 's', 'e', 'w'})) { case 'n': orientation = Bearing.North; break; case 's': orientation = Bearing.South; break; case 'e': orientation = Bearing.East; break; case 'w': orientation = Bearing.West; break; } var martianRobot = new Robot(new Coordinates(x, y), orientation); Console.WriteLine("Enter command sequence using the commands left (L), right (R) and forward (F) - All others will be disregarded"); string commandSequence = Console.ReadLine().ToUpper(); //Kills the sequence if the robot is lost - processor efficient, to be memory efficient, optimal strategy would probably be to make a second //surface location comparison using onGrid() method bool terminateSequence = false; foreach (char c in commandSequence) { switch (c) { case 'L': martianRobot.Left(); break; case 'R': martianRobot.Right(); break; case 'F': if (!surface.onGrid(martianRobot.Forward())) { terminateSequence = true; Robot.lostRobot(martianRobot); Console.WriteLine("LOST"); } break; } if(terminateSequence == true) { break; } } int nextStep = captureInt("Select next action: (0) continue perilous robotic deployments to Mars (1) terminate funding for ESA's fruitless endeavours", 0, 1); if (nextStep == 1) { break; } } Console.WriteLine("Terminated ESA's funding... Future generations will never learn of Mars' strange geometric surface and the dangers there in... Press any key to close"); Console.ReadKey(); }
public static void lostRobot(Robot lostRobot) { scents.Add(lostRobot.position); }