예제 #1
0
    public int clock;              //the counter value of the bomb hexagon

    private void Start()
    {
        master = GameObject.Find("Master").GetComponent <MasterMind>();
        mother = GameObject.Find("Mother");

        key = false;
    }
예제 #2
0
        public void Test_Comparar_04_ii()
        {
            MasterMind mm = new MasterMind();

            mm.SetCodeSecret(RowsDefault.ROW_BRYW);
            string result = mm.GetResultAttempt(RowsDefault.ROW_YWGO);

            Assert.AreEqual(MasterMind.OK_OPOS + MasterMind.OK_OPOS, result);
        }
예제 #3
0
        public void Test_Comparar_01_AttemptWin_XXXX()
        {
            MasterMind mm = new MasterMind();

            mm.SetCodeSecret(RowsDefault.ROW_BRYW);
            string result = mm.GetResultAttempt(RowsDefault.ROW_BRYW);

            Assert.AreEqual(mm.GetResultWin(), result);
        }
예제 #4
0
 private void updateCounters()
 {
     comboBox1.SelectedIndex = -1;
     comboBox2.SelectedIndex = -1;
     comboBox3.SelectedIndex = -1;
     comboBox4.SelectedIndex = -1;
     MasterMind.resetCorrectGuessesCounterr();
     MasterMind.resetCorrectPositionedGuessesCounter();
     MasterMind.incrementGuessCounter();
 }
예제 #5
0
        public virtual void start()
        {
            //        System.out.println("Please enter Number of Pegs and Colors:");
            //        pegs = scanner.nextInt();
            //        colors = scanner.nextInt();

            mm = new MasterMind(pegs, colors);
            Console.WriteLine("Initialized with: " + pegs + ", " + colors);
            movePrompt();
        }
예제 #6
0
        public void Test_ComprobarAciertos_Intento_02_Win()
        {
            MasterMind mm = new MasterMind();

            mm.SetCodeSecret(RowsDefault.ROW_BRYW);
            mm.SetAttempt(RowsDefault.ROW_OGVL);
            mm.SetAttempt(RowsDefault.ROW_WVOY);
            mm.SetAttempt(RowsDefault.ROW_GROB);
            mm.SetAttempt(RowsDefault.ROW_BRYW);

            mm.DrawBoard();
        }
예제 #7
0
        //Validate to send multiple options
        private void btnMain_Click(object sender, System.EventArgs e)
        {
            //When the game is over, restart the game
            if (!cmbPosition.Enabled)
            {
                ResetApp();
            }
            //Check if the initial combination is complete, to proceed to guess
            else if (LineValidationIsComplete(masterCombination) && !masterCombination.IsComplete)
            {
                masterCombination.IsComplete = true;
                gbHistory.Enabled            = true;
                gbCurrentLine.Text           = "Find the Combination";
                btnMain.Text = "Validate";
                cmbPosition.SelectedIndex = 0;
                cmbPosition_SelectedIndexChanged(null, null);
            }
            //Validates if the current combination of the player to guess is complete
            else if (LineValidationIsComplete(currentLine) && !currentLine.IsComplete)
            {
                var masterMind = new MasterMind(masterCombination);
                var result     = masterMind.GetHints(currentLine);

                if (result != null)
                {
                    if (result.Count > 0)
                    {
                        ValidationEntity entity = new ValidationEntity(currentLine, result);
                        entity.IsEqual = (result.Contains(ResultPeg.None) || result.Contains(ResultPeg.White)) ? false : true;
                        resultLines.Add(entity);
                        ShowHistory();
                        currentLine = new MasterEntity();
                        cmbPosition.SelectedIndex = 0;
                        cmbPosition_SelectedIndexChanged(null, null);

                        if (resultLines[resultLines.Count - 1].IsEqual)
                        {
                            showCombination = true;
                            btnShow_Click(null, null);
                            gbColor.Enabled = cmbPosition.Enabled = false;
                            btnMain.Text    = "Reset";
                        }
                    }
                }
            }
        }
예제 #8
0
        public void Test_GenerarCodigoSecreto()
        {
            MasterMind mm = new MasterMind();

            mm.GenerateCodeSecret();
            Console.WriteLine(mm.GetCodeSecret().ToString());

            mm.GenerateCodeSecret();
            Console.WriteLine(mm.GetCodeSecret().ToString());

            mm.GenerateCodeSecret();
            Console.WriteLine(mm.GetCodeSecret().ToString());

            mm.GenerateCodeSecret();
            Console.WriteLine(mm.GetCodeSecret().ToString());

            mm.GenerateCodeSecret();
            Console.WriteLine(mm.GetCodeSecret().ToString());
        }
예제 #9
0
 private void resetSecretCode()
 {
     MasterMind.resetLastValues();
     MasterMind.resetGuessCounter();
     MasterMind.secretCode = MasterMind.getSecretCode();
     if (MasterMind.showSecretCode == true)
     {
         label53.Text = MasterMind.secretCode[0];
         label52.Text = MasterMind.secretCode[1];
         label51.Text = MasterMind.secretCode[2];
         label50.Text = MasterMind.secretCode[3];
     }
     else
     {
         label53.Text = "***";
         label52.Text = "***";
         label51.Text = "***";
         label50.Text = "***";
     }
 }
예제 #10
0
        public void Test_DibujarTableroEmpty()
        {
            MasterMind mm = new MasterMind();

            mm.DrawBoard();
        }
예제 #11
0
 private void Awake()
 {
     master = GameObject.Find("Master").GetComponent <MasterMind>();
 }
예제 #12
0
        static void Main(string[] args)
        {
            // Display title as the C# MasterMind console app.
            Console.WriteLine("Console MasterMind in C#\r");
            Console.WriteLine("------------------------\n");

            Console.WriteLine("Instructions: We have a secret key that you must guess.");
            Console.WriteLine("To play the game, you will enter a " + NB_OF_DIGITS.ToString() + "- digit number, where each digit is between 1 and 6, in order to guess the correct key..\r");
            Console.WriteLine("You will win if you can guess the number within " + MAX_NB_OF_ATTEMPTS.ToString() + " attempts.\r");
            Console.WriteLine("Type a " + NB_OF_DIGITS.ToString() + "- digit number, where each digit is between 1 and 6, and then press Enter");
            Console.WriteLine("Each '+' signals a digit that is both correct and in the correct position");
            Console.WriteLine("Each '-' signals a digit that is correct but in the wrong position");
            Console.WriteLine("Type QUIT to end the game\r");

            // create a secret key that user needs to guess
            MasterMind newGame = new MasterMind();

            // uncomment to debug
            //Console.WriteLine("The answer is: " + newGame.AnswerKeyString);

            int    nbOfAttempts = 0;
            bool?  results;
            string userResponse;

            while (nbOfAttempts < MAX_NB_OF_ATTEMPTS)
            {
                results = newGame.ProcessUserGuess(++nbOfAttempts);
                if (!results.HasValue)
                {
                    break;
                }

                while (results.Value == true || (results.Value == false && nbOfAttempts == MAX_NB_OF_ATTEMPTS))
                {
                    if (results.Value == true)
                    {
                        Console.WriteLine("Great game!");
                    }
                    else if (results.Value == false && nbOfAttempts == MAX_NB_OF_ATTEMPTS)
                    {
                        Console.WriteLine("The answer was: " + newGame.AnswerKeyString);
                        Console.WriteLine("You lose, better luck next time.");
                    }
                    Console.WriteLine("Would you like to play again?");
                    userResponse = Console.ReadLine();
                    if (userResponse != null && (userResponse.Equals("Y", StringComparison.InvariantCultureIgnoreCase) ||
                                                 userResponse.Equals("yes", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        newGame      = new MasterMind();
                        nbOfAttempts = 0;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            // Wait for the user to respond before closing.
            Console.Write("Press any key to close the MasterMind console app...");
            Console.ReadKey();
        }
예제 #13
0
 private void Reset(GameDifficulity difficulity)
 {
     game = new MasterMind(difficulity);
 }
예제 #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Secret");

            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine(i + " " + MasterMind.secretCode[i]);
            }

            Console.WriteLine(comboBox1.Text);
            Console.WriteLine(comboBox2.Text);
            Console.WriteLine(comboBox3.Text);
            Console.WriteLine(comboBox4.Text);
            if ((comboBox1.SelectedItem == null || comboBox1.SelectedIndex == -1) ||
                (comboBox2.SelectedItem == null || comboBox2.SelectedIndex == -1) ||
                (comboBox3.SelectedItem == null || comboBox3.SelectedIndex == -1) ||
                (comboBox4.SelectedItem == null || comboBox4.SelectedIndex == -1))
            {
                MessageBox.Show("Please select color to make a guess");
                return;
            }

            //checking guess with secret code
            if (comboBox1.Text == MasterMind.secretCode[0] &&
                comboBox2.Text == MasterMind.secretCode[1] &&
                comboBox3.Text == MasterMind.secretCode[2] &&
                comboBox4.Text == (MasterMind.secretCode[3]))
            {
                resetSecretCode();
                resetlabels();
                MessageBox.Show("You Win!!!\n" +
                                "Correct Secret Code: " + MasterMind.secretCode[0] + ", " + MasterMind.secretCode[1] + ", " + MasterMind.secretCode[2] + ", " + MasterMind.secretCode[3]);
                disableItems();
                return;
            }
            for (int i = 0; i < MasterMind.secretCode.Length; i++)
            {
                Console.WriteLine(i + " " + MasterMind.secretCode[i]);
            }
            //checking correct positioned guesses
            if (comboBox1.Text.Equals(MasterMind.secretCode[0]))
            {
                MasterMind.incrementcorrectPositionedGuessesCounter();
                Console.WriteLine("CALLED1");
            }
            if (comboBox2.Text.Equals(MasterMind.secretCode[1]))
            {
                MasterMind.incrementcorrectPositionedGuessesCounter();
                Console.WriteLine("CALLED2");
            }
            if (comboBox3.Text.Equals(MasterMind.secretCode[2]))
            {
                MasterMind.incrementcorrectPositionedGuessesCounter();
                Console.WriteLine("CALLED3");
            }
            if (comboBox4.Text.Equals(MasterMind.secretCode[3]))
            {
                MasterMind.incrementcorrectPositionedGuessesCounter();
                Console.WriteLine("CALLED4");
            }

            //checking correct  guesses with different position
            if (MasterMind.secretCode.Contains(comboBox1.Text) && !comboBox1.Text.Equals(MasterMind.secretCode[0]))
            {
                MasterMind.incrementCorrectGuessesCounter();
            }
            if (MasterMind.secretCode.Contains(comboBox2.Text) && !comboBox2.Text.Equals(MasterMind.secretCode[1]))
            {
                MasterMind.incrementCorrectGuessesCounter();
            }
            if (MasterMind.secretCode.Contains(comboBox3.Text) && !comboBox3.Text.Equals(MasterMind.secretCode[2]))
            {
                MasterMind.incrementCorrectGuessesCounter();
            }
            if (MasterMind.secretCode.Contains(comboBox4.Text) && !comboBox4.Text.Equals(MasterMind.secretCode[3]))
            {
                MasterMind.incrementCorrectGuessesCounter();
            }

            //populating guess value
            if (MasterMind.guessCounter == 1)
            {
                label9.Text  = comboBox1.Text;
                label10.Text = comboBox2.Text;
                label11.Text = comboBox3.Text;
                label12.Text = comboBox4.Text;
                //populating result
                label41.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 2)
            {
                label16.Text = comboBox1.Text;
                label15.Text = comboBox2.Text;
                label14.Text = comboBox3.Text;
                label13.Text = comboBox4.Text;
                //populating result
                label42.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 3)
            {
                label40.Text = comboBox1.Text;
                label39.Text = comboBox2.Text;
                label38.Text = comboBox3.Text;
                label37.Text = comboBox4.Text;
                //populating result
                label43.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 4)
            {
                label36.Text = comboBox1.Text;
                label35.Text = comboBox2.Text;
                label34.Text = comboBox3.Text;
                label33.Text = comboBox4.Text;
                //populating result
                label44.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 5)
            {
                label32.Text = comboBox1.Text;
                label31.Text = comboBox2.Text;
                label30.Text = comboBox3.Text;
                label29.Text = comboBox4.Text;
                //populating result
                label45.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 6)
            {
                label28.Text = comboBox1.Text;
                label27.Text = comboBox2.Text;
                label26.Text = comboBox3.Text;
                label25.Text = comboBox4.Text;
                //populating result
                label46.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 7)
            {
                label24.Text = comboBox1.Text;
                label23.Text = comboBox2.Text;
                label22.Text = comboBox3.Text;
                label21.Text = comboBox4.Text;
                //populating result
                label47.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }
            else if (MasterMind.guessCounter == 8)
            {
                label20.Text = comboBox1.Text;
                label19.Text = comboBox2.Text;
                label18.Text = comboBox3.Text;
                label17.Text = comboBox4.Text;
                //populating result
                label48.Text = MasterMind.correctPositionedGuessesCounter.ToString() + "B" + " " + MasterMind.correctGuessesCounter.ToString() + "W";
            }

            updateCounters();
            //checking max limit of guesses

            if (MasterMind.guessCounter == 9)
            {
                resetSecretCode();
                resetlabels();
                disableItems();
                MessageBox.Show("You Lose!!!\n" +
                                "Correct Secret Code: " + MasterMind.secretCode[0] + ", " + MasterMind.secretCode[1] + ", " + MasterMind.secretCode[2] + ", " + MasterMind.secretCode[3]);
                return;
            }
        }