Results 1 to 8 of 8

Thread: Simple Craps Game

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    33

    Question

    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!"

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    33
    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!"



  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    33
    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??"

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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 \
    Sanity is a full time job

    Puh das war harter Stoff!

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    33
    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....





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