473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need Help with Code for a Word Game

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:

Expand|Select|Wrap|Line Numbers
  1. Dim GameOver As Boolean
  2.     Dim NumWords As Integer, ThreeWordList(1000) As String, ThreeWordMeaning(1000) As String
  3.     Dim R As Integer, WordsLeft(1000) As Integer
  4.     Dim SecretWord As String, ComputerLetters(3) As String
  5.     Dim myRandom As New Random
  6.  
  7.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.         Dim sreStreamReader As IO.StreamReader
  9.  
  10.         'THIS SHOULD BE OK
  11.         ' Declare your strings
  12.         Dim A As String
  13.  
  14.         sreStreamReader = IO.File.OpenText("dictionary.txt")
  15.         NumWords = 0
  16.  
  17.         'This section of the code should read each line from the file dictionary.txt and
  18.         'store the word in the array ThreeWordList and store the meaning of each word 
  19.  
  20.         'NOT SURE ABOUT THIS PART
  21.         Do Until NumWords = 1000
  22.             NumWords = NumWords + 1
  23.  
  24.             ThreeWordList(NumWords) = A
  25.             ThreeWordMeaning(NumWords) = A
  26.         Loop
  27.  
  28.         'THIS PART SHOULD BE GOOD
  29.         'Close the File and Display messages in the label as below
  30.  
  31.         sreStreamReader.Close()
  32.         lbldisplay.Visible = True
  33.         lbldisplay.Text = "Guess my secret 3 letter word"
  34.         lbldisplay.Text = lbldisplay.Text + ControlChars.NewLine + ControlChars.NewLine + "Press New Game To Start"
  35.         btnNew.Focus()
  36.     End Sub
  37.  
  38.  
  39.  
  40.     Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
  41.         Dim I As Integer
  42.  
  43.         'THIS SHOULD BE OK
  44.         'Start new game clear listbox, clear labels and enable buttons - basic preliminaries
  45.         ListBox1.Items.Clear()
  46.         ListBox1.Items.Add("Guess" + ControlChars.Tab + ControlChars.Tab + "Number of Letters")
  47.  
  48.         'THIS SHOULD BE RIGHT
  49.         'Generate a Random Number which can be from 1 to NumWords in the dictionary which you have computed before
  50.  
  51.         R = myRandom.Next(0, 1001)
  52.  
  53.         'I THINK THIS IS OK
  54.         'Generate a secret word using the random number        
  55.  
  56.         SecretWord = ThreeWordList(Int(Rnd() * NumWords) + 1)
  57.  
  58.         'NEED HELP WITH THIS PART
  59.         'Extract each letter of the secret word and store each letter in an array called ComputerLetters
  60.         ' myRandom.Next(1, 7)
  61.  
  62.  
  63.  
  64.         For I = 1 To NumWords
  65.             WordsLeft(I) = 1
  66.         Next I
  67.  
  68.  
  69.         'THIS PART LOOKS GOOD
  70.         'Ask the user if they want to play and make the panel visible
  71.         lbldisplay.Text = vbCrLf + "Type in Your Guess." + ControlChars.NewLine & "Then click the Guess Button."
  72.         pnlGuess.Visible = True
  73.  
  74.  
  75.     End Sub
  76.  
  77.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  78.         ' exit  current game
  79.         Me.Close()
  80.     End Sub
  81.  
  82.  
  83.  
  84.     Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click
  85.  
  86.         Dim L As String, userLetters(3) As String
  87.         Dim X As Integer, Y As Integer, Z As Integer
  88.         L = txtGuess.Text
  89.  
  90.         'THIS SHOULD BE OK
  91.         'Take the guess of the user and make sure it is 3 characters long
  92.         If Len(L) <> 3 Then
  93.             lbldisplay.Text = "Your Guess Must Have 3 Letters."
  94.         End If
  95.  
  96.         'THIS SHOULD BE OK
  97.         'Get letters and make sure they are distinct
  98.         For X = 1 To 3
  99.             userLetters(X) = Mid(L, X, 1)
  100.         Next X
  101.  
  102.         If userLetters(1) = userLetters(2) Or userLetters(1) = userLetters(3) Or userLetters(2) = userLetters(3) Then
  103.             lbldisplay.Text = "Your Letters Must Be Different."
  104.         End If
  105.  
  106.  
  107.         'NOT SURE ABOUT THIS PART
  108.         'check if the guess is same as secret word then congratulate the user
  109.         ' if not find how many characters are same and display to user
  110.         ' use a for loop
  111.         If L = SecretWord Then
  112.             lbldisplay.Text = "Correct - You Have Won the Game."
  113.         Else
  114.             Z = 0
  115.             For X = 1 To 3
  116.                 For Y = 1 To 3
  117.                     If userLetters(Y) = ComputerLetters(X) Then Z = Z + 1
  118.  
  119.                 Next Y
  120.             Next X
  121.         End If
  122.  
  123.     End Sub
  124.  
  125.     Private Sub btnGiveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGiveUp.Click
  126.  
  127.         'THIS SHOULD BE OK
  128.         'if the user wants to give up tell them the secretword
  129.         lbldisplay.Text = "That is My Word -" + ControlChars.NewLine + SecretWord
  130.  
  131.     End Sub
  132. End Class
Dec 3 '06 #1
0 1684

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: dnphamus13 | last post by:
I'm new to this and drowning right now. I would like to put my database online for viewing. I managed to do the filtering but i need to do PAGING as the XML doc get bigger. From what i understand...
0
by: riflefire | last post by:
Hello Everyone, I am using the new MITE c# text game engine to code up a MUD style game. I need a lot of help as i am new to C#. The reason i need the help is that the engine requires c# scripts to...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
2
by: theronnightstar | last post by:
I am writing an anagram program for my fiance. Figured it would be an excellent task to learn from. The way it is supposed to work is it reads in a word list from a file into a temporary...
4
tpgames
by: tpgames | last post by:
I need a code that forces all people's firefox browsers to give them a horizontal scroll bar regardless of what their tool bars and other factors tell the browser to do. I have a crossword puzzle...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
2
by: shinerankin | last post by:
Hi Guys & Gals: I have a project with using flash that is updated with an xml file. The developer went belly up and is no longer assisting with anything. I need to write a simple html or php form...
5
by: av3rage | last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.