Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnGoTen_Click(object sender, EventArgs e)
- {
- if (isValidDirection())
- if (robot.Direction == "N")
- robot.Y -= 10;
- if (robot.Direction == "E")
- robot.X -= 10;
- if (robot.Direction == "S")
- robot.Y += 10;
- if (robot.Direction == "W")
- robot.X += 10;
- lblPosition.Text = robot.GetFormattedLocation();
- lblRobotLoc.Location = new Point(robot.X, robot.Y);
- }
- private void btnNorth_Click(object sender, EventArgs e)
- {
- robot.Direction = "N";
- }
- private void btnEast_Click(object sender, EventArgs e)
- {
- robot.Direction = "E";
- }
- private void btnSouth_Click(object sender, EventArgs e)
- {
- robot.Direction = "S";
- }
- private void btnWest_Click(object sender, EventArgs e)
- {
- robot.Direction = "W";
- }
- public class Robot
- {
- //fields
- private int x;
- private int y;
- private string direction;
- public Robot()
- {
- x = 0;
- y = 0;
- direction = "N";
- }
- public int X
- {
- get { return x; }
- set { x = value; }
- }
- public int Y
- {
- get { return y; }
- set { y = value; }
- }
- public string Direction
- {
- get { return direction; }
- set { direction = value; }
- }
- public string GetFormattedLocation()
- {
- string locationString = "{X=" + Convert.ToString(x) + ",Y=" + Convert.ToString(y) + "}";
- return locationString;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement