/// <summary> /// Places the robot on a table top in the specified position, facing the /// specified direction. /// </summary> /// <param name="x">The X position on the table top</param> /// <param name="y">The Y position on the table top</param> /// <param name="facing">The direction to face</param> /// <param name="tableTop">The table top object to act on</param> public void Place(int x, int y, Direction facing, TableTop tableTop) { // can only place if we have a table top and a valid location if (tableTop != null && tableTop.IsValidLocation(x, y)) { currentTableTop = tableTop; currentX = x; currentY = y; currentFacing = facing; isPlaced = true; } }
static void Main(string[] args) { string command = ""; Console.WriteLine("========================================================"); Console.WriteLine(" TOY ROBOT SIMULATOR "); Console.WriteLine("========================================================"); Console.WriteLine(""); Console.WriteLine("DESCRIPTION"); Console.WriteLine(""); Console.WriteLine("- The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units."); Console.WriteLine("- There are no other obstructions on the table surface."); Console.WriteLine("- The robot is free to roam around the surface of the table"); Console.WriteLine(""); Console.WriteLine("VALID COMMAND"); Console.WriteLine(""); Console.WriteLine("- PLACE X,Y,F (Place the Robot on the Table Top)"); Console.WriteLine("- MOVE (Move the Robot 1 Unit in the Direction the Robot is facing)"); Console.WriteLine("- LEFT (Turn the Robot Left)"); Console.WriteLine("- RIGHT (Turn the Robot Right)"); Console.WriteLine("- REPORT (Show the Robot Status)"); TableTop tabletop = new TableTop(5, 5); Robot robot = new Robot(0, 0, ""); RobotCommand robotCommand = new RobotCommand(robot, tabletop); do { Console.WriteLine(""); Console.WriteLine("Please Enter Your Command"); command = Console.ReadLine().ToUpper(); if (command == "REPORT") { Console.WriteLine(robotCommand.RobotResult()); } else { robot = robotCommand.ProcessCommand(command); } } while (command != "EXIT"); }
public RobotCommand(Robot _robot, TableTop _tabletop) { robot = _robot; tabletop = _tabletop; }