/// <summary> /// Moves the robot forwards one space in the current direction /// </summary> public void Move() { // cannot move if robot has not been placed if (isPlaced) { // determine new location int newX = currentX; int newY = currentY; switch (currentFacing) { case Direction.NORTH: newY++; break; case Direction.EAST: newX++; break; case Direction.SOUTH: newY--; break; case Direction.WEST: newX--; break; } // only allow move to a valid location if (currentTableTop.IsValidLocation(newX, newY)) { currentX = newX; currentY = newY; } } }
/// <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; } }