I'm creating a Mastermind game and I want to compare two arrays of Colors
. Both arrays contains 4 colors.
How to check if the first array contains any colors of the second array and how to check too if colors have same positions in array or not.
Any ideas?
I tried this way but it doesn't work everytime I don't know why:
Color[] colorsSelected = { Color.red, Color.red, Color.yellow, Color.green };
Color[] gameResult = { Color.red, Color.blue, Color.yellow, Color.green };
for (int i = 0; i < gameResult.length; i++) { // go through all in second array
if (Arrays.asList(colorsSelected).contains(gameResult[i]) && i == Arrays.asList(colorsSelected).indexOf(gameResult[i])) {
System.out.println(colorsSelected[i]);
}
}