我正在尝试制作一个简单的霰弹枪游戏,其中用户与CPU以及使用枚举选择镜头,屏蔽或重新加载但是当我去运行我的代码时它只是循环用户和计算机选择的内容。我不知道如何解决这个问题
任何指导都将不胜感激
//Declare Variables
Console.Title = "Welcome To The Shotgune Game";
int CPUBullets = 3, userBullets = 3;
ShotgunOption UserOption;
int userScore = 0;
bool QUIT = false;
double gameCount = 0.0;
Random computer = new Random();
Console.Clear();
Console.WriteLine("SHOOT RELOAD SHIELD");
UserOption = GetOptionFromUser();
ShotgunOption CPUOption = (ShotgunOption)computer.Next(1, 3); // 1 is Shot, 2 is Reload, 3 is Shield
do
{
// if (UserOption == "QUIT")
//{
//break;
//}
do
{
//Console.Write("Please enter choice, or enter QUIT to quit: ");
switch (UserOption)
{
case ShotgunOption.Shoot:
if((int)CPUOption == 1)
{
Console.WriteLine("You chose {0} and the computer chose Shoot. It was a tie!", UserOption);
; userBullets --;CPUBullets --; ++gameCount;
}
else if ((int)CPUOption == 2)
{
Console.WriteLine("You chose {0} and the computer chose Reload. You win!", UserOption);
++userScore; ++gameCount;
}
else if ((int)CPUOption == 3)
{
Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", UserOption);
++gameCount;
}
break;
case ShotgunOption.Reload:
if((int)CPUOption == 1)
{
Console.WriteLine("You chose {0} and the computer chose Shoot. You lose!", UserOption);
++userScore; ++gameCount;
}
else if ((int)CPUOption == 2)
{
Console.WriteLine("You chose {0} and the computer chose Reload. You Both Gain A bullet", UserOption);
userBullets++; CPUBullets++; ++gameCount;
}
else if ((int)CPUOption == 3)
{
Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", UserOption);
}
break;
case ShotgunOption.Shield:
if((int)CPUOption == 1)
{
Console.WriteLine("You chose {0} and the computer chose Shoot. You lose!", UserOption);
++gameCount;
}
else if ((int)CPUOption == 2)
{
Console.WriteLine("You chose {0} and the computer chose Reload. You win!", UserOption);
++userScore; ++gameCount;
}
else if ((int)CPUOption == 3)
{
Console.WriteLine("You chose {0} and the computer chose Shield. No Damage!", UserOption);
++gameCount;
}
break;
}
}
while (UserOption != ShotgunOption.Shield || CPUOption != ShotgunOption.Shield);
} while (QUIT == false || gameCount != 3 || UserOption != ShotgunOption.Shield || CPUOption != ShotgunOption.Shield);
if (gameCount > 1)
{
DisplayResults(UserOption, CPUOption, userScore, userBullets, CPUBullets);
}
答案 0 :(得分:0)
您永远不会在循环中更新用户的输入。一旦用户做出选择,它就永远不会改变
UserOption = GetOptionFromUser();
也应该出现在你的循环中。至少这是我能从快速浏览中看出来的。