This site requires JavaScript, please enable it in your browser!
Greenfoot back
Yavelee
Yavelee wrote ...

2015/3/1

Question: Move mushroom for a beforehand specified distance

Yavelee Yavelee

2015/3/1

#
Hello, I am sorry for every mistake I am going to make be it in grammar, vocabulary or expressions. I am not a native speaker and bloody new to programming. Please bear with me. For a school problem I have to program my Kara to push a mushroom through labyrinth kinda thing onto a leaf. (without knowing beforehand where the mushroom is gonna be) But I found a way to get the numbers of spaces I have to push the mushroom in the horizontal and the vertikal direction to get to the gate. My problem right now is that when I just put in the variable (for example "vertikal" ) in to the move ( ) - act - like this - move(vertikal) - (and let vertikal be "2" ) my kara moves 2 spaces like I want it to - but it JUMPS over the mushroom!!! And doesnt push it the 2 spaces I would need it to push the mushroom ... it works if I just put in two times : move(); ... but I want it to be usable in more than one specified situation - so thats my problem. What happens here and how can I resolve it? Thanks so much!!! :-)
if (searchformushroom ==1 && pushthatmushroom < 1) {
             vertikal = horizontalcount/6 ;
             horizontal = 6 - (horizontalcount % 6);
            
            if (vertikal % 2 == 0 ) {
               turnLeft();
               move();
               turnRight();
               move();
               turnRight();
               MOVE(VERTIKAL);
              turnLeft();
              move();
              turnRight();
              move();
              turnRight();
              MOVE(HORIZONTAL);
              turnRight();
              move();
              turnLeft();
              move();
              turnLeft(); } [ ... ]
danpost danpost

2015/3/1

#
You could use a loop. For example:
// instead of
MOVE(VERTIKAL);
// you could try this
for (int i=0; i<VERTIKAL; i++) move();
Yavelee Yavelee

2015/3/1

#
it worked! thank you so much :-)
You need to login to post a reply.