Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with mastermind game

$
0
0
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.
  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

Viewing all articles
Browse latest Browse all 51036

Trending Articles


FLASHBACK WITH SIRASA FM AT GALGAMUWA 2022


Mp3 Download: Mdu - Mazola


Imitation gun was fired at motorist in Leicester road-rage incident


Ndebele names


MCKINNEY EMALINE “EMMA” OF WES...


Okra & Motia — The Workshop (Prod by Hammer)


Skint TV teen to be sentenced


Moondru Mudichu 19-09-2017 – Polimer tv Serial


YOSVANI JAMES Arrested by Miami-Dade County Corrections on Jan 10, 2017


Stories • Goddess Stepmom



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>