java - Word game 3 checks and Jtextarea background color -


I have to make a word game called "Lingo", so far everything is going well but recently I have problems In checks generated, there are 3 checks in the game.

  // First check (int i = 0; i & lt; input.length (); i ++) {if (input.charAt (i) == True Word.charAt ( I)) {LingoBoard [0] [i] .setBackground (Color.GREEN); // When each letter (input) matches the correct word, background (textaria) gets green // second check other {linboboard [0] [i] .Setbackground (color .radi); } // When the letters do not match the letters with the correct word, the textieria turns red // the third check // When the letters are correct words but not in the right place, Textaria Magenta is created  < / Pre> 

I am checking for the third time, I can not find a way to fix my problem. I have tried to do this, but it makes background magenta for all 3 checks.

  if ((Lingoard [0] [i] .gettext (). CharAt (i)! = CorrectWord.charAt (I))) {Lingoboard [0] [i] .setBackground ( Color.MAGENTA); One better way to match the correct word is:  
    

If (input.exls (correct word)) {LingoBoard [0] [i] .setBackground (Color.GREEN); }

However, I'm surprised that your code works as you do not have any closed curl bracket (} followed by the first if < / Code> statement. If you are not too big, can you post the entire class?

For the second and third exams, you are better than doing something like:

  if (! (Input.equals (CorrectWord)) {// ArrayList & lt; character & gt; TempArray = new arreelist & lt; character & gt; (); for (four C: Input Coacharray) {// Play Copy the input to tempArray.add (c);} for each character in the solution for: // (cer c: CorrectWord.toCharArray ()) {// for the loop through player input (char d : Input.toCharArray ()) {// and check if there are facilities (D == c) {tempArray.remove (D); // We only want to delete one four at a time, then break the break; }}} // If all the letters are found, regardless of their order (tempArray.size () == 0) {LingoBoard [0] [i] .setBackground (Color.MAGENTA); } Other {lingoord [0] [i] .setBackground (Color.RED); }}   

The code has not been tested, it is written on the spot. I hate nested for loops , but I have not found a better way of handling the char array manipulation.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -