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!