So I just began a college course in Java, and our first assignment was to write a text-based Mastermind game in Java. I was able to lay out all the necessary framework, but the area that still has me in a fix is getting the computer to check the secret code to the user's guess. I have both integers stored in arrays. How can I do this so that when the user enters one digit at a time, the guess will either be true or false to the secret code, and then output this at the end? Below is as far as I've got with the for loops and code checking.

for (int i = 0; i < xpegs; i++) {
     System.out.print("Color for peg " + counter + " :");
     guess[i] = input.nextInt();
     counter++;


     if (guess[i] == secret[i]) {
      placecounter++;
      //set guess array at this point to -1
      guess[i] = -1;
     } else {
      for (int j = 0; j < xpegs; j++)
       if (guess[j] == secret[i]) {
        colorcounter++;
        //set guess array at this point to -1
        secret[j] = -1;
        break;

        } 
       }

Any help would be greatly appreciated!

The user should not enter 1 digit at a time, but always an entire combination.
Check the combination entered against the combination stored, et voila.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.