Greetings Beren,
My advice is: don't use exceptions do handle normal events, only truely
exceptional ones. Events that occur during normal robot operations
should be handled by the standard flow control structures.
Here is my analysis - the robot continues it's turn until one of 2
events occurs:
Event 1 - Turn is complete i.e. time is up;
Event 2 - a hit is detected
So the code needs a waiting loop with 2 exit conditions, and the
condition that triggered the exit must be known then the loop
terminates.
Here is a code fragment that does it:
int duration = 400;
int endTime = (int)System.currentTimeMillis() + duration;
boolean hit = false;
while(System.currentTimeMillis() < endTime && !hit) // exits when time
is up or a hit occurs
{
hit = hitLeftSensor() || hitRightSensor();
}
if(hit) backup();
By the way, congratulations on nice coding style. Is this really your
first experience at programming?? Keep it up.
What next? Try a robot that heads toward a bright light, avoiding
obstacles on the way. Good luck
Roger
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion