static void Main(string[] args)
        {
            Player randomPlayer = new RandomPlayer("Random Balboa");
            //randomPlayer.Name = "Random Balboa";

            Player rockPlayer = new RockPlayer("Rocky Balboa");
            //rockPlayer.Name = "Rockey Balboa";

            UserPlayer userPlayer = new UserPlayer();

            Console.Write("Enter your Name"); // user input
            userPlayer.Name = Console.ReadLine();;

            Console.WriteLine("Select your rockPlayer!");
            Console.WriteLine("1). Rocky Balboa");
            Console.WriteLine("2). Random Balboa");

            string userInput = Console.ReadLine();

            switch (userInput)
            {
            case "1":
                Play(userPlayer, new RockPlayer("Rocky Balboa"));
                break;

            case "2":
                Play(userPlayer, new RandomPlayer("Random Balboa"));
                break;
            }
        }
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Welcome to the Rock Paper Scissors Competition!\n");
            Console.WriteLine("What is the target score? Enter a number: ");
            int targetScore = Int32.Parse(Console.ReadLine());

            IPlayer player1 = new RandomPlayer();
            IPlayer player2 = new RandomPlayer();

            int round = 1;

            while (player1.Score < targetScore && player2.Score < targetScore)
            {
                Console.WriteLine($"\nRound {round}:");
                Move move1 = player1.NextMove();
                Move move2 = player2.NextMove();

                Miscellaneous.DisplayRoundResult(move1, move2, player1, player2);

                Console.WriteLine($"Score: {player1.Score} - {player2.Score}");
                round++;
            }

            bool player1Won = player1.Score == targetScore;

            Console.WriteLine($"\n\nThe winner is Player {(player1Won ? 1 : 2)} ({(player1Won ? player1.Name : player2.Name)}). Well done {(player1Won ? player1.Owner : player2.Owner)}");
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //RPSChoice choice = RPSChoice.Rock;

            IChoiceGetter p1 = new HumanPlayer(); //could use var, but having the left side be an interface makes things more explicit
            IChoiceGetter p2 = new RandomPlayer();

            var engine = new GameEngine(p1, p2);

            int p1Wins     = 0;
            int p2Wins     = 0;
            int draws      = 0;
            int gameNumber = 1;

            for (int i = 0; i < 100; i++)
            {
                RoundResults result = engine.PlayerRound();

                Console.WriteLine($"Player 1 played {result.P1Choice} and Player 2 played {result.P2Choice}. Game number: {gameNumber}");

                if (result.Result < 0)
                {
                    p1Wins++;
                    Console.WriteLine("Player 1 wins!");
                }
                else if (result.Result > 0)
                {
                    p2Wins++;
                    Console.WriteLine("Player 2 wins!");
                }
                else
                {
                    draws++;
                    Console.WriteLine("Draw!");
                }

                gameNumber++;
            }

            Console.WriteLine("After 100 games: ");
            Console.WriteLine("Player 1 wins: " + p1Wins);
            Console.WriteLine("Player 2 wins: " + p2Wins);
            Console.WriteLine("Draws: " + draws);

            Console.ReadLine();
        }
        /// <summary>
        /// Initialise the Opponent Player for the match users can choose from a finite collection of choices.
        /// </summary>
        /// <returns></returns>
        public IPlayer InitialiseOpponent()
        {
            //Initialise Opponent
            // Request Opponent Type based on list of options:
            var opponentTypeEnumerator = new EnumEnumerator <OpponentType>();
            var opponentTypeOptions    = string.Join(",", opponentTypeEnumerator.EnumerateEnum());
            var requestMessage         = $"Select an Opponent Type from the choices:\n\n{{{opponentTypeOptions}}}";

            var opponentType = (string)InteractionController.RequestInput(requestMessage);

            // Validate Input
            var isValid = opponentTypeOptions.Split(",").ToList().Contains(opponentType);;

            if (!isValid)
            {
                var validationrequest = $"Please provide a Valid choice – The acceptable Opponent Types are as follows:\n\n{opponentTypeOptions}";
                opponentType = InteractionController.RequestValidInput(validationrequest, opponentTypeOptions);
            }

            Enum.TryParse <OpponentType>(opponentType, out var oppType);

            // Switch on OpponentType and instantiate appropriate Player
            IPlayer opponentPlayer = null;

            switch (oppType)
            {
            case OpponentType.Human:
                opponentPlayer = new HumanPlayer("Human", Rules, InteractionController);
                break;

            case OpponentType.Random:
                opponentPlayer = new RandomPlayer("Random", Rules, new Random());
                break;

            case OpponentType.Tactical:
                opponentPlayer = new TacticalPlayer("Tactical", Rules, new Stack <IMove>(), new Random());
                break;
            }

            return(opponentPlayer);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //RPSChoice choice = RPSChoice.Rock;

            IChoiceGetter p1 = new HumanPlayer();
            IChoiceGetter p2 = new RandomPlayer();

            var engine = new GameEngine(p1, p2);

            int p1Wins = 0;
            int p2Wins = 0;
            int draws  = 0;

            for (int i = 0; i < 100; i++)
            {
                RoundResult result = engine.PlayRound();
                Console.WriteLine($"Player 1 played {result.P1Choice}. Player 2 played {result.P2Choice}.");
                if (result.Result < 0)
                {
                    p1Wins++;
                    Console.WriteLine("Player 1 wins!");
                }
                else if (result.Result > 0)
                {
                    p2Wins++;
                    Console.WriteLine("Player 2 wins!");
                }
                else
                {
                    draws++;
                    Console.WriteLine("DRAW!");
                }
            }

            Console.WriteLine("After 100 games: ");
            Console.WriteLine("Player 1 wins: " + p1Wins);
            Console.WriteLine("Player 2 wins: " + p2Wins);
            Console.WriteLine("draws: " + draws);

            Console.ReadLine();
        }
Beispiel #6
0
        public static Moves chooseOpponant(string choice)
        {
            Moves opponantMove = RandomPlayer.makeRandomMove();


            if (choice == "1")
            {
                opponantMove = RandomPlayer.makeRandomMove();
            }
            else if (choice == "2")
            {
                opponantMove = TacticalPlayer.getTacticalMove();
            }
            else
            {
                Console.WriteLine("Did not recognise input, please try again");
                var choose = Console.ReadLine();
                chooseOpponant(choose);
            }

            return(opponantMove);
        }