| Newbie | | Join Date: Nov 2006
Posts: 4
| |
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much appreciated.Here is the code to give more detail: - Dim GameOver As Boolean
-
Dim NumWords As Integer, ThreeWordList(1000) As String, ThreeWordMeaning(1000) As String
-
Dim R As Integer, WordsLeft(1000) As Integer
-
Dim SecretWord As String, ComputerLetters(3) As String
-
Dim myRandom As New Random
-
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Dim sreStreamReader As IO.StreamReader
-
-
'THIS SHOULD BE OK
-
' Declare your strings
-
Dim A As String
-
-
sreStreamReader = IO.File.OpenText("dictionary.txt")
-
NumWords = 0
-
-
'This section of the code should read each line from the file dictionary.txt and
-
'store the word in the array ThreeWordList and store the meaning of each word
-
-
'NOT SURE ABOUT THIS PART
-
Do Until NumWords = 1000
-
NumWords = NumWords + 1
-
-
ThreeWordList(NumWords) = A
-
ThreeWordMeaning(NumWords) = A
-
Loop
-
-
'THIS PART SHOULD BE GOOD
-
'Close the File and Display messages in the label as below
-
-
sreStreamReader.Close()
-
lbldisplay.Visible = True
-
lbldisplay.Text = "Guess my secret 3 letter word"
-
lbldisplay.Text = lbldisplay.Text + ControlChars.NewLine + ControlChars.NewLine + "Press New Game To Start"
-
btnNew.Focus()
-
End Sub
-
-
-
-
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
-
Dim I As Integer
-
-
'THIS SHOULD BE OK
-
'Start new game clear listbox, clear labels and enable buttons - basic preliminaries
-
ListBox1.Items.Clear()
-
ListBox1.Items.Add("Guess" + ControlChars.Tab + ControlChars.Tab + "Number of Letters")
-
-
'THIS SHOULD BE RIGHT
-
'Generate a Random Number which can be from 1 to NumWords in the dictionary which you have computed before
-
-
R = myRandom.Next(0, 1001)
-
-
'I THINK THIS IS OK
-
'Generate a secret word using the random number
-
-
SecretWord = ThreeWordList(Int(Rnd() * NumWords) + 1)
-
-
'NEED HELP WITH THIS PART
-
'Extract each letter of the secret word and store each letter in an array called ComputerLetters
-
' myRandom.Next(1, 7)
-
-
-
-
For I = 1 To NumWords
-
WordsLeft(I) = 1
-
Next I
-
-
-
'THIS PART LOOKS GOOD
-
'Ask the user if they want to play and make the panel visible
-
lbldisplay.Text = vbCrLf + "Type in Your Guess." + ControlChars.NewLine & "Then click the Guess Button."
-
pnlGuess.Visible = True
-
-
-
End Sub
-
-
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
-
' exit current game
-
Me.Close()
-
End Sub
-
-
-
-
Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click
-
-
Dim L As String, userLetters(3) As String
-
Dim X As Integer, Y As Integer, Z As Integer
-
L = txtGuess.Text
-
-
'THIS SHOULD BE OK
-
'Take the guess of the user and make sure it is 3 characters long
-
If Len(L) <> 3 Then
-
lbldisplay.Text = "Your Guess Must Have 3 Letters."
-
End If
-
-
'THIS SHOULD BE OK
-
'Get letters and make sure they are distinct
-
For X = 1 To 3
-
userLetters(X) = Mid(L, X, 1)
-
Next X
-
-
If userLetters(1) = userLetters(2) Or userLetters(1) = userLetters(3) Or userLetters(2) = userLetters(3) Then
-
lbldisplay.Text = "Your Letters Must Be Different."
-
End If
-
-
-
'NOT SURE ABOUT THIS PART
-
'check if the guess is same as secret word then congratulate the user
-
' if not find how many characters are same and display to user
-
' use a for loop
-
If L = SecretWord Then
-
lbldisplay.Text = "Correct - You Have Won the Game."
-
Else
-
Z = 0
-
For X = 1 To 3
-
For Y = 1 To 3
-
If userLetters(Y) = ComputerLetters(X) Then Z = Z + 1
-
-
Next Y
-
Next X
-
End If
-
-
End Sub
-
-
Private Sub btnGiveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGiveUp.Click
-
-
'THIS SHOULD BE OK
-
'if the user wants to give up tell them the secretword
-
lbldisplay.Text = "That is My Word -" + ControlChars.NewLine + SecretWord
-
-
End Sub
-
End Class
|