Exemplo n.º 1
0
        public static void Main(String[] args)
        {
            Random rand = new Random();
            if (args.Length == 1)
            {
                rand = new Random(Convert.ToInt32(args[0]));
            }

            Game aGame = new Game();

            aGame.AddPlayer("Chet");
            aGame.AddPlayer("Pat");
            aGame.AddPlayer("Sue");

            do
            {
                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7)
                {
                    aGame.WrongAnswer();
                }
                else
                {
                    isWinnerDetermined = !aGame.WasLoser();
                }
            }
            while (!isWinnerDetermined);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Random random = new Random();

            Game game = new Game();

            game.AddPlayer("Chet");
            game.AddPlayer("Pat");
            game.AddPlayer("Sue");

            try
            {
                if (game.IsPlayable())
                {
                    Console.WriteLine("Start the game!\r\n");

                    bool isWinner = false;

                    do
                    {
                        game.SelectNexPlayer();

                        int roll = random.Next(5) + 1;
                        game.Roll(roll);

                        int turn = random.Next(9);
                        isWinner = game.Turn(turn);

                        WinnerShow(isWinner, game);
                    } while (!isWinner);
                }
                else
                {
                    Console.WriteLine("The game is not playable, because not enough players.");
                }
            }
            catch (Exception ex)
            {
                //Here we can define logger (Log4net or NLog) functionality.
                Console.WriteLine("The GameRunner throwed exception {0}", ex);
            }

            // Keep the console window open in debug mode.
            Console.WriteLine("-----------------------");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var aGame = new Game();
            var rand = new Random();

            aGame.GetAnswerForQuestion = q => rand.Next(9);

            aGame.AddPlayer("Chet");
            aGame.AddPlayer("Pat");
            aGame.AddPlayer("Sue");

            aGame.Start();

            while (!Game.IsFinished)
            {
                aGame.PlayTurn(rand.Next(5) + 1);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var aGame = new Game();

            aGame.AddPlayer("Chet");
            aGame.AddPlayer("Pat");
            aGame.AddPlayer("Sue");

            var rand = new Random();

            do
            {
                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7)
                {
                    _notAWinner = aGame.WasCorrectlyAnswered();
                }
                else
                {
                    _notAWinner = aGame.WrongAnswer();
                }
            } while (_notAWinner);
        }
Exemplo n.º 5
0
        public static void Main(String[] args)
        {
            Game aGame = new Game();

            aGame.AddPlayer("Chet");
            aGame.AddPlayer("Pat");
            aGame.AddPlayer("Sue");

            Random rand = args.Any() ? new Random(args.First().GetHashCode()) : new Random();

            do
            {
                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7)
                {
                    notAWinner = aGame.IncorrectPlayerAnswer();
                }
                else
                {
                    notAWinner = aGame.CorrectPlayerAnswer();
                }
            } while (notAWinner);
        }
Exemplo n.º 6
0
        public static void Main(String[] args)
        {
            Game aGame = new Game(new QuestionManager());

            aGame.AddPlayer("Chet");
            aGame.AddPlayer("Pat");
            aGame.AddPlayer("Sue");

            Random rand = new Random(1);

            do
            {
                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7)
                {
                    notAWinner = aGame.GotWrongAnswer();
                }
                else
                {
                    notAWinner = aGame.GotCorrectAnswer();
                }
            } while (notAWinner);
        }
Exemplo n.º 7
0
 private void AddPlayers()
 {
     game.AddPlayer("Chet");
     game.AddPlayer("Pat");
     game.AddPlayer("Sue");
 }