2017-01-25 147 views
-5
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*/ 
    } 
} 

}我怎麼能按在C#

我要的是創造一個「猜字遊戲」 用戶「提交按鈕」顯示在C#中的「標籤」密匙在文本框中鍵入一個單詞,按下提交按鈕時 提交的單詞將與文本文件中的隨機單詞進行比較,如果兩個單詞匹配遊戲獲勝。 tks

+0

咦?你的意思是顯示星號而不是實際的單詞嗎? –

回答

2

你想在這些處理程序中做什麼?

編輯所以你想從文件中得到一個隨機單詞,並希望顯示在標籤?

要做到這一點,你可以使用:

var word = File.ReadAllLines(@"Location");

answer = word[new Random().Next(word.Length)];

+0

@Ryan我如何使用劑量的2行代碼,並在其「私人無效的應我把他們 –

+0

要看你要顯示的文字。如果按下按鈕時1那麼處理程序中。 –

+0

首先顯示整個單詞。要只顯示其中的一部分是另一項任務。 –