Beispiel #1
0
        private void InitializeGame()
        {
            Player player = new BasicPlayer(new Rectangle(100, 200, 30, 30), Color.Red);

            //set hats if any
            if (CheckBoxHat.Checked)
            {
                player = new PlayerHatDecorator(player);
            }
            if (CheckBoxSunGlasses.Checked)
            {
                player = new PlayerSunglassesDecorator(player);
            }

            IBackgroundBuilder      backgroundBuilder       = new BackgroundBuilder();
            BackgroundBuildDirector backgroundBuildDirector = new BackgroundBuildDirector(backgroundBuilder);

            //set the background
            if ((string)ComboBoxBackground.SelectedItem == "Ice")
            {
                backgroundBuildDirector.Construct(EStageStyle.ICE);
            }
            else if ((string)ComboBoxBackground.SelectedItem == "Desert")
            {
                backgroundBuildDirector.Construct(EStageStyle.DESERT);
            }
            else if ((string)ComboBoxBackground.SelectedItem == "Jungle")
            {
                backgroundBuildDirector.Construct(EStageStyle.JUNGLE);
            }
            Background background         = backgroundBuildDirector.GetBackground();
            string     difficultySelected = (string)ComboBoxLevel.SelectedItem;

            IDifficulty difficulty = null;

            //set the difficulty
            if (difficultySelected == "Easy")
            {
                difficulty = new EasyDifficulty();
            }
            else if (difficultySelected == "Hard")
            {
                difficulty = new HardDifficulty();
            }
            else if (difficultySelected == "Impossible")
            {
                difficulty = new ImposibleDifficulty();
            }

            Game = new Game(player, background, difficulty);
            Obstacle.XVelocity = 4.0f;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //get user input
            string input = null;

            while (input != "y" && input != "n")
            {
                Console.Write("Would you like to play Rock Paper Sissors? (y/n): ");
                input = Console.ReadLine();
            }

            var history = new List <Turn>();

            while (input == "y")
            {
                //reset input
                input = null;
                while (input != "e")
                {
                    Console.Write("What Difficulty? (e)asy: ");
                    input = Console.ReadLine();
                }

                IDifficulty comp;
                switch (input)
                {
                case "e":
                    comp = new EasyDifficulty();
                    break;

                default:
                    comp = new EasyDifficulty();
                    break;
                }

                //in interest of fairness, get computer move first
                string compMove = comp.getMove();

                //get player move
                input = null;
                while (input != "r" && input != "p" && input != "s")
                {
                    Console.Write("Please make your choice (\"r\" | \"p\" | \"s\"): ");
                    input = Console.ReadLine();
                }

                string playerMove = null;
                switch (input)
                {
                case "r":
                    playerMove = "Rock";
                    break;

                case "p":
                    playerMove = "Paper";
                    break;

                case "s":
                    playerMove = "Sissors";
                    break;
                }

                //figure out the winner
                var turn = new Turn(playerMove, compMove);

                if (turn.Winner != "Invalid")
                {
                    Console.WriteLine($"You played:\t\t{turn.PlayerHand}");
                    Console.WriteLine($"Computer Played:\t{turn.CompHand}");
                    Console.WriteLine($"The winner is: {turn.Winner}");
                }

                history.Add(turn);

                //ask if the player would like to play again
                input = null;
                while (input != "y" && input != "n")
                {
                    Console.Write("Would you like to play again? (y/n): ");
                    input = Console.ReadLine();
                    Console.Clear();
                }
            }
        }