| | |
direct robot
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
OK we stick to your assignment but use this modified enumeration:
c# Syntax (Toggle Plain Text)
// fill in your codes here I don't know the exact ones // it is better to use Direction.North than 231 or whatever public enum Direction { North = 231, West = 232, South = 233, East = 234 }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
•
•
•
•
OK we stick to your assignment but use this modified enumeration:
c# Syntax (Toggle Plain Text)
// fill in your codes here I don't know the exact ones // it is better to use Direction.North than 231 or whatever public enum Direction { North = 231, West = 232, South = 233, East = 234 }
I figured to upload the general idea of what I'm to do if that helps any. I'll keep stabbing away at my form and see if I can get any of the buttons to work.
I already seem to have filled in a great deal of your assignment, before I even read it! Now don't start thinking I am some kind of genius guru, I am not
Try to make something out of your form right now. It is getting very late over here see ya tomorrow! Succes!
Try to make something out of your form right now. It is getting very late over here see ya tomorrow! Succes! Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
Ok updated my code a bit:
robot.cs
I don't know what I'm doing wrong with the location temp = arrowLlb.Location code, it gives me an error about "location" couldn't be found, blah blah. Tired to ask my friend and he wasn't much help signed off on me lol.
robot.cs
C# Syntax (Toggle Plain Text)
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 SimpleRobotForm { public partial class RobotForm : Form { public RobotForm() { InitializeComponent(); } private void RobotForm_Load(object sender, EventArgs e) { } private void northBtn_Click(object sender, EventArgs e) { } private void westBtn_Click(object sender, EventArgs e) { } private void eastBtn_Click(object sender, EventArgs e) { } private void go1Btn_Click(object sender, EventArgs e) { location temp = arrowLlb.Location; temp.X = arrowLlb.Location.X - 1; temp.Y = arrowLlb.Location.Y - 1; arrowLlb.Location = temp; } private void go10Btn_Click(object sender, EventArgs e) { location temp = arrowLlb.Location; temp.X = arrowLlb.Location.X - 10; temp.Y = arrowLlb.Location.Y - 10; arrowLlb.Location = temp; } private void exitBtn_Click(object sender, EventArgs e) { this.Close(); } private void southBtn_Click_1(object sender, EventArgs e) { } private void pointer_Click(object sender, EventArgs e) { } } }
C# Syntax (Toggle Plain Text)
private void go1Btn_Click(object sender, EventArgs e) { location temp = arrowLlb.Location; temp.X = arrowLlb.Location.X - 1; temp.Y = arrowLlb.Location.Y - 1; arrowLlb.Location = temp; } private void go10Btn_Click(object sender, EventArgs e) { location temp = arrowLlb.Location; temp.X = arrowLlb.Location.X - 10; temp.Y = arrowLlb.Location.Y - 10; arrowLlb.Location = temp; }
The things you do sugest you are doing some effort, that is good!
I give you my start of the solution, hope you learn from it.
It is commented here and there, if you have questions : ask.
The robot class:
The forms class:
You should fill in the right codes in the enum, add the other direction and go buttons. Should be easy by now
Also included a picture of what my form looks like.
As you can see it is not much. I usually work that way: begin small, see if it works and then add more things. Good luck!
I give you my start of the solution, hope you learn from it.
It is commented here and there, if you have questions : ask.
The robot class:
c# Syntax (Toggle Plain Text)
namespace simple_robot { // fill in your codes here I don't know the exact ones // it is better to use Direction.North than 231 or whatever // on my system the code for arrow north is 233 and not 231 // try to figure out the rest of the codes for yourself public enum Direction //can define an enum outside a class, thanks Scott!!! { North = 231, West = 232, South = 233, East = 234 } class robot { // your assignment says this has to be a public field instead of // a property, so here it is. public Direction direction; public robot() // Default constructor { location = new Point(); // Sets location.X=0 and location.Y=0 direction = Direction.North; } // commented out: direction is now a public field and no property anymore //public Direction direction { get; set; } 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; } // TO DO: // to be changed by something like this // public void Draw(Panel P) public void Draw(Graphics G) { // Our robot will look like a red ball // but you could draw anything here SolidBrush redBrush = new SolidBrush(Color.Red); Size S = new Size(40,40); Rectangle R = new Rectangle(location, S); // Make a red ball size 40,40 and put it at location G.FillEllipse(redBrush, R); } // we override the ToString method // and return a text for the label that represents the robot // perhaps not the best way to do it, but it works. public override string ToString() { // direction is an enum and used as an ASCII code, // we cast it to a char and make it into a string return ((char)direction).ToString(); } } }
The forms class:
c# Syntax (Toggle Plain Text)
using System; using System.Windows.Forms; namespace simple_robot { public partial class Form1 : Form { private robot Robby = new robot(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // will set Robby pointing North // because it is initialized as such in the constructor robotLbl.Text = Robby.ToString(); // this is all we need to get {X=0,Y=0} on the screen positionLbl.Text = Robby.location.ToString(); } private void northBtn_Click(object sender, EventArgs e) { // set direction of the robot to north Robby.direction = Direction.North; // turn Robby in the right direction, so set the label robotLbl.Text = Robby.ToString(); } private void go1Btn_Click(object sender, EventArgs e) { Robby.Move(1); // adjust position info positionLbl.Text = Robby.location.ToString(); } } }
You should fill in the right codes in the enum, add the other direction and go buttons. Should be easy by now

Also included a picture of what my form looks like.
As you can see it is not much. I usually work that way: begin small, see if it works and then add more things. Good luck!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
Thank you again for the example coding. I looked at it and reread through my book and made a lot more sense. I have managed to get a working robot, and saw where I've been going wrong, did define certain objects in the form, and set certain things to string.
I did borrow the override method, its more functional then having to convert each single string to the WingDings arrow via Uni-code or char value, I can see though where it might cause problems for other project uses.
Being I have to limit the movement to 100< any direction and if it goes 101> or higher show a messagebox, would I use standard validation, that is what I'm guess and playing with.
I did borrow the override method, its more functional then having to convert each single string to the WingDings arrow via Uni-code or char value, I can see though where it might cause problems for other project uses.
Being I have to limit the movement to 100< any direction and if it goes 101> or higher show a messagebox, would I use standard validation, that is what I'm guess and playing with.
First let's add a Panel to the Form. I called mine roboworldPnl and gave it a Size of 200,200. Now drop the robotlabel on to it.
The robot no longer lives on the form but on the panel now.
These are the methods I changed:
You see, I always try to move in small steps and see if they work.
This is far from perfect but we will get there. I know the positionLbl is not working correctly but we'll fix that. I also expect an answer from you to the question I posed in the Draw method.
The robot no longer lives on the form but on the panel now.
These are the methods I changed:
c# Syntax (Toggle Plain Text)
// TO DO: // to be changed by something like this public void Draw(Panel P) { // coordinate translation // can you explain why this is needed? Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2); // because we dropped one control on the panel // we know that the first control in the Controls collection // of the Panel Controls[0] must be our robot label P.Controls[0].Location = L; }
c# Syntax (Toggle Plain Text)
private void go1Btn_Click(object sender, EventArgs e) { Robby.Move(1); Robby.Draw(roboworldPnl); //added, change the other go button also // adjust position info positionLbl.Text = Robby.location.ToString(); }
c# Syntax (Toggle Plain Text)
private void Form1_Load(object sender, EventArgs e) { // will set Robby pointing North // because it is initialized as such in the constructor robotLbl.Text = Robby.ToString(); // Draw Robby for the first time Robby.Draw(roboworldPnl); // this is all we need to get {X=0,Y=0} on the screen positionLbl.Text = Robby.location.ToString(); }
This is far from perfect but we will get there. I know the positionLbl is not working correctly but we'll fix that. I also expect an answer from you to the question I posed in the Draw method.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
C# Syntax (Toggle Plain Text)
// can you explain why this is needed? Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2);
I see it creating and making the arrow go in the direction N/S/W/E and then when the Go1\G10 is clicked animates the arrow (moves it to) the new postion depending on Go1\Go10.
That how I see it working.
Well, not quite. It transforms the coordinate system of the Panel.
Normally point (0,0) is at the top,left corner of the Panel, just like it is in a Form. By using this transformation you put the point (0,0) or (X,Y) at the center of the Panel, the place where your robot comes alive.
Try to leave P.Width/2 out and see what happens!
Normally point (0,0) is at the top,left corner of the Panel, just like it is in a Form. By using this transformation you put the point (0,0) or (X,Y) at the center of the Panel, the place where your robot comes alive.
Try to leave P.Width/2 out and see what happens!
Last edited by ddanbe; Sep 27th, 2009 at 4:02 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
•
•
•
•
Well, not quite. It transforms the coordinate system of the Panel.
Normally point (0,0) is at the top,left corner of the Panel, just like it is in a Form. By using this transformation you put the point (0,0) or (X,Y) at the center of the Panel, the place where your robot comes alive.
Try to leave P.Width/2 out and see what happens!
And tested with out the P.Width/2 it shoves it all the way to the left. meaning that the Height and Width control the center point of the arrow.
Does the Panel have any special validation, like a TimeDate Controler has? I'm just playing around with validation to see if I can limit the movement to 100 any direction and get a message to come up.
![]() |
Similar Threads
- Game: Robots (Class, Constructors, etc.) (C++)
- Python for Laptop Robot Speech recognition and TTS. (Python)
- Siebel Systems Engineer needed (Tech / IT Consultant Job Offers)
- News Story: Linux Powered Robot Dog (Linux Servers and Apache)
- Slow CPU causes damage to robot (C)
- direct X version problems (Windows 95 / 98 / Me)
- Direct CD: PC to Mac (Mac Software)
Other Threads in the C# Forum
- Previous Thread: auto scaling in web application
- Next Thread: Controls added to panel are moving down when repainted
Views: 2081 | Replies: 26
| Thread Tools | Search this Thread |
Tag cloud for c#, directrobot, form, robot
.net access analyst array asp.net basic button buttons c# calendar chat check class client code combobox data database date datetime dbconnection default development dialog dll dom drawing email enter eventhandlers excel expression feedback file files form forms gdi+ hardware html httpwebrequest index java javascript linux lisp list listbox login marshalbyrefobject math mdd messenger msword mysql news open operator oracle packaging panel photoshop php picturebox post printer programming remote remoting resource richtextbox robot saving smoobjects softwaredevelopment sql sql-server ssh statistics string study table tcpclientchannel textbox timer totaldays treeview upload uploadatextfile validation vb video vistaflaw visual visualbasic visualbasic6 webbrowser window winforms wpf







