direct robot

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 1,955
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: 281
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: direct robot

 
1
  #21
Sep 27th, 2009
Just as any control a Panel has a Validating and Validated event, but IMO they are of not much use here. I should check the limits in every go button test if you would pass 100 or -100 in a separate method. This passing would depend on the direction so you could use a switch statement. Coming to think of it, you could probably do this in the Move method of your robot!
The location property of your robot contains the REAL Panel coordinates. When you Draw you shift these by adding half width and height so that 0,0 is in the middle of the Panel.
Now to show these in the position Label you have to substract half width and height. For the Y coordinate you also have to change sign!
The attached doc will make it clearer I hope.
Now for your border testing you could use both, it is up to you which you prefer. Succes.
Last edited by ddanbe; Sep 27th, 2009 at 5:12 pm.
Attached Files
File Type: doc panel coordinates.doc (27.0 KB, 3 views)
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
  #22
Sep 27th, 2009
Originally Posted by ddanbe View Post
Just as any control a Panel has a Validating and Validated event, but IMO they are of not much use here. I should check the limits in every go button test if you would pass 100 or -100 in a separate method. This passing would depend on the direction so you could use a switch statement. Coming to think of it, you could probably do this in the Move method of your robot!
The location property of your robot contains the REAL Panel coordinates. When you Draw you shift these by adding half width and height so that 0,0 is in the middle of the Panel.
Now to show these in the position Label you have to substract half width and height. For the Y coordinate you also have to change sign!
The attached doc will make it clearer I hope.
Now for your border testing you could use both, it is up to you which you prefer. Succes.
I understand the real and fiction values of the panel. The problem I'm running into is I don't understand if I should use a:
  1. get
  2. {
  3. if (location.X > 100 && location.Y > -100)
  4. {
  5. throw new ArgumentException("You can't do that!");
  6. }
in the robot.cs or for the go1\10 buttons.

The book shows how to through an argument exception, but not for something like moving an object more for an indexer that validates data and throws an argument.
Or if I just throw an arguementExcept with try if else finally?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
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: 281
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: direct robot

 
1
  #23
Sep 27th, 2009
Why not make your own robotexception class?
  1. class RobotException : Exception
  2. {
  3. public string robotstr;
  4. public RobotException(string message)
  5. : base(message)
  6. {
  7. robotstr = message;
  8. }
  9. }
Use it:
  1. try
  2. {
  3. //something went wrong so throw exception
  4. throw new RobotException("no no");
  5. }
  6. catch (RobotException ex)
  7. {
  8. MessageBox.Show(ex.robotstr);
  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
  #24
Sep 27th, 2009
form:
  1. private void go10Btn_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. throw new robotexception("You can't go that far; limited to 100units of movement");
  6. }
  7. catch (robotexception ex)
  8. {
  9. MessageBox.Show(ex.robotstr);
  10. }
  11. //Go 10.
  12. myRobot.Move(10);
  13. myRobot.Draw(robotpanel);
  14. //Update location info.
  15. robotlocationLlb.Text = myRobot.location.ToString();
  16.  
  17.  
  18.  
  19. }
robot.cs:
  1. class robotexception : Exception
  2. {
  3. public string robotstring;
  4. public robotexception(string message)
  5. : base(message)
  6. {
  7. robotstring = message;
  8. }
  9. }

Nope my stuff still isn't working, but I'm going to try to just work on getting something to at least validate if it goes over 100 and I'd be happy lol
Last edited by EvilLinux; Sep 27th, 2009 at 7:41 pm.
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
  #25
Sep 27th, 2009
Originally Posted by EvilLinux View Post
form:
  1. private void go10Btn_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. throw new robotexception("You can't go that far; limited to 100units of movement");
  6. }
  7. catch (robotexception ex)
  8. {
  9. MessageBox.Show(ex.robotstr);
  10. }
  11. //Go 10.
  12. myRobot.Move(10);
  13. myRobot.Draw(robotpanel);
  14. //Update location info.
  15. robotlocationLlb.Text = myRobot.location.ToString();
  16.  
  17.  
  18.  
  19. }
robot.cs:
  1. class robotexception : Exception
  2. {
  3. public string robotstring;
  4. public robotexception(string message)
  5. : base(message)
  6. {
  7. robotstring = message;
  8. }
  9. }

Nope my stuff still isn't working, but I'm going to try to just work on getting something to at least validate if it goes over 100 and I'd be happy lol
Been playing with for a while and just keep getting a namespace error about it. I would normally think the validation is easier, but everything I've tired to do to get this retarded project to show message once X or Y hits 100 or -100 doesn't work. (this proves me I'm not going to be a programmer in life lol).
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
  #26
Sep 27th, 2009
My friend took one look at my code and said:
"your putting your if \ else in the wrong place"
I put it at the location = P... And freaking work. I drove myself nuts for nothing on the validation . Now to relax and try to regrow some of my hair .
Thank you so much again for help and direction on this.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
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: 281
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: direct robot

 
0
  #27
Sep 28th, 2009
You could also use the Abs method to ease your testing of the fictive coordinates. Like in : if (Math.Abs(X)>100)...
Good luck and happy programming!
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  
Reply

Tags
c#, directrobot, form, robot

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC