簡體   English   中英

將文件數組鏈接到字符串數組

[英]Linking File arrays to String arrays

我正在寫一個拼字游戲,我需要幫助。 這樣,當用戶單擊按鈕時,將播放聲音文件,並為用戶提供文本字段來拼寫聲音文件中發音的單詞。 之后,用戶通過按鈕確認!!! 如果輸入的文本與聲音文件的文本匹配,則用戶正確。 否則,用戶是錯誤的...我創建了一個包含50個內容的文件數組和一個包含50個內容的字符串數組...我想以這種方式鏈接它們...任何想法! 我是這里的新來者!

首先,您要以這樣的方式構建數組,即文件數組中元素x處的聲音與元素x中的字符串數組中的單詞匹配。 播放聲音時,將其元素的索引保存在數組中。 當用戶輸入單詞時,請檢查其是否在您的字符串數組中;如果是,請檢查其索引是否與聲音文件的索引相匹配;如果是,則表明他們拼寫的單詞正確。

//The index of the sound and input from user
int soundToPlay;
String input;

Private int findStringIndex(String input){
  for(int i = 0; i < yourStringArray.length; i++){
    if(yourStringArray[i].equals(input){
      return i;
    }
  }
//not sure if java will allow you to send null like this. If not, you will have to find another way to deal with a string that isnt in your array
return null;
}

private void findMatch(int soundToPlay, String input){
  int index = findStringIndex(input);
  if(index == null){
    //String not in array, notify user
  }
  if(index == soundToPlay){
    //match found, notify user, play next sound
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM