Solved

Guess the Number Game-- cmd button & reset button

Posted on 2007-12-03
2
1,326 Views
Last Modified: 2008-02-01
I am creating a game... "Guess the Number Game"  The progam is to generate a random number, then the user is to attempt to guess the number. The program is to generate hints to the user which allows the user to refine teh guesses as the game goes on, and is to generate the number of guesses taken.

I need help with these items:
1) I don't know how to generate the guesses taken
2) The 'how to play' button is not working. I want it to give the instructions of the game even though they are pretty much self-explanatory in a message box
3) I am tying to get the reset button to work also and I can't get it to work. I don't know whats wrong with it.
4) also I would like to enhance the game a little bit.... more like "warm" "hot" "cold" "freezing" "boiling" or something along those lines.

Please help :) Thanks!!!
Public Class frmproject5
    Inherits System.Windows.Forms.Form
    Dim intNumberToGuess As Long
    Dim previousGuesses As New System.Collections.Hashtable
 
    Private Sub Button1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguess.Click
 
        Dim intGuess As Long
        Dim UpperBound As Long
        Dim LowerBound As Long
 
        If IsNumeric(txtguess.Text) Then
            intGuess = CLng(txtguess.Text)
        Else
            MsgBox("Enter a number into the textbox!")
        End If
 
        Update()
 
        If Not (previousGuesses(intGuess) Is Nothing) Then
            lblinfo.Text() = "youve already tried this number - try again"
 
            MsgBox("youve already tried this number - try again")
 
        Else
 
            If intGuess < intNumberToGuess Then
                lblinfo.Text() = "Too Low!"
 
                MsgBox("Number is Too Low - Have another go!")
 
            ElseIf intGuess > intNumberToGuess Then
 
                lblinfo.Text = "Too High!"
 
                MsgBox("Number is Too High - Have another go!")
 
            ElseIf intGuess = intNumberToGuess Then
 
                lblinfo.Text = "You've Got It!"
 
                MsgBox("Well Done - You've worked out the random number - Now have another go!")
 
                intNumberToGuess = Int((UpperBound - LowerBound + 100) * Rnd() + LowerBound)
 
            End If
 
            'Add the numbers guessed into the listbox
 
            listguess.Items.Add(txtguess.Text)
 
            previousGuesses(intGuess) = intGuess
 
        End If
 
 
 
    End Sub
 
    Private Sub btnHnowToPlay_Click()
        MsgBox("Type a number between 0 and 100 into the box labeled Type Guess Here. The program will generate a random number and will tell you if you've gone to high or to low, keep guessing until you are CORRECT! but you only have 6 guesses.")
    End Sub
 
    Private Sub cmdReset_Click()
        txtguess.Text = ""
        ' listguess.clear()
        lblinfo.Text = ""
        btnguess.Enabled = False
        Randomize()
    End Sub
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intNumberToGuess As Long
        Dim UpperBound As Long
        Dim LowerBound As Long
 
        Randomize()
 
        intNumberToGuess = Int((UpperBound - LowerBound + 100) * Rnd() + LowerBound)
    End Sub
 
End Class

Open in new window

0
Comment
Question by:ashblynn02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 20401117
1) I don't know how to generate the guesses taken
You need a global variable or an (invisible?) field on your form to keep track of the number of guesses.  Upon reflection, why not just have a visible field labelled "Guesses taken" to keep track of that number.   Just add one to it, for each guess. And obviously, set it to zero in the reset logic.


2) The 'how to play' button is not working. I want it to give the instructions of the game even though they are pretty much self-explanatory in a message box

Look at subroutine header for Button_Enter.  That's the way thd how to play subroutine header should look: it needs the parameters and the Handles clause.

3) I am tying to get the reset button to work also and I can't get it to work. I don't know whats wrong with it.

See answer to #2.

4) also I would like to enhance the game a little bit.... more like "warm" "hot" "cold" "freezing" "boiling" or something along those lines.

That's a good idea.  I guess in the Enter button routine you have some logic that calculates how close the guess is and give the feedback, much like you give feed back for "too high or too low".   It's just a little more sophisticated.





0
 
LVL 5

Expert Comment

by:23637269
ID: 21087723
There are quite a few ways to take care of this.
You can generate a type with all the params you want ie grid locations, correct numbers, hintProvided etc...
Then loop through the array and update the hintProvided value so that you can skip it next time.

You can use one of the timer controls to take care of providing the hints, and you can enable/disable the timer based on a chkBox "Provide Hints" and you can pair it with a textbox or radio buttons for interval.

Or you could change the tip caption if you wanted to display hint info.

There are a lot of ways you can go, it sounds like fun.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question