This is what I have so far
robot.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Direct_Simple_Robot
{
public enum Direction
{
North = 231,
West = 232,
South = 233,
East = 234
}
class robot
{
public Direction direction;
public robot() // Default constructor
{
location = new Point(); // Sets location.X=0 and location.Y=0
direction = Direction.North;
}
public Point location { get; set; }
public void Move(int unitToMove)
{
Point P = new Point();
switch (direction)
{
case Direction.North:
P.X = location.X;
P.Y = location.Y - unitToMove;
break;
case Direction.West:
P.X = location.X - unitToMove;
P.Y = location.Y;
break;
case Direction.South:
P.X = location.X;
P.Y = location.Y + unitToMove;
break;
case Direction.East:
P.X = location.X + unitToMove;
P.Y = location.Y;
break;
default:
break;
}
location = P;
}
public void Draw(Panel P)
{
Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2);
P.Controls[0].Location = L;
}
public override string ToString()
{
return ((char)direction).ToString();
}
}
}
mainform
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Direct_Simple_Robot
{
public partial class Form1 : Form
{
private robot Robby = new robot();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
lblRobot.Text = Robby.ToString();
Robby.Draw(pnlRobot);
lblPosition.Text = Robby.location.ToString();
}
private void BtnGo1_Click(object sender, EventArgs e)
{
Robby.Move(1);
Robby.Draw(pnlRobot);
lblPosition.Text = Robby.location.ToString();
}
private void btn   Go10_Click(object sender, EventArgs e)
{
Robby.Move(10);
Robby.Draw(pnlRobot);
lblPosition.Text = Robby.location.ToString();
}
private void BtnN_Click(object sender, EventArgs e)
{
Robby.direction = Direction.North;
lblRobot.Text = Robby.ToString();
}
private void btnE_Click(object sender, EventArgs e)
{
Robby.direction = Direction.East;
lblRobot.Text = Robby.ToString();
}
private void btnS_Click(object sender, EventArgs e)
{
Robby.direction = Direction.South;
lblRobot.Text = Robby.ToString();
}
private void btnW_Click(object sender, EventArgs e)
{
Robby.direction = Direction.West;
lblRobot.Text = Robby.ToString();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
For some reason my arrow is pointing the wrong way
I need to limit the range
and somehow fix the x/y position label at the top