Você está na página 1de 13

Option Explicit

Dim SelectingMyCase As Boolean

Dim NumOfCasesLeft As Integer

Dim sum As Long ' the bankers offer amount

Dim MyCase As Integer ' users own case

Dim CasePicked As Integer ' case selected by user, not his own

Dim pickcount As Integer ' keeps track of number of cases left to pick

Dim bCount As Integer ' keeps track of number of amounts still showing

Dim PriceArray(26) As String 'holds the money amounts

Dim PM(26) 'randomized number list used for prize money index

Dim PrevArray(9) As String 'stores previous offers

Dim pc As Integer ' index for above array

Private Declare Sub ReleaseCapture Lib "user32" ()

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal
wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Private Sub Form_Load()

Picture1.Enabled = False 'lock gameboard until ready to play

Display.Text = " Press Start to Begin..."

End Sub

Private Sub LoadAmtArray()

Dim x As Integer

PriceArray(0) = ".01"
PriceArray(1) = "1"

PriceArray(2) = "5"

PriceArray(3) = "10"

PriceArray(4) = "25"

PriceArray(5) = "50"

PriceArray(6) = "75"

PriceArray(7) = "100"

PriceArray(8) = "200"

PriceArray(9) = "300"

PriceArray(10) = "400"

PriceArray(11) = "500"

PriceArray(12) = "750"

PriceArray(13) = "1000"

PriceArray(14) = "5000"

PriceArray(15) = "10000"

PriceArray(16) = "25000"

PriceArray(17) = "50000"

PriceArray(18) = "75000"

PriceArray(19) = "100000"

PriceArray(20) = "200000"

PriceArray(21) = "300000"

PriceArray(22) = "400000"

PriceArray(23) = "500000"

PriceArray(24) = "750000"

PriceArray(25) = "1000000"
'load the prize amounts into the windows

For x = 0 To 25

If PriceArray(x) >= 100 Then

lblAmounts(x).Caption = Format(PriceArray(x), "#,##0")

Else

lblAmounts(x).Caption = Format(PriceArray(x), "#,##0.00")

End If

Next x

End Sub

Private Sub LoadPrizeMoneyArray()

Dim MaxNumber As Integer

Dim seq As Integer

Dim MainLoop As Integer

Dim ChosenNumber As Integer

Dim A(26)

Dim x As Integer

MaxNumber = 25 'Sets the maximum number to pick

For seq = 0 To MaxNumber

A(seq) = seq

Next seq

'Main Loop (mix em all up)

Randomize
For MainLoop = MaxNumber To 0 Step -1

ChosenNumber = Int(MainLoop * Rnd)

PM(MaxNumber - MainLoop) = A(ChosenNumber)

A(ChosenNumber) = A(MainLoop)

Next MainLoop

End Sub

Private Sub cmdStart_Click()

Dim x As Integer

MyCase = 0

CasePicked = 0

OT4.Caption = "1" ' set Round number to beginning

pickcount = 6

pc = 0

txtPrevOffer.Visible = False

txtPrevOffer.Text = "Previous Offers" & vbCrLf

NumOfCasesLeft = 26

imgSelectedCase.Visible = False 'hide bottom briefcase from previous game

lblSelectedNum.Visible = False

Display.Text = " Pick a Case"

For x = 0 To 25 'load all briefcases

imgBriefCase(x).Visible = True

lblCaseNum(x).Visible = True

lblAmounts(x).Visible = True
lblCaseNum(x).Caption = x + 1

Next x

'set some values

LoadAmtArray

LoadPrizeMoneyArray

SelectingMyCase = True

Picture1.Enabled = True ' allow gameplay

cmdStart.Visible = False

Picture1.BackColor = &HFF0000 'change background color back to blue

Picture2.BackColor = &HFF0000

Picture4.BackColor = &HFF0000

OT1.BackCol = &HFF0000

OT2.BackCol = &HFF0000

OT3.BackCol = &HFF0000

End Sub

Private Sub cmdDeal_Click()

Dim x As Integer

OT4.Visible = False ' hide Round number

Display.Text = " Deal is " & Format(sum, "$#,##0") & " "

lblSelectedNum.Caption = lblAmounts(PM(MyCase)).Caption

For x = 0 To 25

If imgBriefCase(x).Visible = True Then ' show amounts for remaining briefcases

If lblAmounts(PM(x)).Caption > 50 Then

lblCaseNum(x).Caption = Format(lblAmounts(PM(x)).Caption, "#,##0")


Else

lblCaseNum(x).Caption = Format(lblAmounts(PM(x)).Caption, "#,##0.00")

End If

End If

Next x

cmdStart.Visible = True

cmdDeal.Visible = False

cmdNoDeal.Visible = False

txtPrevOffer.Visible = False

End Sub

Private Sub cmdNoDeal_Click()

Dim x As Integer

cmdDeal.Visible = False

cmdNoDeal.Visible = False

Offer.Enabled = False ' in case you press no deal button before timer is
finished

If NumOfCasesLeft = 19 Then pickcount = 5

If NumOfCasesLeft = 14 Then pickcount = 4

If NumOfCasesLeft = 10 Then pickcount = 3

If NumOfCasesLeft = 7 Then pickcount = 2

If NumOfCasesLeft = 5 Then pickcount = 1

If NumOfCasesLeft = 4 Then pickcount = 1

If NumOfCasesLeft = 3 Then pickcount = 1

If NumOfCasesLeft = 2 Then pickcount = 1


If NumOfCasesLeft = 1 Then

Display.Text = " You Won " & Format(lblAmounts(PM(MyCase)).Caption, "$#,##0.00") & " "

lblSelectedNum.Caption = lblAmounts(PM(MyCase)).Caption ' show users prize money

For x = 0 To 25 ' open remaining briefcases and show prize


money

If imgBriefCase(x).Visible = True Then

lblCaseNum(x).Caption = lblAmounts(PM(x)).Caption

End If

Next x

cmdStart.Visible = True

Picture1.Enabled = False ' lock gameboard so you can't screw around

txtPrevOffer.Visible = False

Exit Sub

End If

If pickcount = 1 Then

Display.Text = " Pick " & pickcount & " Case "

Else

Display.Text = " Pick " & pickcount & " Cases "

End If

pickcount = pickcount - 1

Picture1.Enabled = True 'enable game borad to continue game

Picture1.BackColor = &HFF0000 'change background color back to blue

Picture2.BackColor = &HFF0000

Picture4.BackColor = &HFF0000

OT1.BackCol = &HFF0000

OT2.BackCol = &HFF0000
OT3.BackCol = &HFF0000

OT4.Caption = OT4.Caption + 1 ' advance Round number

txtPrevOffer.Visible = False

End Sub

Private Sub cmdExit_Click()

DelayTimer.Enabled = False

Unload Me

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

FormDrag Me

End Sub

Private Sub imgBriefCase_Click(Index As Integer) 'in case user clicks on image and not label

PickingCases Index

End Sub

Private Sub lblCaseNum_Click(Index As Integer) 'in case user clicks on label and not image

PickingCases Index

End Sub

Private Sub PickingCases(Index As Integer)

If SelectingMyCase = True Then

imgBriefCase(Index).Visible = False ' place selected briefcase at bottom of gameboard


lblCaseNum(Index).Visible = False

imgSelectedCase.Visible = True

lblSelectedNum.Visible = True

lblSelectedNum.Caption = Index + 1

MyCase = Index 'save selected case index number

NumOfCasesLeft = NumOfCasesLeft - 1

Display.Text = " Pick " & pickcount & " Cases"

pickcount = pickcount - 1

SelectingMyCase = False

OT4.Visible = True ' show Round number

Exit Sub

End If

If Index = MyCase Then Exit Sub 'if user clicks on selected case it will not disappear

DelayTimer.Enabled = True ' hide case that was clicked on

If pickcount <> 0 Then

Display.Text = " Pick " & pickcount & " Cases"

End If

CasePicked = Index

If PriceArray(PM(Index)) >= 100 Then

lblCaseNum(Index).Caption = Format(PriceArray(PM(Index)), "#,##0")

Else

lblCaseNum(Index).Caption = Format(PriceArray(PM(Index)), "#,##0.00")

End If

If pickcount = 0 Then

Picture1.Enabled = False 'so briefcases cannot be clicked on at end of round


Picture1.BackColor = vbRed ' offer time so change background colors

Picture2.BackColor = vbRed

Picture4.BackColor = vbRed

OT1.BackCol = vbRed

OT2.BackCol = vbRed

OT3.BackCol = vbRed

Calculate ' time to make an offer

Display.Text = " It's The Banker..."

Offer.Enabled = True

Exit Sub

End If

pickcount = pickcount - 1

End Sub

Private Sub DelayTimer_Timer()

Dim x As Integer

'hide case after being selected

For x = 0 To 25

If lblCaseNum(CasePicked).Caption = lblAmounts(x).Caption Then

lblAmounts(x).Visible = False

End If

Next x

imgBriefCase(CasePicked).Visible = False

lblCaseNum(CasePicked).Visible = False

NumOfCasesLeft = NumOfCasesLeft - 1
DelayTimer.Enabled = False

End Sub

Private Sub Offer_Timer()

Display.Text = " His Offer is " & Format(sum, "$#,##0")

txtPrevOffer.Visible = True

Offer.Enabled = False

End Sub

Private Sub Form_Unload(Cancel As Integer)

DelayTimer.Enabled = False

Unload Me

End Sub

Private Sub Calculate()

Dim x As Integer

bCount = 0

sum = 0

For x = 0 To 25 ' just to make sure selected amounts are not showing in amounts
columns

If lblCaseNum(CasePicked).Caption = lblAmounts(x).Caption Then

lblAmounts(x).Visible = False

End If

If lblAmounts(x).Visible = True Then ' count the number of remaining amounts


bCount = bCount + 1

End If

Next x

For x = 0 To 25 ' now add all amounts remaining , together

If lblAmounts(x).Visible = True Then

sum = sum + lblAmounts(x).Caption

End If

Next x

' I'm using simple averaging for the math... nothing complicated, but seems to work okay

If NumOfCasesLeft = 20 Then sum = (sum / bCount) / 2

If NumOfCasesLeft = 15 Then sum = (sum / bCount) / 1.7

If NumOfCasesLeft = 11 Then sum = (sum / bCount) / 1.5

If NumOfCasesLeft = 8 Then sum = (sum / bCount) / 1.3

If NumOfCasesLeft = 6 Then sum = (sum / bCount)

If NumOfCasesLeft = 5 Then sum = (sum / bCount)

If NumOfCasesLeft = 4 Then sum = (sum / bCount)

If NumOfCasesLeft = 3 Then sum = (sum / bCount)

If NumOfCasesLeft = 2 Then sum = (sum / bCount)

If NumOfCasesLeft = 1 Then sum = (sum / bCount)

' round off the offer by removing the last three digits and replacing them with 000

If sum >= 1000 Then

sum = (sum / 1000)


sum = sum & "000"

End If

PrevArray(pc) = Format(sum, "$#,##0")

txtPrevOffer.Text = txtPrevOffer.Text & PrevArray(pc) & vbCrLf

pc = pc + 1

cmdDeal.Visible = True

cmdNoDeal.Visible = True

End Sub

Private Sub FormDrag(TheForm As Form)

ReleaseCapture

Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)

End Sub

Private Sub Picture1_Click()

End Sub

Você também pode gostar