コード例 #1
0
ファイル: Program.cs プロジェクト: luisfb/problema1-hbsis
        private static void StartTournament()
        {
            Console.WriteLine("Inform the number of players (4 or 8):");
            short players;

            if (!short.TryParse(Console.ReadKey().KeyChar.ToString(), out players))
            {
                Console.WriteLine("Invalid input.");
                StartUp();
                return;
            }
            if (players != 4 && players != 8)
            {
                Console.WriteLine("Invalid input.");
                StartUp();
                return;
            }
            Console.WriteLine(string.Empty);
            RpsPlayer winner;

            try
            {
                List <TournamentBracket> tournamentBracketList = new List <TournamentBracket>()
                {
                    new TournamentBracket()
                };
                for (var i = 0; i < players; i++)
                {
                    Console.WriteLine($"Inform the name of Player {i + 1}:");
                    var name = Console.ReadLine();
                    Console.WriteLine(string.Empty);
                    Console.WriteLine($"Inform the choice for Player {i + 1} [R/P/S]:");
                    var choice = Console.ReadKey().KeyChar.ToString();
                    Console.WriteLine(string.Empty);
                    var player = new RpsPlayer(name, choice);
                    if (!tournamentBracketList.Last().AddPlayer(player))
                    {
                        tournamentBracketList.Add(new TournamentBracket());
                        tournamentBracketList.Last().AddPlayer(player);
                    }
                }
                var tournament = new Tournament.Tournament(tournamentBracketList);
                var game       = new RpsGame();
                winner = game.GetTournamentWinner(tournament);
            }
            catch (Exception e)
            {
                Console.WriteLine($"**** ERROR: {e.Message}");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("The winner is:");
            Console.WriteLine(winner.PlayerName);
            Console.WriteLine($"With his choice of {winner.Choice}");
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: luisfb/problema1-hbsis
        private static void StartNormalMatch()
        {
            Console.WriteLine("Inform the name of player 1:");
            var name1 = Console.ReadLine();

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Inform the choice for Player 1 [R/P/S]:");
            var choice1 = Console.ReadKey().KeyChar.ToString();

            Console.WriteLine(string.Empty);

            Console.WriteLine("Inform the name of player 2:");
            var name2 = Console.ReadLine();

            Console.WriteLine(string.Empty);
            Console.WriteLine($"Inform the choice for Player 2 [R/P/S]:");
            var choice2 = Console.ReadKey().KeyChar.ToString();

            Console.WriteLine(string.Empty);
            RpsPlayer winner;

            try
            {
                var players = new List <RpsPlayer>()
                {
                    new RpsPlayer(name1, choice1), new RpsPlayer(name2, choice2)
                };
                var game = new RpsGame();
                winner = game.GetWinner(players);
            }
            catch (Exception e)
            {
                Console.WriteLine($"**** ERROR: {e.Message}");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("The winner is:");
            Console.WriteLine(winner.PlayerName);
            Console.WriteLine($"With his choice of {winner.Choice}");
            Console.ReadKey();
        }