我希望顯示一個簡單的hang子手設計,使用基於用戶輸入的不正確答案的鍵盤中的字符。這些不正確的答案每次都會給hang子手畫一個新的片斷,儘管我不確定如何做到這一點。我已經讓我的程序功能在顯示正確的答案並循環回到新單詞之前循環10次猜測。繪製一個簡單的hang子手設計鏈接到我在c中不正確的猜測#
我問的問題是我不知道如何在C#中對hang子手進行可視化表示,以及如何將其與現有代碼相關聯,以便根據不正確的猜測繪製hang子手的特定部分。我該怎麼做呢?
代碼如下。
namespace ConsoleApplication9
{
class Program
{
static string RandomWord()
{
Random rnd = new Random();
int response = rnd.Next(1, 4);
string randWord = "";
switch (response)
{
case 1:
randWord = "dog";
break;
case 2:
randWord = "robot";
break;
case 3:
randWord = "fish";
break;
case 4:
randWord = "continue";
break;
}
return randWord;
}
static void Main(string[] args)
{
string value = "";
int count = 0;
int gameLoop = 0;
string inData;
Console.WriteLine("Welcome to Hangman here is the first word");
do
{
count = 0;
value = RandomWord();
char[] newValue = new char[value.Length];
for (int i = 0; i < newValue.Length; i++)
{
newValue[i] = '_';
}
for (int i = 0; i < newValue.Length; i++)
{
Console.Write(newValue[i] + " ");
}
do
{
count++;
Console.Write("\n\nPlease enter your guess : ");
char input = (Console.ReadLine().ToCharArray()[0]);
for (int i = 0; i < value.Length; i++)
{
if (value[i] == input)
{
newValue[i] = input;
}
}
for (int x = 0; x < newValue.Length; x++)
{
Console.Write(newValue[x] + " ");
}
string s = (value);
string t = new string(newValue);
int c = string.Compare(s, t);
if (c == 0)
{
count = 10;
Console.WriteLine("\n\nCongratulations you guessed the word {0}", value);
}
} while (count < 10);
string Wrong = (value);
string Wrong2 = new string(newValue);
int gameOver = string.Compare(Wrong, Wrong2);
if (gameOver != 0)
{
Console.WriteLine("\n\nGame Over! the correct word was {0}", value);
}
Console.WriteLine("Would you like to go again? if so press 1 or 0 to exit");
inData = Console.ReadLine();
gameLoop = Convert.ToInt32(inData);
}
while (gameLoop == 1);
}
}
}
你在找什麼樣的幫助?它不是表現得像你想的那樣?你看到什麼行爲?如果你可以對你的問題更精確一些,而不是期待我們讀你的想法,那對我們會有幫助的。 – reuben