【发布时间】:2020-08-22 04:54:09
【问题描述】:
?: 运算符有问题,所以我尝试了 if-else 块,一切正常。但是当使用 other 运算符时,它就停止工作了。
using System;
namespace firstGame
{
class Program
{
public string playerName;
public int playerScore;
public int gameNumber;
public int playerGuess;
public void GameStart()
{
string r;
Console.WriteLine("Welcome to my first game");
Console.Write("please enter your gamer name : ");
this.playerName= Console.ReadLine();
do
{
this.gameNumber = Convert.ToInt16(new Random().Next(0,10));
this.playerScore = 1;
if (this.playerScore == 1)
{
Console.WriteLine("Guess the hidden number between (1-10)");
do
{
Console.Write("guess number {0} :: ", this.playerScore);
string num = Console.ReadLine();
int.TryParse(num, out _) ? this.playerGuess=Convert.ToInt16(num) : Console.WriteLine("Are you sure it is a number !!?") ;
this.playerScore++;
} while (this.playerGuess != this.gameNumber);
Console.WriteLine("BINGO {0} is the correct number", this.gameNumber);
Console.Write("would you like a new lvl ? (Y/N) :: "); r=Console.ReadLine();
}
else
{
this.playerScore = 0;
break;
}
} while (r=="Y");
}
static void Main(string[] args)
{
new Program().GameStart();
}
}
}
我在某处犯了一个错误,但在哪里和如何超出了我的范围。
【问题讨论】: