Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. private void btnGoTen_Click(object sender, EventArgs e)
  2. {
  3. if (isValidDirection())
  4. if (robot.Direction == "N")
  5. robot.Y -= 10;
  6. if (robot.Direction == "E")
  7. robot.X -= 10;
  8. if (robot.Direction == "S")
  9. robot.Y += 10;
  10. if (robot.Direction == "W")
  11. robot.X += 10;
  12. lblPosition.Text = robot.GetFormattedLocation();
  13. lblRobotLoc.Location = new Point(robot.X, robot.Y);
  14. }
  15.  
  16. private void btnNorth_Click(object sender, EventArgs e)
  17. {
  18. robot.Direction = "N";
  19. }
  20.  
  21. private void btnEast_Click(object sender, EventArgs e)
  22. {
  23. robot.Direction = "E";
  24. }
  25.  
  26. private void btnSouth_Click(object sender, EventArgs e)
  27. {
  28. robot.Direction = "S";
  29. }
  30.  
  31. private void btnWest_Click(object sender, EventArgs e)
  32. {
  33. robot.Direction = "W";
  34. }
  35.  
  36. public class Robot
  37. {
  38. //fields
  39. private int x;
  40. private int y;
  41. private string direction;
  42.  
  43. public Robot()
  44. {
  45. x = 0;
  46. y = 0;
  47. direction = "N";
  48. }
  49.  
  50.  
  51. public int X
  52. {
  53. get { return x; }
  54. set { x = value; }
  55. }
  56.  
  57. public int Y
  58. {
  59. get { return y; }
  60. set { y = value; }
  61. }
  62.  
  63. public string Direction
  64. {
  65. get { return direction; }
  66. set { direction = value; }
  67. }
  68.  
  69. public string GetFormattedLocation()
  70. {
  71. string locationString = "{X=" + Convert.ToString(x) + ",Y=" + Convert.ToString(y) + "}";
  72. return locationString;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement