direct robot

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: direct robot

 
0
  #11
Sep 25th, 2009
OK we stick to your assignment but use this modified enumeration:
  1. // fill in your codes here I don't know the exact ones
  2. // it is better to use Direction.North than 231 or whatever
  3. public enum Direction
  4. {
  5. North = 231,
  6. West = 232,
  7. South = 233,
  8. East = 234
  9. }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 77
Reputation: EvilLinux is an unknown quantity at this point 
Solved Threads: 0
EvilLinux EvilLinux is offline Offline
Junior Poster in Training

Re: direct robot

 
0
  #12
Sep 25th, 2009
Originally Posted by ddanbe View Post
OK we stick to your assignment but use this modified enumeration:
  1. // fill in your codes here I don't know the exact ones
  2. // it is better to use Direction.North than 231 or whatever
  3. public enum Direction
  4. {
  5. North = 231,
  6. West = 232,
  7. South = 233,
  8. East = 234
  9. }
Ok I'm following you on this now its making sense. I'll handle the number once I can figure what they show us as. My forms a mess at the moment lol.
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.
Attached Files
File Type: doc robot.doc (29.0 KB, 8 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: direct robot

 
0
  #13
Sep 25th, 2009
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!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 77
Reputation: EvilLinux is an unknown quantity at this point 
Solved Threads: 0
EvilLinux EvilLinux is offline Offline
Junior Poster in Training

Re: direct robot

 
0
  #14
Sep 26th, 2009
Ok updated my code a bit:

robot.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace SimpleRobotForm
  11. {
  12. public partial class RobotForm : Form
  13. {
  14.  
  15. public RobotForm()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20.  
  21. private void RobotForm_Load(object sender, EventArgs e)
  22. {
  23.  
  24. }
  25.  
  26. private void northBtn_Click(object sender, EventArgs e)
  27. {
  28.  
  29. }
  30.  
  31. private void westBtn_Click(object sender, EventArgs e)
  32. {
  33.  
  34. }
  35.  
  36. private void eastBtn_Click(object sender, EventArgs e)
  37. {
  38.  
  39. }
  40.  
  41. private void go1Btn_Click(object sender, EventArgs e)
  42. {
  43. location temp = arrowLlb.Location;
  44. temp.X = arrowLlb.Location.X - 1;
  45. temp.Y = arrowLlb.Location.Y - 1;
  46. arrowLlb.Location = temp;
  47. }
  48.  
  49. private void go10Btn_Click(object sender, EventArgs e)
  50. {
  51. location temp = arrowLlb.Location;
  52. temp.X = arrowLlb.Location.X - 10;
  53. temp.Y = arrowLlb.Location.Y - 10;
  54. arrowLlb.Location = temp;
  55. }
  56.  
  57. private void exitBtn_Click(object sender, EventArgs e)
  58. {
  59. this.Close();
  60. }
  61.  
  62. private void southBtn_Click_1(object sender, EventArgs e)
  63. {
  64.  
  65. }
  66.  
  67. private void pointer_Click(object sender, EventArgs e)
  68. {
  69.  
  70. }
  71. }
  72. }

  1. private void go1Btn_Click(object sender, EventArgs e)
  2. {
  3. location temp = arrowLlb.Location;
  4. temp.X = arrowLlb.Location.X - 1;
  5. temp.Y = arrowLlb.Location.Y - 1;
  6. arrowLlb.Location = temp;
  7. }
  8.  
  9. private void go10Btn_Click(object sender, EventArgs e)
  10. {
  11. location temp = arrowLlb.Location;
  12. temp.X = arrowLlb.Location.X - 10;
  13. temp.Y = arrowLlb.Location.Y - 10;
  14. arrowLlb.Location = temp;
  15. }
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: direct robot

 
0
  #15
Sep 26th, 2009
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:
  1. namespace simple_robot
  2. {
  3. // fill in your codes here I don't know the exact ones
  4. // it is better to use Direction.North than 231 or whatever
  5. // on my system the code for arrow north is 233 and not 231
  6. // try to figure out the rest of the codes for yourself
  7. public enum Direction //can define an enum outside a class, thanks Scott!!!
  8. {
  9. North = 231,
  10. West = 232,
  11. South = 233,
  12. East = 234
  13. }
  14.  
  15. class robot
  16. {
  17. // your assignment says this has to be a public field instead of
  18. // a property, so here it is.
  19. public Direction direction;
  20.  
  21. public robot() // Default constructor
  22. {
  23. location = new Point(); // Sets location.X=0 and location.Y=0
  24. direction = Direction.North;
  25. }
  26.  
  27. // commented out: direction is now a public field and no property anymore
  28. //public Direction direction { get; set; }
  29. public Point location { get; set; }
  30.  
  31. public void Move(int unitToMove)
  32. {
  33. Point P = new Point();
  34.  
  35. switch (direction)
  36. {
  37. case Direction.North:
  38. P.X = location.X;
  39. P.Y = location.Y - unitToMove;
  40. break;
  41. case Direction.West:
  42. P.X = location.X - unitToMove;
  43. P.Y = location.Y;
  44. break;
  45. case Direction.South:
  46. P.X = location.X;
  47. P.Y = location.Y + unitToMove;
  48. break;
  49. case Direction.East:
  50. P.X = location.X + unitToMove;
  51. P.Y = location.Y;
  52. break;
  53. default:
  54. break;
  55. }
  56. location = P;
  57. }
  58.  
  59. // TO DO:
  60. // to be changed by something like this
  61. // public void Draw(Panel P)
  62. public void Draw(Graphics G)
  63. {
  64. // Our robot will look like a red ball
  65. // but you could draw anything here
  66. SolidBrush redBrush = new SolidBrush(Color.Red);
  67. Size S = new Size(40,40);
  68. Rectangle R = new Rectangle(location, S);
  69. // Make a red ball size 40,40 and put it at location
  70. G.FillEllipse(redBrush, R);
  71. }
  72.  
  73. // we override the ToString method
  74. // and return a text for the label that represents the robot
  75. // perhaps not the best way to do it, but it works.
  76. public override string ToString()
  77. {
  78. // direction is an enum and used as an ASCII code,
  79. // we cast it to a char and make it into a string
  80. return ((char)direction).ToString();
  81. }
  82. }
  83. }

The forms class:
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace simple_robot
  5. {
  6. public partial class Form1 : Form
  7. {
  8. private robot Robby = new robot();
  9.  
  10. public Form1()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15. private void Form1_Load(object sender, EventArgs e)
  16. {
  17. // will set Robby pointing North
  18. // because it is initialized as such in the constructor
  19. robotLbl.Text = Robby.ToString();
  20. // this is all we need to get {X=0,Y=0} on the screen
  21. positionLbl.Text = Robby.location.ToString();
  22. }
  23.  
  24. private void northBtn_Click(object sender, EventArgs e)
  25. {
  26. // set direction of the robot to north
  27. Robby.direction = Direction.North;
  28. // turn Robby in the right direction, so set the label
  29. robotLbl.Text = Robby.ToString();
  30. }
  31.  
  32. private void go1Btn_Click(object sender, EventArgs e)
  33. {
  34. Robby.Move(1);
  35. // adjust position info
  36. positionLbl.Text = Robby.location.ToString();
  37. }
  38. }
  39. }

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!
Attached Thumbnails
robotForm.jpg  
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 77
Reputation: EvilLinux is an unknown quantity at this point 
Solved Threads: 0
EvilLinux EvilLinux is offline Offline
Junior Poster in Training

Re: direct robot

 
0
  #16
Sep 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: direct robot

 
0
  #17
Sep 27th, 2009
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:
  1. // TO DO:
  2. // to be changed by something like this
  3. public void Draw(Panel P)
  4. {
  5. // coordinate translation
  6. // can you explain why this is needed?
  7. Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2);
  8. // because we dropped one control on the panel
  9. // we know that the first control in the Controls collection
  10. // of the Panel Controls[0] must be our robot label
  11. P.Controls[0].Location = L;
  12. }
  1. private void go1Btn_Click(object sender, EventArgs e)
  2. {
  3. Robby.Move(1);
  4. Robby.Draw(roboworldPnl); //added, change the other go button also
  5. // adjust position info
  6. positionLbl.Text = Robby.location.ToString();
  7. }
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. // will set Robby pointing North
  4. // because it is initialized as such in the constructor
  5. robotLbl.Text = Robby.ToString();
  6. // Draw Robby for the first time
  7. Robby.Draw(roboworldPnl);
  8. // this is all we need to get {X=0,Y=0} on the screen
  9. positionLbl.Text = Robby.location.ToString();
  10. }
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 77
Reputation: EvilLinux is an unknown quantity at this point 
Solved Threads: 0
EvilLinux EvilLinux is offline Offline
Junior Poster in Training

Re: direct robot

 
0
  #18
Sep 27th, 2009
  1. // can you explain why this is needed?
  2. Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2);
It controls the current location of the Robot, and I believe because we the panel is set to 200,200 the P.width is dived by 2 so technically the Panel is really 100,100?
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: direct robot

 
0
  #19
Sep 27th, 2009
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!
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 77
Reputation: EvilLinux is an unknown quantity at this point 
Solved Threads: 0
EvilLinux EvilLinux is offline Offline
Junior Poster in Training

Re: direct robot

 
0
  #20
Sep 27th, 2009
Originally Posted by ddanbe View Post
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!
I understand, I was looking around because the panel says Top Left, so normally if you don't define something it will go with the panel values.
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.
Reply With Quote Quick reply to this message  
Reply

Tags
c#, directrobot, form, robot

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2081 | Replies: 26
Thread Tools Search this Thread



Tag cloud for c#, directrobot, form, robot
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC