【发布时间】:2017-11-18 10:16:57
【问题描述】:
我会简短地说:基本的刽子手游戏,它循环播放玩家 2 的字母选择,如果它与玩家 1 单词的第一个字符不匹配,它将删除一个生命,第二个,直到它要么无论玩家 1 字长是多少条生命,都能找到匹配项或被删除。
我显然不希望这样,我希望它检查数组 - 如果没有匹配,则删除生命。
for (int i = 0; i < playerTwoGuesses.Length; i++)
{
Thread.Sleep(1400);
Console.Write("Guess: ");
count = 0;
do
{
try
{
playerTwoGuesses[i] = char.Parse(Console.ReadLine());
validGuess = true;
}
catch (Exception)
{
Console.WriteLine("Please enter a single character only.");
}
} while (validGuess == false);
for (int j = 0; j < playerOneDisguised.Length; j++)
{
if (playerOneCharacters[j] == playerTwoGuesses[i])
{
playerOneDisguised[j] = playerTwoGuesses[i];
}
else
{
lives = lives - 1;
}
}
if (lives == 0)
{
Console.WriteLine("Oh no! It seems you've lost. Closing game in 5 seconds.");
Thread.Sleep(5000);
Environment.Exit(0);
}
Console.WriteLine(playerOneDisguised);
for (int k = 0; k < playerOneDisguised.Length; k++)
{
if (playerOneDisguised[k] != '*')
{
count = count + 1;
if (count == playerOneDisguised.Length)
{
Console.WriteLine("Congratulations you've won!");
Thread.Sleep(1000);
Console.WriteLine("Closing game in 5 seconds.");
Thread.Sleep(5000);
Environment.Exit(0);
}
}
}
}
【问题讨论】:
-
所以你可能想检查输入的字母是否包含在单词中。如果没有,一条生命就被移除了……