jeudi 19 novembre 2020

Java If /Else statement Command String

So I am new to coding and am taking a course for it right now. I am trying to have the code I am writing take a string like and make a turtle image move or draw based on the commands, I am using a for loop but whenever I input the command string it executes the movements in a weird order.

int stringLength = commands.length();

for(int i=0; i<stringLength ;i++) {
    if (thigny.contains("F")) {

        rabbit.forward(move);

    } else if (thigny.contains("f")) {

        rabbit.penUp();
        rabbit.forward(move);

    } else if (thingy.contains("+")) {
        rabbit.turnLeft();
    } else if (thingy.contains("-")) {
        rabbit.turnRight();

    }
}

Aucun commentaire:

Enregistrer un commentaire