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*/
}
}
}
我想要的是创造一个"猜单词游戏" 用户键入文本框中的单词,并按下提交按钮 如果两个单词匹配,则提交的单词将与文本文件中的随机单词进行比较。 tks
答案 0 :(得分:2)
您希望在这些处理程序中做什么?
编辑所以你想从文件中获取一个随机单词并想要在标签中显示?
为此,您可以使用:
var word = File.ReadAllLines(@"Location");
answer = word[new Random().Next(word.Length)];