PDA

Click to See Complete Forum and Search --> : Simple Craps Game


cfreiling
Nov 29th, 2000, 12:13 AM
Las Vegas Craps Style Game. Simple class project? I've looked Up and Down left to right, back and forth and asked a few classmates but they dont understand why My game does not work. I have the problem here:

--------------------------------------------------
'Calls Function to Roll Dice
Private Function RollDice() As Integer
Dim Die1 As Integer, Die2 As Integer, DieSum As Integer
Dim a As Integer, b As Integer

Die1 = 1 + Int(6 * Rnd()) 'Roll Die1
Die2 = 1 + Int(6 * Rnd()) 'Roll Die2

Call DisplayDie(imgDie1, Die1) 'Draws die1 image
Call DisplayDie(imgDie2, Die2) '<---Have Problem Here.


mDie1 = Die1 'Stores die1 Value
mDie2 = Die2 'Stores die2 Value
DieSum = Die1 + Die2 'Sum Dice
RollDice = DieSum 'Returns die sum to caller
End Function
--------------------------------------------------
The problem is with Call DisplayDie(imgDie2, Die2).
If its not that it usually when:

-----------------
Private Sub DisplayDie(imgDie As Image, Face As Integer)
imgDie.Picture = ("F:\CIS-5\Ch06\images\die" & Face & ".gif")

End Sub
-----------------

When it calls for the picture(image) its generates a mismatch with the & after Face

I've applied the Full Code for the game below

----------FULL CODE-------------------------------

Option Explicit
Dim mMyPoint As Integer 'General Declaration
Dim mDie1 As Integer 'General Declaration
Dim mDie2 As Integer 'General Declaration


Const snakeEyes = 2 'Explicitly assign 2
Const Trey = 3 'Implicitly assign 3 (snakeEyes + 1)
Const yoleven = 11 'Explicitly assign 11
Const boxcars As Integer = 12 'Implicitly assign 12([yo leven])

Private Sub InitializizeGame(mintMyPoint As Integer)
mMyPoint = 0
fraPoint.Caption = "Point"
lblStatus.Caption = ""
imgPointDie1.Picture = LoadPicture("")
imgPointDie2.Picture = LoadPicture("")
End Sub

Private Sub cmdPlay_Click()
Dim sum As Integer

Call InitializizeGame(0)

'Initialization

Call Randomize

sum = RollDice() 'Invoke rolldice

'Detrimine outcome of first roll
Select Case sum
Case 7, [yoleven]
cmdRoll.Enabled = False 'Disable Roll button
lblStatus.Caption = "You Win!"
Case snakeEyes, Trey, boxcars
cmdRoll.Enabled = False
lblStatus.Caption = "Sorry, You Lose."
Case Else
mMyPoint = sum
fraPoint.Caption = "Point Is " & sum
lblStatus.Caption = "Roll Again."
Call DisplayDie(imgPointDie1, mDie1)
Call DisplayDie(imgPointDie2, mDie2)
cmdPlay.Enabled = False 'Disable Play Button
cmdRoll.Enabled = True 'Enable Roll Button
End Select

End Sub
Private Sub cmdRoll_Click()
Dim sum As Integer

sum = RollDice() 'Invoke rolldice
'Check For a win
If sum = mMyPoint Then 'Win
lblStatus.Caption = "You Win!!!"
cmdRoll.Enabled = False
cmdPlay.Enabled = True
ElseIf sum = 7 Then 'Lose
lblStatus.Caption = "Sorry, You Lose."
cmdRoll.Enabled = False
cmdPlay.Enabled = True
End If

End Sub

Private Sub DisplayDie(imgDie As Image, Face As Integer)
imgDie.Picture = ("F:\CIS-5\Ch06\images\die" & Face & ".gif")

End Sub

Private Function RollDice() As Integer
Dim Die1 As Integer, Die2 As Integer, DieSum As Integer
Dim a As Integer, b As Integer

Die1 = 1 + Int(6 * Rnd()) 'Roll Die1
Die2 = 1 + Int(6 * Rnd()) 'Roll Die2

Call DisplayDie(imgDie1, Die1) 'Draws die1 image
Call DisplayDie(imgDie2, Die2) 'Draws die2 image


mDie1 = Die1 'Stores die1 Value
mDie2 = Die2 'Stores die2 Value
DieSum = Die1 + Die2 'Sum Dice
RollDice = DieSum 'Returns die sum to caller
End Function

Private Sub Form_Load()
Icon = LoadPicture("F:\CIS-5\Ch06\images\die.ico")
End Sub
----------END CODE----------------------------------------

HELP IS WELCOME!!!!
Thanks

"Never Play Leap Frog with a Unicorn!"

HarryW
Nov 29th, 2000, 02:15 AM
Just a guess - where you have

imgDie.Picture = ("F:\CIS-5\Ch06\images\die" & Face & ".gif")

Maybe you could try

imgDie.Picture = ("F:\CIS-5\Ch06\images\die" & Str(Face) & ".gif")

I would have thought that VB would do an implicit cast from integer to string here (the & operator concatenates strings, so the parameters either side must be strings) but perhaps this is causing a problem.

HarryW
Nov 29th, 2000, 02:19 AM
Now I notice it, why are all these string expressions in brackets?

imgDie.Picture = "F:\CIS-5\Ch06\images\die" & Str(Face) & ".gif"

ought to be fine.

cfreiling
Nov 29th, 2000, 02:20 AM
Didnt think about Str, But I'll I'll try it. Thanks.
I even looked over another Game that was done the same way. and Couldnt see what was wrong.

Anyways thanks again I'll chekc it and let ya know...

G'nite (so cali)


"Never Play Leap Frog with a Unicorn!"

cfreiling
Nov 29th, 2000, 02:31 AM
Nah its still hangin up at imgDie2 when

Call DisplayDie(imgDie1, Die1)
Call DisplayDie(imgDie2, Die2) <---

it does fine with imgDie1???

ERRRRR



"No TV NO BEER MAKE HOMER GO... SOMETHING SOMETHING??"

HarryW
Nov 29th, 2000, 02:52 AM
Well, umm, sorry that didn't help. I've had one other thought. Perhaps you should use

imgDie.Picture = LoadPicture("F:\CIS-5\Ch06\images\die" & Str(Face) & ".gif")

I don't know why I think that, I've been up all night and it's nealry 9 am so don't assume I know what I'm talking about :)

/\/\isanThr0p
Nov 29th, 2000, 09:33 AM
what are the names of the pics? is it die1 ...
or is it in the directory die and has the number 1 as name? If yes you forgot a \

cfreiling
Nov 29th, 2000, 05:38 PM
nah Tried that Still didnt work correctly.
and to "/\/\isanThr0p" its the file name then followed by its face value the file type.

Funny thing is I made a new one, the same way I started with the other one. and it works fine... But I'm still gonna try and figure out the last one....

Thanks again Guys....