首先,我沒有要求代碼...我剛剛到了點,我不知道如何進步...可以有人請向我解釋如何開始這個hang子手的這一步?我已經有按鈕的排列:Hang子手 - 隱藏字符串,然後取消隱藏每個字符如果猜測正確
String b[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
for(i = 0; i < buttons.length; i++) {
buttons[i] = new JButton(b[i]);
panel.add(buttons[i]);
}
然後我試圖隱瞞這個詞來自一個列表:
public String readWord() {
try {
BufferedReader reader = new BufferedReader(new FileReader("Words.txt"));
String line = reader.readLine();
List<String> words = new ArrayList<String>();
while(line != null) {
String[] wordsLine = line.split(" ");
boolean addAll = words.addAll(Arrays.asList(wordsLine));
line = reader.readLine();
}
Random rand = new Random(System.currentTimeMillis());
String randomWord = words.get(rand.nextInt(words.size()));
return randomWord;
} catch (Exception e) {
return null;
}
}
現在能有人請點我到正確的方向用「 - 」隱藏單詞。而當用戶點擊一個正確的按鈕,該字母必須出現...
如果它不是很清楚,我很抱歉。