Attraversare in colonna

L'obbiettivo di questa serie di esercizi è quello di far attraversare al buggle il suo mondo. Esso dovrà numerare le celle dove camminerà in modo tale che venga mostrato l'ordine di attraversamento.

Il ciclo principale del tuo codice dovrà essere qualcosa come:

 mentre non siamo nella posizione finale
   vai avanti alla prossima posizione
   contrassegna la cella con il suo numero

Diversamente dagli esercizi svolti in precedenza, non userememo metodi simili a forward(), backward(), Invece calcoleremo le coordinate della posizione seguente del buggle usando il metodo setPos(x, y) per teleportare il buggle direttamente a quella posizione. Per esempio setPos(3, 5) teleporterà il buggle alla cella con le coordinate x=3 e y=5.

Il tuo primo compito è quello di scrivere una funzione booleana che indica se il buggle ha raggiunto la posizione finale oppure no, e cioé se si trova all'angolo in basso a destra. Per fare questo puoi utilizzare getWorldWidth() e getWorldHeight() che ritornano rispettivamente la larghezza e l'altezza del mondo. Il controllo da fare sarà quello di confrontare l'attuale posizione del bug (cui puoi accedere con getX() e getY()) con la dimensione del mondo.
Beware, the first line and column are numbered 0 and not 1, and the point (0,0) is on the top left corner. This may seem surprising, but it is very often so in Computer Science.

Then, you have to write the code to reach the next position. In this exercise, you have to traverse the world row after row. So, if you are at the bottom of a row, you have to move to the top of next row. Else, you have to move to the cell below.

Dopodiché potrete eseguire il programma per controllare se il buggle ha attraversato il mondo nell'ordine corretto e se si ferma al momento opportuno. Usa li pulsante stop se il buggle non si ferma quando deve.

It is now time to write down the cell numbers. For that, you will need a counter initialiser to zero at the beginning of your code, and incremented by one at each step (for example with counter += 1;). Then, you have to use writeMessage() to write the value on the ground.

You probably need to write the first [!java|scala|c]or last [/!]value out of the main loop [!java|scala|c], depending on whether you prefer to use a while or a do/while one[/!].

È il tuo turno...