-4
私は文字を入力して単語を推測する必要があるゲームHangManに似たコードを作る必要があります。すべてはちょっとうまくいくが、私は間違った手紙を入力すると手紙がその言葉に入っていないと言いたい。助けてください!HangManのようなC#プログラム
string secretword = "m a n a m e j e f f";
string[] secretarray = secretword.Split(' ');
string letter = "";
string[] guessarray = new string[secretarray.Length];
int counter = 0;
int guess = 0;
for (int i = 0; i < guessarray.Length; i++)
{
guessarray[i] = "_";
}
foreach (string s in guessarray)
{
Console.Write(s + " ");
}
while (guess != secretarray.Length)
{
Console.WriteLine();
Console.Write("Enter a letter: ");
letter = Convert.ToString(Console.ReadLine());
for (int i = 0; i < secretarray.Length; i++)
{
if (secretarray[i] == letter)
{
guessarray[i] = letter;
guess++;
}
}
if (guess != 0)
{
foreach (string s in guessarray)
{
Console.Write(s + " ");
}
}
else if (guess == 0)
{
Console.WriteLine("There is no letter like that!");
}
counter++;
}
Console.WriteLine();
Console.WriteLine("You guessd the word with tries: " + counter);
Console.ReadLine();