Пример #1
0
 public Engine(ScoreBoard board)
 {
     this.scoreBoard = board;
     this.guessCount = 0;
     this.cheats = new Cheat();
     this.theNumber = new GameNumber();
 }
Пример #2
0
        public string GetCheat(GameNumber theNumber)
        {
            Random randPosGenerator = new Random();

            if (this.count < MaxCheatsAllowed)
            {
                while (true)
                {
                    int randPossition = randPosGenerator.Next(0, 4);
                    if (cheatNumber[randPossition] == 'X')
                    {
                        switch (randPossition)
                        {
                            case 0:
                                this.cheatNumber[randPossition] = (char)(theNumber.FirstDigit + '0');
                                break;
                            case 1:
                                this.cheatNumber[randPossition] = (char)(theNumber.SecondDigit + '0');
                                break;
                            case 2:
                                this.cheatNumber[randPossition] = (char)(theNumber.ThirdDigit + '0');
                                break;
                            case 3:
                                this.cheatNumber[randPossition] = (char)(theNumber.FourthDigit + '0');
                                break;
                        }
                        break;
                    }
                }

                this.count++;
            }

            return new String(cheatNumber);
        }
Пример #3
0
 public Engine(ScoreBoard board)
 {
     this.scoreBoard = board;
     this.guessCount = 0;
     this.cheats     = new Cheat();
     this.theNumber  = new GameNumber();
 }
Пример #4
0
 private void ResetGameData()
 {
     Console.WriteLine();
     Printer.PrintWelcomeMessage();
     this.theNumber  = new GameNumber();
     this.cheats     = new Cheat();
     this.guessCount = 0;
 }
Пример #5
0
        public string GetCheat(GameNumber theNumber)
        {
            Random randPosGenerator = new Random();

            if (this.count < MaxCheatsAllowed)
            {
                while (true)
                {
                    int randPossition = randPosGenerator.Next(0, 4);
                    if (cheatNumber[randPossition] == 'X')
                    {
                        switch (randPossition)
                        {
                        case 0:
                            this.cheatNumber[randPossition] = (char)(theNumber.FirstDigit + '0');
                            break;

                        case 1:
                            this.cheatNumber[randPossition] = (char)(theNumber.SecondDigit + '0');
                            break;

                        case 2:
                            this.cheatNumber[randPossition] = (char)(theNumber.ThirdDigit + '0');
                            break;

                        case 3:
                            this.cheatNumber[randPossition] = (char)(theNumber.FourthDigit + '0');
                            break;
                        }
                        break;
                    }
                }

                this.count++;
            }

            return(new String(cheatNumber));
        }
Пример #6
0
 private void ResetGameData()
 {
     Console.WriteLine();
     Printer.PrintWelcomeMessage();
     this.theNumber = new GameNumber();
     this.cheats = new Cheat();
     this.guessCount = 0;
 }
Пример #7
0
        public static Result GetBullsAndCowsMatches(PlayerGuess playerGuess, GameNumber gameNumber)
        {
            int bulls = 0;

            // checks if playerGuess.FirstDigit is a bull:
            bool isFirstDigitBull = false;

            if (gameNumber.FirstDigit == playerGuess.FirstDigit)
            {
                isFirstDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.SecondDigit is a bull:
            bool isSecondDigitBull = false;

            if (gameNumber.SecondDigit == playerGuess.SecondDigit)
            {
                isSecondDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.ThirdDigit is a bull:
            bool isThirdDigitBull = false;

            if (gameNumber.ThirdDigit == playerGuess.ThirdDigit)
            {
                isThirdDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.FourthDigit is a bull:
            bool isFourthDigitBull = false;

            if (gameNumber.FourthDigit == playerGuess.FourthDigit)
            {
                isFourthDigitBull = true;
                bulls++;
            }

            int cows = 0;

            // checks if playerGuess.playerGuess.FirstDigit is cow:
            if (!isFirstDigitBull)
            {
                if (!isSecondDigitBull && playerGuess.FirstDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.FirstDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.FirstDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.SecondDigit is cow:
            if (!isSecondDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.SecondDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.SecondDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.SecondDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.ThirdDigit is cow:
            if (!isThirdDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.ThirdDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isSecondDigitBull && playerGuess.ThirdDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.ThirdDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.FourthDigit is cow:
            if (!isFourthDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.FourthDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isSecondDigitBull && playerGuess.FourthDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.FourthDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
            }

            Result guessResult = new Result(bulls, cows);

            return(guessResult);
        }
        public static Result GetBullsAndCowsMatches(PlayerGuess playerGuess, GameNumber gameNumber)
        {
            int bulls = 0;

            // checks if playerGuess.FirstDigit is a bull:
            bool isFirstDigitBull = false;
            if (gameNumber.FirstDigit == playerGuess.FirstDigit)
            {
                isFirstDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.SecondDigit is a bull:
            bool isSecondDigitBull = false;
            if (gameNumber.SecondDigit == playerGuess.SecondDigit)
            {
                isSecondDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.ThirdDigit is a bull:
            bool isThirdDigitBull = false;
            if (gameNumber.ThirdDigit == playerGuess.ThirdDigit)
            {
                isThirdDigitBull = true;
                bulls++;
            }

            // checks if playerGuess.FourthDigit is a bull:
            bool isFourthDigitBull = false;
            if (gameNumber.FourthDigit == playerGuess.FourthDigit)
            {
                isFourthDigitBull = true;
                bulls++;
            }

            int cows = 0;

            // checks if playerGuess.playerGuess.FirstDigit is cow:
            if (!isFirstDigitBull)
            {
                if (!isSecondDigitBull && playerGuess.FirstDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.FirstDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.FirstDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.SecondDigit is cow:
            if (!isSecondDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.SecondDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.SecondDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.SecondDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.ThirdDigit is cow:
            if (!isThirdDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.ThirdDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isSecondDigitBull && playerGuess.ThirdDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isFourthDigitBull && playerGuess.ThirdDigit == gameNumber.FourthDigit)
                {
                    cows++;
                }
            }

            // checks if playerGuess.FourthDigit is cow:
            if (!isFourthDigitBull)
            {
                if (!isFirstDigitBull && playerGuess.FourthDigit == gameNumber.FirstDigit)
                {
                    cows++;
                }
                else if (!isSecondDigitBull && playerGuess.FourthDigit == gameNumber.SecondDigit)
                {
                    cows++;
                }
                else if (!isThirdDigitBull && playerGuess.FourthDigit == gameNumber.ThirdDigit)
                {
                    cows++;
                }
            }

            Result guessResult = new Result(bulls, cows);
            return guessResult;
        }