我正试图制作一个匈牙利游戏,我想让这个程序会说“恭喜你已经猜到了这个词”如果这个词是可见的? [英] am Trying To Make A Hungman Game And I Want To Make That The Program Will Say "Congrats Your Have Guessed The Word" If The Word Is Visable?
本文介绍了我正试图制作一个匈牙利游戏,我想让这个程序会说“恭喜你已经猜到了这个词”如果这个词是可见的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hänga_gubbe
{
class Program
{
static void Main(string[] args)
{
string s = "saviosa";
char x;
int counter = 0;
string ut = "";
char[] bokstav = new char[7];
for (int i = 0; i < s.Length; i++)
{
bokstav[i] = 'X';
}
do
{
ut = "";
Console.Write("mata in en bokstav: ");
x = Convert.ToChar(Console.ReadLine());
for (int i = 0; i < s.Length; i++)
{
if (s[i] == x)
bokstav[i] = x;
}
counter++;
for (int i = 0; i < s.Length; i++)
{
ut = ut + Convert.ToString(bokstav[i]);
}
Console.WriteLine(ut);
} while (counter < s.Length);
Console.ReadKey();
}
}
}
推荐答案
应该这样做。
This should do.
for (int i = 0; i < s.Length; i++)
{
ut = ut + Convert.ToString(bokstav[i]);
}
Console.WriteLine(ut);
//Add this line
if (ut == s) Console.WriteLine("Congrats, you guessed right");
添加了澄清的代码。
Added code for clarification.
这篇关于我正试图制作一个匈牙利游戏,我想让这个程序会说“恭喜你已经猜到了这个词”如果这个词是可见的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文