做一個hang子手遊戲我該如何將我的userInput與給定的字符串/字中的字符進行比較,然後如何以某種方式記錄這個正確字符的位置以顯示回用戶。初學者試圖在C#中做一個Hang子手程序
namespace ConsoleApplication5
{
class Program
{
/* static int ResponseCorrect()
{
Random rnd = new Random();
int response = rnd.Next(1, 4);
switch (response)
{
case 1:
RandWord = "Robot";
break;
case 2:
RandWord = "Fish";
break;
case 3:
RandWord = "James";
break;
case 4:
RandWord = "Chocolate";
break;
}
return response;
}*/
static void Main(string[] args)
{
string value = "Robot";
int userInput = 0;
string inData = "";
string inData2 = "";
char myletter = 'd';
bool letterinWord = false;
Console.WriteLine("Welcome to Hangman, Please select a number between 1 and 4 for your number!");
inData = Console.ReadLine();
userInput = Convert.ToInt32(inData);
Console.WriteLine("This is your first guess, enter a letter");
inData2 = Console.ReadLine();
myletter = Convert.ToChar(inData2);
char[] array = value.ToCharArray();
for (int counter = 0; counter < array.Length; counter++)
{
char letter = array[counter];
if (myletter == letter)
{
letterinWord = true;
}
}
if (letterinWord == true)
Console.WriteLine("Congratulations");
else
Console.WriteLine("u suck");
}
}
}
嘗試使您的問題更具體一點,這是目前一般 – Daveo
請刪除不必要的文本和代碼,以便我們可以快速查看實際問題。你不必給我們介紹自己,只要問題和你的嘗試的明確描述,他們的結果和他們的預期結果就足夠了。 –
對不起,這是我的第一篇文章,我想有人爲我編輯,謝謝誰做的。 – user3084866