예제 #1
0
        public static DefaultPlayer CreatePlayer()
        {
            var random = new Random();

            PlayerId++;
            DefaultPlayer newPlayer = null;

            switch (random.Next(1, 5))
            {
            case 1:
                newPlayer = new CheaterPlayer(PlayerNameGenerator.GetNextPlayerName(), PlayerId);
                break;

            case 2:
                newPlayer = new MemoryPlayer(PlayerNameGenerator.GetNextPlayerName(), PlayerId);
                break;

            case 3:
                newPlayer = new RandomPlayer(PlayerNameGenerator.GetNextPlayerName(), PlayerId);
                break;

            case 4:
                newPlayer = new ThoroughCheaterPlayer(PlayerNameGenerator.GetNextPlayerName(), PlayerId);
                break;

            case 5:
                newPlayer = new ThoroughPlayer(PlayerNameGenerator.GetNextPlayerName(), PlayerId);
                break;
            }

            _playersList.Add(newPlayer);
            return(newPlayer);
        }
예제 #2
0
        public void PlayerGeneratesOrderedNumbers()
        {
            //given
            var player = new ThoroughCheaterPlayer();

            //when
            var newNumber = player.GuessNumber();

            //then
            Assert.That(newNumber, Is.EqualTo(41));

            //and when
            newNumber = player.GuessNumber();

            //then
            Assert.That(newNumber, Is.EqualTo(42));
        }
예제 #3
0
        public void PlayerDontGenerateAlreadyGuessedNumber()
        {
            //given
            var knowNumbersStub = MockRepository.GenerateStub <IKnowNumbers>();

            knowNumbersStub.Stub(x => x.RememberNumbers(1));

            var player = new ThoroughCheaterPlayer(knowNumbersStub);

            //when
            player.NewNumberGuessed(41);

            //then
            knowNumbersStub.AssertWasCalled(x => x.RememberNumbers(1));

            //and when
            var newNumber = player.GuessNumber();

            //then
            Assert.That(newNumber, Is.EqualTo(42));
        }
예제 #4
0
        private void SetPlayersNamesAndTypes(int numberOfPlayers)
        {
            Console.WriteLine("Enter players \"Name\" and choose players types");
            Console.WriteLine("Player types are:");
            Console.WriteLine("1. Random player");
            Console.WriteLine("2. Memory player");
            Console.WriteLine("3. Thorough player");
            Console.WriteLine("4. Cheater player");
            Console.WriteLine("5. Thorough Cheater player");
            for (int i = 0; i < numberOfPlayers; i++)
            {
                bool isCorrectPlayerInput = false;
                while (!isCorrectPlayerInput)
                {
                    try
                    {
                        Console.Write("Enter Player {0} name: ", i + 1);
                        string name = Console.ReadLine();

                        Console.Write("Choose type for player {0} [1 to 5]: ", i + 1);
                        int playerTypeInput = int.Parse(Console.ReadLine());
                        if (playerTypeInput < 1 || 5 < playerTypeInput)
                        {
                            throw new FormatException("Player type must be between 1 and 5!");
                        }

                        switch (playerTypeInput)
                        {
                            case 1:
                                {
                                    RandomPlayer newPlayer = new RandomPlayer(name, new CustomRandom());
                                    this.players.Add(newPlayer);
                                    break;
                                }

                            case 2:
                                {
                                    MemoryPlayer newPlayer = new MemoryPlayer(name, new CustomRandom());
                                    this.players.Add(newPlayer);
                                    break;
                                }

                            case 3:
                                {
                                    ThoroughPlayer newPlayer = new ThoroughPlayer(name);
                                    this.players.Add(newPlayer);
                                    break;
                                }

                            case 4:
                                {
                                    CheaterPlayer newPlayer = new CheaterPlayer(name, new CustomRandom());
                                    this.players.Add(newPlayer);
                                    break;
                                }

                            case 5:
                                {
                                    ThoroughCheaterPlayer newPlayer = new ThoroughCheaterPlayer(name);
                                    this.players.Add(newPlayer);
                                    break;
                                }

                            default:
                                break;
                        }

                        isCorrectPlayerInput = true;
                    }
                    catch (FormatException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (ArgumentNullException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }