Hey everyone
I have been working on the mastermind game in c# but currently am stuck. Currently my program works but it is having difficulty spotting when the user has entered the correct colour (in my code number) and position. Below is a statement i use to try and find if the user has entered a correct guess
It seems to think all guesses are a correct Black pin guess after you have mad ea correct black pin guess once.
this is how i create the scret code
I hope someone can help me.
Thanks
I have been working on the mastermind game in c# but currently am stuck. Currently my program works but it is having difficulty spotting when the user has entered the correct colour (in my code number) and position. Below is a statement i use to try and find if the user has entered a correct guess
It seems to think all guesses are a correct Black pin guess after you have mad ea correct black pin guess once.
int[] GuessArray = new int[N];
for(int i=0; i < N; i++)
{
Console.Write("Please enter your guess: ");
GuessArray[i] = Convert.ToInt16(Console.ReadLine());
if (GuessArray[i] == numbers[i] && numbers.Contains(GuessArray[i]))
{
guessblack = true;
}
else if (numbers.Contains(GuessArray[i]))
{
guesswhite = true;
}
else
{
wrong = true;
}
//Show if a guess was correct or not
if (guessblack == true)
{
Console.WriteLine("=======================");
Console.WriteLine("Black Pin");
Console.WriteLine("======================");
}
else if (guesswhite == true)
{
Console.WriteLine("=======================");
Console.WriteLine("White Pin");
Console.WriteLine("======================");
}
else
{
Console.WriteLine("=======================");
Console.WriteLine("Incorrect");
Console.WriteLine("======================");
}
}
}
this is how i create the scret code
//Create the secret code
Random random = new Random();
int[] numbers = new int[N];
Console.WriteLine();
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = random.Next(1, M);
Console.WriteLine(numbers[i]);
}
I hope someone can help me.
Thanks