shad0w
Number of posts : 173 Points : 238 Reputation : 0 Registration date : 2009-03-18 Location : 127.0.0.1
| Subject: [VB6] Hi-Lo [Game] Thu Mar 19, 2009 7:22 pm | |
| This program creates a game of hi-lo where you get to risk point and gain double or lose points. Kind of like a guessing game but with points. - Code:
-
'************************************************************ 'Creates a game of hi-lo where the player risks points and gains double 'if his guess is in the correct range. '************************************************************
Option Explicit
Private intrandom As Integer Const inthigh As Integer = 13 Const intlow As Integer = 1 Private intrisk As Integer Private intplayertotal As Integer
Private Sub cmdDone_Click() Unload Me End Sub
Private Sub cmdhigh_Click() intrandom = rndint(inthigh, intlow) intrisk = txtrisk.Text
If intrandom >= 8 And intrandom <= 13 Then intplayertotal = intplayertotal + (2 * intrisk) lblmessage.Caption = "You Win! The number was " & intrandom & vbCrLf & "Total points = " intplayertotal Else lblmessage.Caption = "You Lose! The number was " & intrandom & vbCrLf & "Total points = " intplayertotal End If End Sub
Private Sub cmdlow_Click() intrandom = rndint(inthigh, intlow) intrisk = txtrisk.Text
If intrandom >= 1 And intrandom <= 6 Then intplayertotal = intplayertotal + (2 * intrisk) lblmessage.Caption = "You Win! The number was " & intrandom & vbCrLf & "Total points = " intplayertotal Else lblmessage.Caption = "You Lose! The number was " & intrandom & vbCrLf & "Total points = " intplayertotal End If End Sub
Private Sub Form_Load() Randomize intplayertotal = 1000 End Sub
Private Sub txtrisk_Change() lblmessage.Caption = "" End Sub
'******************************************************** 'Finds a random number between 13 and 1 and assigns it to rndint ' 'post: rndint is a random number between 1 and 13. '********************************************************
Function rndint(ByVal inthigh As Integer, ByVal intlow As Integer) As Integer rndint = Int(inthigh * Rnd + intlow) End Function | |
|