-
May 13th, 2003, 10:42 AM
#1
Thread Starter
Lively Member
Bowling Score Algorithm
Hey everyone...
I am attempting to write a program that calculates the score of a bowling game. I have the pinfall's stored in a 2-d array
pinfall(n,m)
-where n is the framenumber 1-10 and m is the shot number 1,2
I am having trouble writing the code to calculate the score. If there are any suggestions, please post 'em
-Mike
"Have you ever woken up, looked at yourself in the mirror, and said 'screw the diet, how fat can i possibly get'?"
-
May 13th, 2003, 11:17 AM
#2
Hyperactive Member
what if you get a strike in the last frame?
how is that score tracked?
-
May 13th, 2003, 11:26 AM
#3
Thread Starter
Lively Member
#Region " Basic Commands (Button Click & Form Load)"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frame(9, 3) As Integer
getvalues(frame)
End Sub
#End Region
#Region " This is Where the values are retrieved before sent through the checker "
Sub getvalues(ByRef frame As Array)
Dim bonus As Integer
'First Frame
frame(0, 1) = CInt(txt11.Text)
frame(0, 2) = CInt(txt12.Text)
'Second Frame
frame(1, 1) = CInt(txt21.Text)
frame(1, 2) = CInt(txt22.Text)
'Third Frame
frame(2, 1) = CInt(txt31.Text)
frame(2, 2) = CInt(txt32.Text)
'Fourth Frame
frame(3, 1) = CInt(txt41.Text)
frame(3, 2) = CInt(txt42.Text)
'Fifth frame
frame(4, 1) = CInt(txt51.Text)
frame(4, 2) = CInt(txt52.Text)
'Sixth Frame
frame(5, 1) = CInt(txt61.Text)
frame(5, 2) = CInt(txt62.Text)
'Seventh Frame
frame(6, 1) = CInt(txt71.Text)
frame(6, 2) = CInt(txt72.Text)
'Eighth Frame
frame(7, 1) = CInt(txt81.Text)
frame(7, 2) = CInt(txt82.Text)
'Ninth Frame
frame(8, 1) = CInt(txt91.Text)
frame(8, 2) = CInt(txt92.Text)
'Tenth Frame
frame(9, 1) = CInt(txt101.Text)
frame(9, 2) = CInt(txt102.Text)
checker(frame, bonus) 'After input, check all values ** RUN CHECKER **
End Sub
#End Region
#Region " This is the Value Checker. "
Sub checker(ByVal frame As Array, ByVal bonus As Integer)
'Declare temporary variable to assist in value checking
Dim n As Integer
Dim broken As Integer
For n = 0 To 9
If frame(n, 1) > 10 Or frame(n, 1) < 0 Then
broken = n
badval(broken)
Exit Sub
End If
If frame(n, 2) > 10 Or frame(n, 2) < 0 Then
broken = n
badval(broken)
Exit Sub
End If
If n < 9 And (frame(n, 1) + frame(n, 2) > 10 Or frame(n, 1) + frame(n, 2) < 0) Then
broken = n
badval(broken)
Exit Sub
End If
Next
If frame(9, 2) > 10 Or bonus > 10 Or frame(9, 2) < 0 Or bonus < 0 Then
broken = 10
badval(broken)
Exit Sub
End If
calcgame(frame, bonus) 'After Values are checked, go to the scorer
End Sub
#End Region
#Region " This is the Scoring Mechanizm."
Sub calcgame(ByVal frame As Array, ByVal bonus As Integer)
Dim pinfall(9) As Integer
Dim runtot As Integer
Dim n As Integer
For n = 0 To 8 'Scoring the First 9 frames
'STRIKE
If frame(n, 1) = 10 Then
If frame(n + 1, 1) = 10 Then
If n < 8 Then
pinfall(n) = 10 + frame(n + 1, 1) + frame(n + 2, 1)
Else : pinfall(n) = 10 + frame(9, 1) + frame(9, 2)
End If
pinfall(n) = 10 + frame(n + 1, 1) + frame(n + 1, 2)
'SPARE
ElseIf frame(n, 1) + frame(n, 2) = 10 Then
pinfall(n) = 10 + frame(n + 1, 1)
Else : pinfall(n) = frame(n, 1) + frame(n, 2)
End If
End If
If n = 9 And frame(n, 1) = 10 Then 'Strike in the 10th
pinfall(n) = 10 + frame(n, 1) + bonus
runtot = pinfall(n) + runtot
Exit Sub 'Exit the Scorer After the tenth frame
ElseIf n = 9 And frame(n, 1) + frame(n, 2) = 10 Then 'spare in the tenth\
pinfall(n) = 10 + bonus
runtot = pinfall(n) + runtot
Exit Sub 'Exit the scorer after the tenth Frame
End If
runtot = pinfall(n) + runtot
Next
MsgBox(runtot)
End Sub
#End Region '<-----ERROR IN HERE
#Region " This is where all the errors are sent."
Sub badval(ByVal n As Integer) 'This is when there is an error in input
MsgBox("Error in Frame " & n + 1, MsgBoxStyle.Critical)
End Sub
#End Region
"Have you ever woken up, looked at yourself in the mirror, and said 'screw the diet, how fat can i possibly get'?"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|