Results 1 to 15 of 15

Thread: Above or Below(game help) **CODE INCLUDED**

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Above or Below(game help) **CODE INCLUDED**

    ok now that i have a random roll generated, i would like the user to be able to guess weather the next roll will be above or below the second roll. I have created two command buttons called cmdAbove and cmdBelow
    they should be able to click on their guess
    If anyone could modify my code to do this it would be amazing
    Thank you!!



    Private Sub cmdStart_Click()
    Picture1.Cls
    Dim randomvalue As Integer
    randomvalue = Int(Rnd * 6)
    Picture1.Picture = Image1(randomvalue).Picture
    MsgBox "Will the next roll be above or below the orignal roll?"


    End Sub

  2. #2
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: Above or Below(game help) **CODE INCLUDED**

    Code:
    Dim GuessAbove As Boolean
    
    Private Sub cmdAbove_Click()
        GuessAbove = True
    End Sub
    
    Private Sub cmdBelow_Click()
        GuessAbove = False
    End Sub
    
    Private Sub cmdStart_Click()
    Static LastRoll As Integer
    Dim randomvalue As Integer
    
    Picture1.Cls
    MsgBox "Will the next roll be above or below the orignal roll?"
    randomvalue = Int(Rnd * 6)
    Picture1.Picture = Image1(randomvalue).Picture
    If (randomvalue > LastRoll And GuessAbove) Or (randomvalue < LastRoll And Not GuessAbove) Then
        MsgBox "Correct!!!"
    Else
        MsgBox "Incorrect."
    End If
    LastRoll = randomvalue
    
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    everything seems to be correct
    its just that when i click start, the message box appears
    Will the next roll be above or below the original roll?

    and then it dosent let me pick above or below
    it just automatically says correct or incorrect?

  4. #4
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: Above or Below(game help) **CODE INCLUDED**

    You click on Above or Below, then click on Start.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    i would like the user to first see the dice rolled and then pick above or below
    is that possible?
    sorry for not clarifying enough
    so basically their is two dice being rolled in one game

  6. #6
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: Above or Below(game help) **CODE INCLUDED**

    I'm sorry, I misunderstood. Delete the cmdStart button and try this:

    vb Code:
    1. Dim LastRoll As Integer
    2. Dim CurRoll As Integer
    3.  
    4. Sub Form_Load()
    5.     Call NewRoll
    6.     DoEvents
    7.     Me.Show
    8.     DoEvents
    9.     LastRoll = CurRoll
    10.     MsgBox "Will the next roll be above or below the current roll?"
    11. End Sub
    12.  
    13. Sub NewRoll()
    14.     Dim RndNum As Integer
    15.     Picture1.Cls
    16.     RndNum = CInt(Rnd * 5) + 1 'generates a random number from 1 to 6
    17.     Picture1.Picture = Image1(RndNum).Picture
    18.     CurRoll = RndNum
    19. End Sub
    20.  
    21. Private Sub cmdAbove_Click()
    22.     Call NewRoll
    23.     If CurRoll > LastRoll Then
    24.         MsgBox "Correct!!!"
    25.     Else
    26.         MsgBox "Incorrect."
    27.     End If
    28.     LastRoll = CurRoll
    29.     MsgBox "Will the next roll be above or below the current roll?"
    30. End Sub
    31.  
    32. Private Sub cmdBelow_Click()
    33.     Call NewRoll
    34.     If CurRoll < LastRoll Then
    35.         MsgBox "Correct!!!"
    36.     Else
    37.         MsgBox "Incorrect."
    38.     End If
    39.     LastRoll = CurRoll
    40.     MsgBox "Will the next roll be above or below the current roll?"
    41. End Sub

    I did not test this code. Lemme know if there are any problems.

  7. #7
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: Above or Below(game help) **CODE INCLUDED**

    I just reread your post and noticed you want two dice. My code only uses one. If this is not acceptable then let me know and I will recode it.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    it seems great
    its just that i want to be able to start the program with a command button called start
    right now as soon as i start the program it generates a roll automatically
    i would like it to generate the roll at a click of a button
    i was also wondering if i could output the second dice roll in a another picture box, so the user knows exact value of the second roll.


    but other then that its perfect
    thanks alot

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    does anyone understand?

  10. #10
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: Above or Below(game help) **CODE INCLUDED**

    Sorry for the delayed response. I think I understand what you are asking, but why do you need 3 buttons?

    You want them to have to click on "Above" or "Below", then click on a start button instead of it doing the roll automatically when they guess?

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    i want them to click on the start button
    then a roll generates and is displayed in a picoutput
    then i want them to guess weather the next roll will be above or below the roll just generated
    then i want it to generate the second roll, that will be compared with the first roll to give them a result ex: You are correct ( If posssible display the second roll in another picture box)

    Then they can start the whole process over if they want, by clicking start again

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    Does anyone understand?

  13. #13
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: Above or Below(game help) **CODE INCLUDED**

    I wouldn't use a Msgbox, but just a label. In that case this might be what you want:

    1. A form with a "start" button, a "Higher" button, and a "Lower button". Two picture boxes, and one label.

    2. The form loads but nothing happens. The Higher button and Lower button are not enabled. The Label says "Click the Start button"

    3. Start button is clicked, a random number from 1 to 6 is created, and a die is shown in one of the picture boxes. The Start button is disabled, the label changes to say "Select whether the next roll will be higher or lower". The Higher and Lower buttons are enabled.

    4. User clicks either Higher or Lower button.

    5. A new random number is generated between 1 and 6 and an image is displayed in the 2nd picture box. The Higher and Lower buttons are disabled. The Start button is enabled. The label reads either "Correct. Press Start for a new game" or "Incorrect. Press Start for a new game", depending on whether the guess was correct or not.

    6. The start button is clicked again. Both picture boxes are cleared, and then everything repeats as shown in step 3 above.

    Is that basically what you want?

    I would personally use "Higher" and "Lower" rather than "Above" and "Below", but you can use whatever you want.

    You didn't say what to do if the two numbers are the same.

    Is this a class assignment, or just something you're doing on your own?

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    Caskbill.. I agree
    Can anyone modify my code to do that?

    1.
    Dim LastRoll As Integer
    2.
    Dim CurRoll As Integer
    3.

    4.
    Sub Form_Load()
    5.
    Call NewRoll
    6.
    DoEvents
    7.
    Me.Show
    8.
    DoEvents
    9.
    LastRoll = CurRoll
    10.
    MsgBox "Will the next roll be above or below the current roll?"
    11.
    End Sub
    12.

    13.
    Sub NewRoll()
    14.
    Dim RndNum As Integer
    15.
    Picture1.Cls
    16.
    RndNum = CInt(Rnd * 5) + 1 'generates a random number from 1 to 6
    17.
    Picture1.Picture = Image1(RndNum).Picture
    18.
    CurRoll = RndNum
    19.
    End Sub
    20.

    21.
    Private Sub cmdAbove_Click()
    22.
    Call NewRoll
    23.
    If CurRoll > LastRoll Then
    24.
    MsgBox "Correct!!!"
    25.
    Else
    26.
    MsgBox "Incorrect."
    27.
    End If
    28.
    LastRoll = CurRoll
    29.
    MsgBox "Will the next roll be above or below the current roll?"
    30.
    End Sub
    31.

    32.
    Private Sub cmdBelow_Click()
    33.
    Call NewRoll
    34.
    If CurRoll < LastRoll Then
    35.
    MsgBox "Correct!!!"
    36.
    Else
    37.
    MsgBox "Incorrect."
    38.
    End If
    39.
    LastRoll = CurRoll
    40.
    MsgBox "Will the next roll be above or below the current roll?"
    41.
    End Sub
    Last edited by ClassX; May 23rd, 2009 at 04:44 PM.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: Above or Below(game help) **CODE INCLUDED**

    anyone get it?

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