Exemple #1
0
 public static void AddPlayersToGame(DiceGame diceGame, int numOfPlayers)
 {
     for (int i = 0; i < numOfPlayers; i++)
     {
         diceGame.AddPlayer(new Player()
         {
             Name  = $"Player{i + 1}",
             Score = 0
         });
     }
 }
Exemple #2
0
        public static void PrintPlayerTurnInfo(DiceGame game)
        {
            Player activePlayer = game.ActivePlayer;

            Console.WriteLine("Active Player: " + activePlayer.Name);
            Console.Write("Dices: ");
            foreach (Dice dice in game.Dices)
            {
                Console.Write(dice.Face + "   ");
            }
            Console.WriteLine();
            Console.WriteLine("Score: " + activePlayer.Score);
            Console.WriteLine("Turn result: " + activePlayer.History[game.Turn]);
            Console.WriteLine();
        }
Exemple #3
0
        public static void PlayGame(DiceGame game)
        {
            game.StartGame();
            Random random = new Random();

            while (!game.IsGameOver)
            {
                Console.WriteLine("Turn: " + (game.Turn + 1));
                game.PlayTurn(random);
                PrintPlayerTurnInfo(game);
                if (game.IsGameOver)
                {
                    break;
                }
                game.SetNextPlayer();
            }

            GenerateGameResult(game);
        }
Exemple #4
0
        public static void PrintOutGameResult(DiceGame diceGame)
        {
            Player winner = diceGame.TheWinner();

            Console.WriteLine("\n------- Game End. -------\n");

            if (winner == null)
            {
                Console.WriteLine("\nThere is no Winner.\n");
            }
            else
            {
                Console.WriteLine($"The Winner is {winner.Name}.\n");
                for (int i = 0; i < winner.History.Count; i++)
                {
                    Console.WriteLine($"  Round({i + 1}) : {winner.History[i]}");
                }
            }
            Console.WriteLine("\n");
        }
Exemple #5
0
        static void Main(string[] args)
        {
            int numOfPlayer = 2;

            do
            {
                Console.Write("Enter number of players: ");
            } while (!int.TryParse(Console.ReadLine(), out numOfPlayer));

            DiceGame game = new DiceGame(2);

            for (int i = 0; i < numOfPlayer; i++)
            {
                game.AddPlayer(new Player("Player" + (i + 1)));
            }

            Console.WriteLine();

            PlayGame(game);
            Console.ReadKey();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            DiceGame diceGame = new DiceGame(2);

            Console.WriteLine("\nWelcome to Dice Game!!!!!");

            int numOfPlayers = GetNumberOfPlayers();

            AddPlayersToGame(diceGame, numOfPlayers);

            diceGame.Start();
            Console.WriteLine("\n------- Game Start! -------");
            while (!diceGame.IsGameOver)
            {
                diceGame.PlayTurn();
                Console.WriteLine($"{diceGame.ActivePlayer.Name}");
                ShowDiceResult(diceGame.Dices);
                Console.WriteLine($"  Score: {diceGame.ActivePlayer.ThisTurnScore}\tTotal Score: {diceGame.ActivePlayer.Score}");
                Console.ReadLine();
            }

            PrintOutGameResult(diceGame);
        }