当一个单词有空格(意味着有两个单词)时,我想在该索引中放置一个正斜杠。
所以:你好= _ _ _ _ _ / _ _ _ _ _
目前我的游戏将所有字符转换为下划线,因此如果用户输入两个单词,其他玩家将永远无法正确输入单词。
所以我需要做的基本上是用正斜杠替换 EMPTY SPACE 并且在我处理来自用户的输入时,检查实际单词是否等于 _ _ _ _ _ / _ _ _ _ 等。
即用正斜杠检查。
我的代码:这是生成下划线的代码:
for (int i = 0; i < word.Length; i++)
{
label += "_ ";
}
这是处理用户选择的字母的代码:
public string Process(string gameLetter, string currentWord)
{
underscoredWord = currentWord;
if (word.Contains(gameLetter))
{
correctLetters += gameLetter;
underscoredWord = Regex.Replace(word.Replace(" ", "/"), "[^" + correctLetters + "]", " _");
if (underscoredWord == word)
return underscoredWord;
}
else
tries++;
return underscoredWord; //return with no amendments
}
知道如何修改它们以允许游戏使用两个单词吗?非常感谢任何帮助。