Results 1 to 6 of 6

Thread: Building a simple games using random numbers.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    edmonds, Wa USA
    Posts
    2

    Post

    Hi I am trying to build a simple little game that is a guessing game between 1-10 and I am having all types of problems
    If anyone has any suggestions please e-mail me or post any ideas.
    Thank you

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461

    Post

    Mmmm....

    How can people make suggestions to "HELP" you when you don't really tell them what problems you are having.

    You say you are having "all sorts of problems"...

    - Compiling problems?
    - Inability to generate a random number?
    - Number keeps coming up the same?
    - Number is a floating point not an integer?
    - Gives you syntax errors?
    - Type Mismatch errors?
    - GPF errors?
    - Whats a form?

    I mean I could go on all day trying to mind-read what "problems" you have... how about you tell us what they are and we can give you PROPER ideas rather than wishy-washy ones? ;-)

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post This should answer all your questions

    Here's the easiest way to solve your problem, since I'm not sure what your problem is:

    1. Start a new project
    2. On the form, drop 2 labels, 1 textbox, and 2 command buttons.
    3. Don't change any of the default names given to the controls.
    4. Paste the following code into the form's code window.
    5. Run the project.

    Code:
    Option Explicit
    
    Private nMyNumber As Integer
    
    Private Sub Command1_Click()
        Dim nResponse As Integer
        
        Select Case Val(Text1)
            Case Is = nMyNumber
                nResponse = MsgBox("Congratulations! You did it!" & vbNewLine & _
                    vbNewLine & "Do you want to play again?", vbYesNo, "Good Job!")
                If nResponse = vbYes Then
                    Form_Load
                Else
                    End
                End If
            Case Is < nMyNumber
                MsgBox "Sorry, that's wrong. <hint: try a bigger number>"
            Case Else
                MsgBox "Sorry, that's wrong. <hint: try a smaller number>"
        End Select
    End Sub
    
    Private Sub Command2_Click()
        Dim nResponse As Integer
        
        nResponse = MsgBox("The number was " & nMyNumber & vbNewLine & vbNewLine & _
            "Do you want to play again?", vbYesNo, "Quitter!")
            
        If nResponse = vbYes Then
            Form_Load
        Else
            End
        End If
    End Sub
    
    Private Sub Form_Load()
        Dim nGuess As Integer
        
        Randomize   'This randomizes the random number generator seed
        
        'To produce random integers in a given range, use this formula:
        'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    
        nMyNumber = Int(10 * Rnd + 1)
        
        SetUpControls
    End Sub
    
    Private Function SetUpControls()
        With Me
            .Caption = "Guessing Game"
            .Width = 4095
            .Height = 3420
            .Top = (Screen.Height - .Height) / 2
            .Left = (Screen.Width - .Width) / 2
        End With
        With Label1
            .Caption = "Type your guess here:"
            .Width = 1700
            .Top = 1200
            .Left = 840
            .Height = 250
        End With
        With Label2
            .Caption = "I'm thinking of a number between (and including) " & _
                "1 and 10.  See if you can guess what it is!"
            .Width = 3500
            .Top = 240
            .Height = 500
            .Left = 240
        End With
        With Text1
            .Text = ""
            .Top = 1200
            .Width = 500
            .Height = 285
            .Left = 2640
        End With
        With Command1
            .Caption = "Click Here To Submit Guess"
            .Width = 2415
            .Top = 1800
            .Left = 780
            .Height = 375
        End With
        With Command2
            .Caption = "I Give Up"
            .Width = Command1.Width
            .Height = Command1.Height
            .Left = Command1.Left
            .Top = 2400
        End With
    End Function
    If that doesn't take care of you, please post a more descriptive statement defining your problem!

    ~seaweed

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461

    Post

    Way to go Seaweed ;-)

    Alas my philosophy on life has always been different.

    "Give a man a fish and he will eat today... TEACH a man to fish and he will eat forever"

    I hope Seattleman enjoys his little morsel.... he will be back tomorrow to ask you for another one

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post I agree with your philosophy, but...

    I had a little time before dinner and it looked like an easy project.

    Hopefully he will examine the code, see how it works, and gain a little knowledge from it. I know that I have learned volumes from reading other people's code. If he takes his time and looks at it, there is a lot he can learn (about basic concepts).

    ~seaweed

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    edmonds, Wa USA
    Posts
    2

    Post Thanks

    I am trying to learn VB, But I have been having problems putting things in the right place and your message helped me to understand a little more about orginizing the code.
    If anyone has any simple code I would really enjoy seeing it.
    Thanks for all your help Seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width