コード例 #1
0
ファイル: Program.cs プロジェクト: SeungsooKang/DiceGame
 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
         });
     }
 }
コード例 #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();
        }
コード例 #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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: SeungsooKang/DiceGame
        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");
        }
コード例 #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();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: SeungsooKang/DiceGame
        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);
        }