Пример #1
0
        static void Main(string[] args)
        {
            int randomNum;
            var randNum        = new Random();
            var rockPlayer     = new PlayerRock();
            var paperPlayer    = new PlayerPaper();
            var scissorsPlayer = new PlayerScissors();

            for (var i = 1; i <= 100; i++)
            {
                randomNum = randNum.Next(1, 4);
                switch (randomNum)
                {
                case 1:
                    Fight(rockPlayer, paperPlayer);
                    break;

                case 2:
                    Fight(rockPlayer, scissorsPlayer);
                    break;

                case 3:
                    Fight(paperPlayer, scissorsPlayer);
                    break;
                }
            }
            Console.WriteLine("Rock Wins:      " + rockPlayer.Wins);
            Console.WriteLine("Paper Wins:     " + paperPlayer.Wins);
            Console.WriteLine("Scissors Wins:  " + scissorsPlayer.Wins);
            Console.ReadLine();
        }
Пример #2
0
 static void Main(string[] args)
 {
     int randomNum;
     var randNum = new Random();
     var rockPlayer = new PlayerRock();
     var paperPlayer = new PlayerPaper();
     var scissorsPlayer = new PlayerScissors();
     for (var i = 1; i <= 100; i++) {
         randomNum = randNum.Next(1,4);
         switch (randomNum) {
             case 1:
                 Fight(rockPlayer, paperPlayer);
                 break;
             case 2:
                 Fight(rockPlayer, scissorsPlayer);
                 break;
             case 3:
                 Fight(paperPlayer, scissorsPlayer);
                 break;
         }
     }
     Console.WriteLine("Rock Wins:      " + rockPlayer.Wins);
     Console.WriteLine("Paper Wins:     " + paperPlayer.Wins);
     Console.WriteLine("Scissors Wins:  " + scissorsPlayer.Wins);
     Console.ReadLine();
 }
Пример #3
0
        // Class Method

        public Game()

        /* Use the Game() constructor is used to initialize the Player_______ properties.
         * If you neglect to initialize these properties then you will get a Null Reference Exception when you
         * attempt to interact with the BillingAddress or ShippingAddress properties.
         */
        {
            this.PlayerPaper    = new PlayerPaper();
            this.PlayerRock     = new PlayerRock();
            this.PlayerScissors = new PlayerScissors();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var game = new Game();

            var scissors = new PlayerScissors().Act();
            var rock = new PlayerRock().Act();
            var paper = new PlayerPaper().Act();

            var gameArray = new string[] {
                scissors, rock, paper
            };

            var rnd = new Random(); //Random is a class, not method
            //var x = rnd.Next(gameArray.Length);
            //var x2 = gameArray[x];

            //Thread.Sleep(3000);

            //var y = rnd.Next(gameArray.Length);
            //var y2 = gameArray[y];

            var counterOne = 0;
            var counterTwo = 0;
            var counterTie = 0;

            for (int i = 0; i < 100; i++)
            {

                var x = rnd.Next(gameArray.Length);
                var x2 = gameArray[x];


                var y = rnd.Next(gameArray.Length);
                var y2 = gameArray[y];

                game.Fight(x2, y2);
                if (game.Fight(x2, y2) == "Player1") {
                    counterOne++;
                }
                else if(game.Fight(x2, y2) == "Player2"){
                    counterTwo++;
                }
                else {
                    counterTie++;
                }
                
            }


            Debug.Assert(game.Fight(scissors, paper) == "Player1");
            Debug.Assert(game.Fight(rock, scissors) == "Player1");
            Debug.Assert(game.Fight(paper, scissors) == "Player2");


            if (counterOne > counterTwo)
            {
                Console.WriteLine("Player One won " + counterOne + " times! They win!");
                Console.WriteLine("Player Two won " + counterTwo + " times! They lose.");
                Console.WriteLine("There were " + counterTie + " ties.");
            }
            else {
                Console.WriteLine("Player Two won " + counterTwo + " times! They win!");
                Console.WriteLine("Player One won " + counterOne + " times! They lose.");
                Console.WriteLine("There were " + counterTie + " ties.");

            }

            Console.ReadLine();
            
        }