I'm writing a spelling bee game and I need help. It is such that when the user clicks a button, a sound file plays and a text field is provided for the user to spell the word pronounced in the sound file. After which the user confirms with a button!!! If the text entered matches that of the sound file, the user is correct. Else, the user is false... I created a file array with 50 contents and a string array with 50 contents... I want to link them in that manner...any Ideas please!! I am a new comer here!
-
I suggest you break this down into smaller parts. For example, you need to 1. Create the visual UI with the text field and button. 2. Read a file. 3. Play a sound. Figure out what other small tasks you need to accomplish and attempt to figure out how to do each one. When you have a specific problem with any step, please feel free to ask more questions.Code-Apprentice– Code-Apprentice2016-08-30 23:29:27 +00:00Commented Aug 30, 2016 at 23:29
-
Yea.... I'm at the point where I have to link the File array[50] with the String Array[50] such that when the user puts in an answer..... and the String element matches the file element....he/she is correct. If not, he / she is wrong. @Code-ApprenticeKosi– Kosi2016-08-30 23:50:05 +00:00Commented Aug 30, 2016 at 23:50
-
Please show us what you have tried and explain, in detail, what difficulty you have encountered.Code-Apprentice– Code-Apprentice2016-08-31 00:10:12 +00:00Commented Aug 31, 2016 at 0:10
Add a comment
|
1 Answer
First you build you arrays in such a way that the sound at element x in your file array matches the word in your string array at element x. When you play the sound, save the index of its element in the array. When the user enters a word, check if its in your string array, if yes, check if its index matches the index of the sound file, if yes, the word they spelled was correct.
//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
}
}