mardi 15 décembre 2015

processing/java regenerate a random string?

I'm currently building a hangman game and have an array of words

String[] wordList = {"Word 1", "Word 2", "Word 3"};

but I also added in hints like so

String[] hintList = {"Hint 1", "Hint 2", "Hint 3"};

so to make the hints show up, instead of generating the word to use like this:

String theWord = wordList[int(random(0, wordList.length))];

I decided to use

int randomWordPlace = int(random(0, wordList.length));
String theWord = wordList[randomWordPlace];

I thought this would allow me to write an easy "reset" function like so

void reset(){
    randomWordPlace = int(random(0,wordList.length));
}

this works, i think, except It doesn't redraw the spaces. i tried running the function for drawing the spaces within the reset but that doesn't solve it. If it would help, I can post the entire code.




Aucun commentaire:

Enregistrer un commentaire