C# 如何在“中”显示秘密单词;标签";在c中,按a键;“提交”按钮;在c中#
} 我想要的是创造一个“猜字游戏” 用户在文本框中键入一个单词,并在按下提交按钮时键入C# 如何在“中”显示秘密单词;标签";在c中,按a键;“提交”按钮;在c中#,c#,visual-studio,C#,Visual Studio,} 我想要的是创造一个“猜字游戏” 用户在文本框中键入一个单词,并在按下提交按钮时键入 提交的单词将与文本文件中的随机单词进行比较,如果两个单词都匹配,则游戏获胜。tks您希望在这些处理程序中执行什么操作 编辑所以您想从文件中获取一个随机单词并显示在标签中 为此,您可以使用: var word=File.ReadAllLines(@“位置”) answer=word[new Random().Next(word.Length)]嗯?你的意思是显示星号而不是实际的单词吗?@Ryan我怎么能使用两行
提交的单词将与文本文件中的随机单词进行比较,如果两个单词都匹配,则游戏获胜。tks您希望在这些处理程序中执行什么操作 编辑所以您想从文件中获取一个随机单词并显示在标签中 为此,您可以使用:
var word=File.ReadAllLines(@“位置”)代码>
answer=word[new Random().Next(word.Length)]代码>嗯?你的意思是显示星号而不是实际的单词吗?@Ryan我怎么能使用两行代码,其中“private void我应该把它们放在哪个位置取决于你想让单词出现。如果按下按钮1,那么在处理程序中。首先显示整个单词。只显示部分单词是另一项任务。
public partial class Form1 : Form
{
int ranNum;
Random ranNumGen;
string[] words;
const int post = 20;
public Form1()
{
words = new string[post];
ranNumGen = new Random();
words = File.ReadAllLines(@"C:\Users\User\Desktop\prog\c\c\text.txt");
}
//Start new game
private void button1_Click(object sender, EventArgs e)
{
/*here what i want is that when button1 is pressed the game would start */
}
private void label1_Click(object sender, EventArgs e)
{
/* here in label 1 what i want is random word from a text file to be displayed in a manner that it could be guessed*/
}
private void button2_Click_1(object sender, EventArgs e)
{
/* here this is a "submit" button, a word in a text box is submitted and compared to random word from the text file */
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
/* in this text box the user enters a word, and the word has to match the random word from the text file*/
}
}