Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Card Game (21) Dosent work... need help
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
G-lant




PostPosted: Tue Jan 11, 2005 1:43 pm   Post subject: Card Game (21) Dosent work... need help

Heres the code could someone please help me find out whats wrong? oh and BTW its from a book.
code:
Option Explicit
Private Const strPlayer As String = "player"
Private Const strComputer As String = "computer"
Private Const srtDraw As String = "draw"

Private Sub Command1_Click()
    Static intPlayerScore As Integer, intCompScore As Integer, intDrawScore As Integer
    Dim intPlayerTotal As Integer, intCompTotal As Integer
   
    Call dealcard(imgPlayerCard1, intPlayerTotal)
    Call dealcard(imgPlayerCard2, intPlayerTotal)
    Call dealcard(imgPlayerCard3, intPlayerTotal)
   
    Call dealcard(imgComputerCard1, intCompTotal)
    Call dealcard(imgComputerCard2, intCompTotal)
    Call dealcard(imgComputerCard3, intCompTotal)
   
    If winner(intPlayerTotal, intCompTotal) = strPlayer Then
        lblWinner.Caption = "You Won!"
        Call updatescore(intPlayerScore)
        Call showscore(lblScore, intPlayerScore, intCompScore, intDrawScore)
    ElseIf winner(intPlayerTotal, intCompScore, intDrawScore) Then
        lblWinner.Caption = "computer won!"
        Call updatescore(intCompScore)
        Call showscore(lblScore, intplayercsore, intCompScore, intDrawScore)
    Else
        lblWinner.Caption = "It's a draw!"
        Call updatescore(intDrawScore)
        Call showscore(lblScore, intplayer, intCompScore, intDrawScore)
    End If
End Sub
Sub dealcard(ByRef imgCard As Image, ByRef intPlayerTotal As Integer)
    Dim intCardNum As Integer
   
intCardNum = Int(10 * Rnd + 1)
If intCardNum = 1 Then
    imgCard.Picture = LoadPicture(card1.wmf)
ElseIf intCardNum = 2 Then
    imgCard.Picture = LoadPicture(card2.wmf)
ElseIf intCardNum = 3 Then
    imgCard.Picture = LoadPicture(card3.wmf)
    ElseIf intCardNum = 4 Then
    imgCard.Picture = LoadPicture(card4.wmf)
ElseIf intCardNum = 5 Then
    imgCard.Picture = LoadPicture(card5.wmf)
    ElseIf intCardNum = 6 Then
    imgCard.Picture = LoadPicture(card6.wmf)
ElseIf intCardNum = 7 Then
    imgCard.Picture = LoadPicture(card7.wmf)
    ElseIf intCardNum = 8 Then
    imgCard.Picture = LoadPicture(card8.wmf)
ElseIf intCardNum = 9 Then
    imgCard.Picture = LoadPicture(card9.wmf)
    ElseIf intCardNum = 10 Then
    imgCard.Picture = LoadPicture(card10.wmf)
End If
intPlayerTotal = intplatertotal + intCardNum
End Sub

Function winner(ByVal intPlayerTotal As Integer, ByVal intCompTotal As Integer) As String
    Const intlimit As Integer = 21

If (intplatertotal = intCompTotal) Or _
    (intPlayerTotal > intlimit And intCompTotal > intlimit) Then
    winner = strDraw
ElseIf (intCompTotal > intlimit) Or _
    (intplatertotal > intCompTotal And intplatertotal <= limit) Then
    winner = strPlayer
Else
    winner = strComputer
   End If
End Function

Sub updatescore(ByRef intWinner As Integer)
    Const intWinPoints As Integer = 1
   
    intWinner = intWinner + intWinPoints
End Sub

'Sub showscore(ByRef lblLable As lable, ByVal intplayer As Integer, ByVal intComputer As Integer, ByVal intDrawScore As Integer)
    lblScore.Caption = "you:" & intPlayerScore & vbCrLf & "Computer: " & intCompScore & vbCrLf & "Draws:" & intDrawScore
End Sub


Private Sub Command2_Click()
    Unload Me
End Sub
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 11, 2005 10:03 pm   Post subject: (No subject)

come on, get with the program Rolling Eyes

point out problematic code segments or atleast tell us what the problem is. I ain't reading though the code you copied from the book... you're probably missing something.
Mint




PostPosted: Wed Jan 12, 2005 6:37 pm   Post subject: Re: Card Game (21) Dosent work... need help

code:

'Sub showscore(ByRef lblLable As lable, ByVal intplayer As Integer, ByVal intComputer As Integer, ByVal intDrawScore As Integer)
    lblScore.Caption = "you:" & intPlayerScore & vbCrLf & "Computer: " & intCompScore & vbCrLf & "Draws:" & intDrawScore
End Sub


I think that the problem may be that you have this section as a comment but I'm not sure. (Shrug)
SuperGenius




PostPosted: Sun Jan 16, 2005 12:25 am   Post subject: (No subject)

you could tighten that up a fair bit by using arrays.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: