我正在开发word scramble android app。我想以序列顺序显示单词的字符串,但在下面的代码中,它从字典中获取随机单词。我的问题是如何更改我的代码以从序列顺序中的字典中获取单词?
String[] dictionary=
{"One","Server","Terminate","Analyze","Finish","Start","Wonder","Slow"};
r = new Random(System.currentTimeMillis());
newGame();
// shuffle algorithm
private String shuffleWord(String word){
List<String> letters = Arrays.asList(word.split(""));
Collections.shuffle(letters);
String Shuffled="";
for (String letter : letters ){
Shuffled += letter;
}
return Shuffled;
}
private void newGame(){
// get random word from dictionary
currentWord= dictionary[r.nextInt(dictionary.length)];
// show the shuffled word
tv_word.setText(shuffleWord(currentWord));
// clear the textfield
et_guess.setText("");
// switch buttons
b_new.setEnabled(false);
b_check.setEnabled(true);
}
}
答案 0 :(得分:0)
其实你用随机位置选择你的单词
r = new Random(System.currentTimeMillis());
使用从0到ArrayOfWords长度的随机整数。
currentWord= dictionary[r.nextInt(dictionary.length)];
为什么你不尝试制作一个计数器呢?
int r = 0;
while (r<dictionary.length()) {
currentWord = dictionary[r];
r++;
}
或者我不明白你的答案。但是我理解的是假的。