尝试在用户按2时重置计数值 [英] trying to get the count value to reset when the user presses 2
问题描述
尝试在用户按下2时重置计数值并获得新的玩家名称。我还在学习,我不能为我的生活找出我做错的事。
class Program
{
public static int guessNumber;
public static Random rand = new Random();
public static bool gameOver;
public static void Main()
{
guessNumber = rand.Next(1,100)+ 1;
var count = 1;
var gamesPlayed = 1;
var userGuess = 0;
字符串名称;
Console.WriteLine(" Hello user weclome to my guessing game \ nplease告诉我你的名字");
name = Console.ReadLine();
do
{
Console.WriteLine("请猜测1到100之间的数字");
userGuess = Convert.ToInt32(Console.ReadLine());
GuessNumber(count,userGuess);
count ++;
} while(gameOver == false);
Console.ReadLine();
}
public static int GuessNumber(int count,int usernumber)
{
var tryAgain = 0;
if(usernumber< guessNumber)
{
Console.WriteLine("太低了。请再试一次!");
Console.WriteLine(count);
}
else if(usernumber> guessNumber)
{
Console.WriteLine("太高了。请再试一次!");
Console.WriteLine(count);
}
其他
{
Console.WriteLine("你的号码做得好!\ n你有'+ count +
"guesses\\\
press 1再次播放\ nnpress 2 to quit");
tryAgain = Convert.ToInt32(Console.ReadLine());
while(tryAgain!= 1&& tryAgain!= 2)
{
Console.WriteLine("请只输入1再播放或2输入退出");
tryAgain = Convert.ToInt32(Console.ReadLine());
}
if(tryAgain.Equals(2))
gameOver = true;
guessNumber = rand.Next(1,100)+ 1;
Console.WriteLine(" Hello user weclome to my guess game game \ nplease告诉我你的名字");
string name = Console.ReadLine();
count = 1;
}
返回计数;
}
}
}
&NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
请编辑您的帖子和地点使用代码按钮将代码放入代码块中,这样可以更轻松地读取代码。
trying to get the count value to reset when the user presses 2 and to get a new name of player also. im still learning and i cannot for the life of me work out what im doing wrong.
class Program { public static int guessNumber; public static Random rand = new Random(); public static bool gameOver; public static void Main() { guessNumber = rand.Next(1, 100) + 1; var count = 1; var gamesPlayed = 1; var userGuess = 0; string name; Console.WriteLine("Hello user weclome to my guessing game\nplease tell me your name"); name = Console.ReadLine(); do { Console.WriteLine("Please guess a number between 1 and 100"); userGuess = Convert.ToInt32(Console.ReadLine()); GuessNumber(count, userGuess); count++; } while (gameOver == false); Console.ReadLine(); } public static int GuessNumber(int count, int usernumber) { var tryAgain = 0; if (usernumber < guessNumber) { Console.WriteLine("Too low. Please have another go!"); Console.WriteLine(count); } else if (usernumber > guessNumber) { Console.WriteLine("Too High. Please have another go!"); Console.WriteLine(count); } else { Console.WriteLine("You got the number right well done!\nYou had " + count + " guesses\npress 1 to play again\npress 2 to quit"); tryAgain = Convert.ToInt32(Console.ReadLine()); while (tryAgain != 1 && tryAgain != 2) { Console.WriteLine("Please input only 1 to play again or 2 to quit"); tryAgain = Convert.ToInt32(Console.ReadLine()); } if (tryAgain.Equals(2)) gameOver = true; guessNumber = rand.Next(1, 100) + 1; Console.WriteLine("Hello user weclome to my guessing game\nplease tell me your name"); string name = Console.ReadLine(); count = 1; } return count; } } }
Please edit your post and place your code into a code block using the code button which allows reading the code much easier,
这篇关于尝试在用户按2时重置计数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!