Hi, been working on this project and just confusing the heck out of myself.
My project is

Operation
•   This project simulates a simple robot that can move a given direction and distance.
•   To determine the direction the robot will move, the user clicks the N (North), S (South), E (East), or W (West) button.
•   The robot is displayed as an arrow that points in the currently selected direction.
•   The user can move the robot 1 or 10 units in the selected direction by clicking the Go 1 or Go 10 button.
•   The robot’s current X, Y position is displayed in a label at the top of the form.
Specifications
•   Create a class called Robot that has a method that causes the robot to move, a public field that contains the current direction, and a property that returns the robot’s current position as a Point structure. When the robot is instantiated, the position should be set to 0, 0 (the center) and the direction should be set to North.
•   Limit the range of the robot to 100 units in any direction. If the user attempts to move the robot beyond this range, the Robot class should raise an event. The application should respond to this event by displaying an appropriate message. 
Hints
•   The easiest way to create the moving arrow is to use a label control. Then, the program can adjust the control’s Position property to move the arrow within a panel control. If you need to, you can use online help to research this control.
•   To create the arrow, set the label’s Font property to the Wingdings font. Then, you can use the int values 231 through 234 to set the label to the appropriate arrow

Click Here
I'm really just confused on how to do all of this.

Recommended Answers

All 7 Replies

Place a panel in your form, set the position and size of the panel which you want to set as limit, and in that panel use a picture box control add an arrow in it. Now place your labels outside the panel and add the x and y values as text in that ...... now when user press N the add one point to y at each press unless the limit reaches that is the upper limit of your panel, and when user press S minu one point from y of picture box at each change also check the values of x and y and update you labels..... same as with E and W..... on pressing W subtract one point and on pressing E add one point to the x value of picturebox

or as you want instead of picturebox use the label containing arrow

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 ![Robot](/attachments/large/3/Robot.png "Robot")  ![Robot1](/attachments/small/3/Robot1.png "align-left") 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

    private void btnGo10_Click(object sender, EventArgs e)
    {
        Robby.Move(10);
        Robby.Draw(pnlRobot);
        lblPosition.Text = Robby.location.ToString();
    }

I figured out how to fix the arrows direction problem. Now the biggest problem I have is gettting the right numbers to show up on my position label and also to make it so that if the robot tries to go past 100 units that a message pops up

I know that I need to make it so that the Y cord's sign fliips.. but iI'm not sure how

I'm still having issues with the validation of the location. (making it so that the robot cant go outside the range of 100). Also fixing the Y cord so that the numbers come out correctly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.