我正在开发基于新工具和新技术的hang子手游戏,但我还没有达到这部分课程的工作内容,但是我试图取得一个良好的开端。C#hang子手,操纵字符串
到目前为止,我有这个代码(见下文)我试图显示零数组元素中的每个字符的下划线(总共七个字符),然后揭示一个字符位置,如果猜测它正确,我只是看除了我的代码之外,还有一些洞察力,可能是一篇文章,甚至是一段代码片段,这可能会让我对两难处境有所了解。
编辑:这是我的新代码,但是,在进入亚利桑那州'a'时,它只能找到并打印第一个'a'我该如何解决这个问题以找到并打印两个控制台?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Array_Arizona_Test
{
class Program
{
static void Main(string[] args)
{
int count = 0;
string secretWord = "arizona";
char[] secret = new char[secretWord.Length];
Console.WriteLine("Welcome to Hangman!");
Console.WriteLine("\nFirst Word.....\n");
for (int i = 0; i < secret.Length; i++)
{
secret[i] = '_';
}
for (int i = 0; i < secret.Length; i++)
{
Console.Write(secret[i] + " ");
}
do
{
for (int i = 0; i < secretWord.Length; i++)
{
Console.Write("\n\nPlease enter your guess : ");
char input = (Console.ReadLine().ToCharArray()[0]);
if (secretWord[i] == input)
{
secret[i] = input;
for (int x = 0; x < secret.Length; x++)
{
Console.Write(secret[x] + " ");
}
}
else
{
for (int j = 0; j < secret.Length; j++)
{
Console.Write(secret[i] + " ");
}
}
}
count++;
} while (count < 5);
}
}
}
有什么问题的代码? –
[这是一个答案](http://stackoverflow.com/questions/20449517/find-every-same-letters-in-a-word),可以帮助你。 – paqogomez
请阅读第二段的前两行,我试图让控制台显示猜测字符的位置,如果其正确,那么迄今为止,它会打印太多的下划线给控制台。 –