Thread: need help for a programming exercice

1. need help for a programming exercice

Hello,

I am a first year programming student and I got problem solving an exercice I would be glad if you could help me.

Write a program, Tut6_2.cs where robby walks around the perimeter of room 8
, avoiding blue obstacles. In room 8, the obstacles are all one square wide (again), but of varied length.

Your solution should use while loops to negotiate these obstacles

Code:
```namespace CE0721a {
classtut6_2 {
publicvoid run() {
// make objects

Robot robby = new Robot();
Room room = new Room(8);
Picture picture = new Picture(room, robby);

robby.right();
picture.draw();

while (true) {
if (robby.ahead_is_colour(room, "white")) {
robby.move();
picture.draw();
if (robby.ahead_is_colour(room, "blue")) {
robby.left();
picture.draw();
}
if (robby.ahead_is_colour(room, "black")) {
robby.left();
picture.draw();
}
}
}
}
}
}```
I attached a picture of the room 8.The problem I encounter is when the robot go up the obstacle I don t know how he can check at his right.

Thank you in advance for your help
best regards
Thibault[ATTACH]11093
[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

2. I'm guessing your location is just tracked in some X,Y coordinate...why not just check map[x + 1,y]? Need more information before we can help you with this. How's the map stored? How's the robot's location stored?

3. Just so you know, next time you should paste "text" and not "html" into the code tags.

4. Woah, for one, you have an infinite loop. Yes you might want it to repeat but you should always have an easy exit option other than the three finger salute.

Next you should modify the routine to take into account the direction of movement just taken. Always think backwards.

5. Originally Posted by thibault0613
The problem I encounter is when the robot go up the obstacle I don t know how he can check at his right.
Unless I am missing something in translation here, his "right" depends on what way he is facing.

Quzah.

Popular pages Recent additions