forked from jbrains/trivia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclsGame.cls
205 lines (184 loc) · 6.52 KB
/
clsGame.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsGame"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private cPlayers As New Collection
Private iaPlaces(1 To 6) As Integer
Private iaPurses(1 To 6) As Integer
Private baInPenaltyBox(1 To 6) As Boolean
Private cPopQuestions As New Collection
Private cScienceQuestions As New Collection
Private cSportsQuestions As New Collection
Private cRockQuestions As New Collection
Public tbOutPut As TextBox
Private iCurrentPlayer As Integer
Private bIsGettingOutOfPenaltyBox As Boolean
Public Sub Class_Initialize()
iCurrentPlayer = 1
For i = 1 To 50
cPopQuestions.Add ("Pop Question " & i)
cScienceQuestions.Add ("Science Question " & i)
cSportsQuestions.Add ("Sports Question " & i)
cRockQuestions.Add (CreateRockQuestion(i))
Next
End Sub
Private Sub WriteLine(line As String)
tbOutPut.Text = tbOutPut.Text & line & vbCrLf
End Sub
Public Function CreateRockQuestion(iNumber)
CreateRockQuestion = "Rock Question " & iNumber
End Function
Public Function IsPlayable()
IsPlayable = HowManyPlayers >= 2
End Function
Public Function HowManyPlayers()
HowManyPlayers = cPlayers.Count
End Function
Public Function Add(sPlayerName)
cPlayers.Add sPlayerName
iaPlaces(HowManyPlayers) = 0
iaPurses(HowManyPlayers) = 0
baInPenaltyBox(HowManyPlayers) = False
WriteLine sPlayerName & " was added"
WriteLine "They are player number " & cPlayers.Count
Add = True
End Function
Public Sub Roll(iRoll)
WriteLine cPlayers(iCurrentPlayer) & " is the current player"
WriteLine "They have rolled a " & iRoll
If baInPenaltyBox(iCurrentPlayer) Then
If Not iRoll Mod 2 = 0 Then
bIsGettingOutOfPenaltyBox = True
WriteLine cPlayers(iCurrentPlayer) & " is getting out of the penalty box"
iaPlaces(iCurrentPlayer) = iaPlaces(iCurrentPlayer) + iRoll
If iaPlaces(iCurrentPlayer) > 11 Then iaPlaces(iCurrentPlayer) = iaPlaces(iCurrentPlayer) - 12
WriteLine cPlayers(iCurrentPlayer) & _
"'s new location is " & _
iaPlaces(iCurrentPlayer)
WriteLine "The category is " & CurrentCategory
AskQuestion
Else
WriteLine cPlayers(iCurrentPlayer) & " is not getting out of the penalty box"
bIsGettingOutOfPenaltyBox = False
End If
Else
iaPlaces(iCurrentPlayer) = iaPlaces(iCurrentPlayer) + iRoll
If iaPlaces(iCurrentPlayer) > 11 Then iaPlaces(iCurrentPlayer) = iaPlaces(iCurrentPlayer) - 12
WriteLine cPlayers(iCurrentPlayer) & _
"'s new location is " & _
iaPlaces(iCurrentPlayer)
WriteLine "The category is " & CurrentCategory
AskQuestion
End If
End Sub
Private Sub AskQuestion()
If CurrentCategory = "Pop" Then
WriteLine cPopQuestions.Item(1)
cPopQuestions.Remove 1
End If
If CurrentCategory = "Science" Then
WriteLine cScienceQuestions.Item(1)
cPopQuestions.Remove 1
End If
If CurrentCategory = "Sports" Then
WriteLine cSportsQuestions.Item(1)
cPopQuestions.Remove 1
End If
If CurrentCategory = "Rock" Then
WriteLine cRockQuestions.Item(1)
cPopQuestions.Remove 1
End If
End Sub
Private Function CurrentCategory()
If iaPlaces(iCurrentPlayer) = 0 Then
CurrentCategory = "Pop"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 4 Then
CurrentCategory = "Pop"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 8 Then
CurrentCategory = "Pop"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 1 Then
CurrentCategory = "Science"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 5 Then
CurrentCategory = "Science"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 9 Then
CurrentCategory = "Science"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 2 Then
CurrentCategory = "Sports"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 6 Then
CurrentCategory = "Sports"
Exit Function
End If
If iaPlaces(iCurrentPlayer) = 10 Then
CurrentCategory = "Sports"
Exit Function
End If
CurrentCategory = "Rock"
End Function
Public Function WasCorrectlyAnswered()
If baInPenaltyBox(iCurrentPlayer) Then
If bIsGettingOutOfPenaltyBox Then
WriteLine "Answer was correct!!!!"
iaPurses(iCurrentPlayer) = iaPurses(iCurrentPlayer) + 1
WriteLine cPlayers(iCurrentPlayer) & _
" now has " & _
iaPurses(iCurrentPlayer) & _
" Gold Coins."
winner = DidPlayerWin
iCurrentPlayer = iCurrentPlayer + 1
If iCurrentPlayer = cPlayers.Count + 1 Then iCurrentPlayer = 1
WasCorrectlyAnswered = winner
Exit Function
Else
iCurrentPlayer = iCurrentPlayer + 1
If iCurrentPlayer = cPlayers.Count + 1 Then iCurrentPlayer = 1
WasCorrectlyAnswered = True
Exit Function
End If
Else
WriteLine "Answer was corrent!!!!"
iaPurses(iCurrentPlayer) = iaPurses(iCurrentPlayer) + 1
WriteLine cPlayers(iCurrentPlayer) & _
" now has " & _
iaPurses(iCurrentPlayer) & _
" Gold Coins."
winner = DidPlayerWin
iCurrentPlayer = iCurrentPlayer + 1
If iCurrentPlayer = cPlayers.Count + 1 Then iCurrentPlayer = 1
WasCorrectlyAnswered = winner
Exit Function
End If
End Function
Public Function WrongAnswer()
WriteLine "Question was incorrectly answered"
WriteLine cPlayers(iCurrentPlayer) + " was sent to the penalty box"
baInPenaltyBox(iCurrentPlayer) = True
iCurrentPlayer = iCurrentPlayer + 1
If iCurrentPlayer = cPlayers.Count + 1 Then iCurrentPlayer = 1
WrongAnswer = True
End Function
Private Function DidPlayerWin()
DidPlayerWin = Not iaPurses(iCurrentPlayer) = 6
End Function