在当前上下文中不存在

在当前上下文中不存在

本文介绍了在当前上下文中不存在名称“...”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在制作一个简单的猎枪游戏,其中用户与计算机并选择拍摄,屏蔽或重新加载但由于某种原因,在我的while循环结束时,我设置条件,它表示在当前上下文中不存在CPUOption



任何指导都会被暗示



Hi I am making a simple shotgun game where the user vs the computer and pick shoot, shield or reload But for some reason at the end of my while loop where I set the condition it says that CPUOption does not exist in current context

Any guidance would be appercaited

//Declare Variables
            Console.Title = "Welcome To The Shotgune Game";
            int CPUBullets = 3, userBullets = 3;
            ShotgunOption UserOption;
            int computerChoice, userScore = 0;
            bool QUIT = false;
            double gameCount = 0.0;
            Random computer = new Random();

            Console.Clear();
            Console.WriteLine("SHOOT RELOAD SHIELD");
             do
            {
                do
                {
                //Console.Write("Please enter choice, or enter QUIT to quit: ");
                UserOption = GetOptionFromUser();

                if (UserOption.ToUpper() == "QUIT")
                {
                    break;
                }
                ShotgunOption CPUOption = (ShotgunOption)computer.Next(1, 3); // 1 is Shot, 2 is Reload, 3 is Shield



                  switch (UserOption.ToUpper())
                {
                    case "SHOOT":
                        if (CPUOption == 1)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shoot. It was a tie!", userChoice);
                            ; userBullets --;CPUBullets --; ++gameCount;
                        }
                        else if (CPUOption == 2)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Reload. You win!", userChoice);
                            ++userScore; ++gameCount;
                        }
                        else if (CPUOption == 3)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", userChoice);
                            ++gameCount;
                        }
                        break;
                    case "RELAOD":
                        if (CPUOption == 1)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shoot. You lose!", userChoice);
                             ++userScore; ++gameCount;
                        }
                        else if (CPUOption == 2)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Reload. You Both Gain A bullet", userChoice);
                            userBullets++; CPUBullets++; ++gameCount;
                        }
                        else if (CPUOption == 3)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", userChoice);

                        }
                        break;
                    case "SHIELD":
                        if (CPUOption == 1)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shoot. You lose!", userChoice);
                            ++gameCount;
                        }
                        else if (CPUOption == 2)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Reload. You win!", userChoice);
                            ++userScore; ++gameCount;
                        }
                        else if (CPUOption == 3)
                        {
                            Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", userChoice);
                            ++gameCount;
                        }
                        break;

                }
              }
              while (UserOption != ShotgunOption.Shield || CPUOption != 3);
            } while (QUIT == false || gameCount == 3);

推荐答案


这篇关于在当前上下文中不存在名称“...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 04:11