-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmCricket.vb
2173 lines (1710 loc) · 88.5 KB
/
frmCricket.vb
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'Option Strict On
Option Explicit On
Imports System.IO 'Imports VB = Microsoft.VisualBasic
Friend Class frmCricket
Inherits Form
' -------------------------------------------------------------------------------
' Dart Scorekeeper
'
' Written by Matthew Monroe
' Started in July 1999
' Ported to .NET in 2011
'
' E-mail: [email protected] or [email protected]
' Repository: https://github.com/alchemistmatt
'
' -------------------------------------------------------------------------------
'
' Licensed under the Apache License, Version 2.0; you may not use this file except
' in compliance with the License. You may obtain a copy of the License at
' http://www.apache.org/licenses/LICENSE-2.0
#Region "Constants and Enums"
Private Const MAX_UNDO_HISTORY As Short = 5000
Private Const MAX_BOX_INDEX As Short = 41
Private Const BOXES_PER_COL As Short = 7
Private Const SCOREBOX_SIZE_NORMAL As Short = 33 ' Pixels
Private Const SCOREBOX_SIZE_SMALL As Short = 25 ' Pixels
Private Const SCOREBOX_DIM_ADDON As Short = 5
Private Enum spScorePictureConstants
spZero = 0
spOne = 1
spTwo = 2
spThree = 3
spClosed = 4
spZeroDimmed = 5
spOneDimmed = 6
spTwoDimmed = 7
spThreeDimmed = 8
spClosedDimmed = 9
End Enum
#End Region
#Region "Structures"
Public Structure udtRealTimeStatsType
Public PlayerName As String
Public ThrowCount As Short
Public ScoreTotal As Integer
End Structure
Public Structure usrUndoHistory
Public TeamIndex As Short
Public DartValue As Short
Public Multiplier As Short
Public DistanceFromCenter As Short
Public ValidHits As Short
' Note: ValidHits is a count of how many of the subhits for this throw counted
' i.e. If a player has two 20's, and hits a double 20, but the other
' teams have already closed out 20's, then only the first of the two parts
' of the double 20 actually counts
Public PlayerName As String
End Structure
#End Region
#Region "Module-wide variables"
Private mUndoHistory(MAX_UNDO_HISTORY) As usrUndoHistory ' 1-based array
Private boolDoubledIn() As Boolean
Private intCurrentHole() As Short
Private intMostRecentGolfScore As Short
Private mUndoHistoryCount, mMaxUndoHistoryCount As Short
Private HistoryIndexOfMostRecentTurn As Short
Private mMaxTeamIndexInGame, mMaxBoxIndexInGame As Short
Private mStartTime, mLastClickTime As DateTime
Private mLastClickTeam As Short
Private mPauseDelay As Integer
Private mPlayerRow, mPlayerColumn As Short ' Both are 0-based
' The following variables are used to prevent the history buffer from getting scrambled
Private mUndoRedoInProgress As Boolean
Private mNewGameButtonClicked As Boolean
Private mRelativeScoringEnabled As Boolean
Private mScoreAreaSize As sasScoreAreaSizeConstants
Private mGameType As gtGameTypeConstants = gtGameTypeConstants.gtCricket
#End Region
Public Sub AdvanceToNextTeam(boolSkipEliminatedTeams As Boolean)
Try
Do
If lstCurrentTeam.SelectedIndex < mMaxTeamIndexInGame Then
lstCurrentTeam.SelectedIndex = lstCurrentTeam.SelectedIndex + 1
mPlayerColumn += 1S
Else
lstCurrentTeam.SelectedIndex = 0
mPlayerColumn = 0
If mPlayerRow = 1 Then mPlayerRow = 0 Else mPlayerRow = 1
End If
Loop While boolSkipEliminatedTeams AndAlso
lblWinStatus.Item(lstCurrentTeam.SelectedIndex).Visible AndAlso
lblWinStatus.Item(lstCurrentTeam.SelectedIndex).Text = "Out"
HighlightCurrentPlayer(mPlayerRow, True)
frmDartBoard.ClearDartBoard()
If mUndoHistoryCount >= mMaxUndoHistoryCount Then
HistoryIndexOfMostRecentTurn = mUndoHistoryCount
End If
' Update real-time statistics
UpdateRealTimeStats()
lblCurrentHole.Text = CStr(intCurrentHole(lstCurrentTeam.SelectedIndex))
Catch ex As Exception
HandleException("AdvanceToNextTeam", ex)
End Try
End Sub
Private Sub AddScore(ScoreAmt As Short, ScoreBoxIndex As Short, ScoringTeamIndex As Short)
Dim x As Short
Try
If glbBoolCutThroatCricket Then
If glbCutThroatMode = 0 Then
' Other teams receive points; low score wins
For x = 0 To mMaxTeamIndexInGame
If Not IsClosed(x, ScoreBoxIndex) Then
UpdateTeamScore(x, GetTeamScore(x) + ScoreAmt)
End If
Next x
Else
' Current team receives points; high score wins
UpdateTeamScore(ScoringTeamIndex, GetTeamScore(ScoringTeamIndex) + ScoreAmt)
End If
End If
Catch ex As Exception
HandleException("AddScore", ex)
End Try
End Sub
Private Sub ChangePicAndTag(BoxIndex As Short, increment As Short)
Dim CurrentVal As Short
Try
CurrentVal = GetScoreBoxHitCount(BoxIndex)
CurrentVal += increment
If CurrentVal >= 0 Then
pctScoreBox.Item(BoxIndex).Tag = CurrentVal.ToString
End If
' Update and position HitCount box
txtHitCount.Text = CType(pctScoreBox.Item(BoxIndex).Tag, String)
txtHitCount.Top = pctScoreBox.Item(BoxIndex).Top
txtHitCount.Left = pctScoreBox.Item(BoxIndex).Left - pctScoreBox.Item(BoxIndex).Width
txtHitCount.Visible = True
If CurrentVal >= spScorePictureConstants.spZero And CurrentVal <= spScorePictureConstants.spThree Then
SetPicture(pctScoreBox.Item(BoxIndex), CType(CurrentVal, spScorePictureConstants))
End If
If CurrentVal = spScorePictureConstants.spThree Then
' Player just closed the number; play a sound
PlayWaveFileForPlayer("DartClose", False, True)
End If
mLastClickTime = DateTime.Now
Catch ex As Exception
HandleException("ChangePicAndTag", ex)
End Try
End Sub
Public Function CheckForGameOver(SuppressNotify As Boolean) As Boolean
Dim I, y, x, z, intScoreBoxHitCount As Short
Dim intLowestScore As Short
Dim boolPlayingGolf As Boolean
Dim boolBestScore, boolGameIsOver As Boolean
Dim boolAlreadyKnowGameIsOver As Boolean
Try
' If lblWinStatus.Item(0) is visible and does not contain the word Out, then
' it either contains the word Lose or Win
' In this case, the game _must_ be over
If lblWinStatus.Item(0).Visible = True And lblWinStatus.Item(0).Text <> "Out" Then
boolAlreadyKnowGameIsOver = True
End If
' Check for Game Over
' if a team is all closed _and_ has lower score than others, then game over
' If playing 301 I don't check for game over until past the first "If boolGameIsOver Then" statement
For x = 0 To mMaxTeamIndexInGame
boolGameIsOver = True ' Assume game over (set false later if not)
boolPlayingGolf = False
Select Case mGameType
Case gtGameTypeConstants.gtCricket
For y = 0 To BOXES_PER_COL - 1
If Not IsClosed(x, y) Then
' Not all boxes are closed, game not over yet
boolGameIsOver = False
Exit For
End If
Next y
Case gtGameTypeConstants.gtGolf
' Game is over if all teams are done with hole 18 (and on hole 19)
If intCurrentHole(mMaxTeamIndexInGame) <= 18 Then
boolGameIsOver = False
End If
boolPlayingGolf = True
Case Else ' Includes 301
boolGameIsOver = True
End Select
If boolGameIsOver Then
' Assume best score (set false later if not)
boolBestScore = True
Select Case mGameType
Case gtGameTypeConstants.gtCricket
' Playing Cricket
For z = 0 To mMaxTeamIndexInGame
If z <> x AndAlso glbCutThroatMode = 0 AndAlso GetTeamScore(z) < GetTeamScore(x) OrElse
z <> x AndAlso glbCutThroatMode = 1 AndAlso GetTeamScore(z) > GetTeamScore(x) Then
boolBestScore = False
Exit For
End If
Next z
boolGameIsOver = boolBestScore
Case gtGameTypeConstants.gtGolf
' Teams(s) with lowest score have won
intLowestScore = GetTeamScore(x)
For z = 0 To mMaxTeamIndexInGame
If z <> x Then
If GetTeamScore(z) < intLowestScore Then
intLowestScore = GetTeamScore(z)
End If
End If
Next z
boolGameIsOver = True
Case Else ' Includes 301
' If Score is not zero, then you haven't won
If GetTeamScore(x) <> 0 Then
boolGameIsOver = False
Else
boolGameIsOver = True
End If
End Select
If boolGameIsOver Then
' Game over
lblStatus.Text = "Game Over."
For z = 0 To mMaxTeamIndexInGame
If (boolPlayingGolf AndAlso GetTeamScore(z) = intLowestScore) OrElse
(Not boolPlayingGolf AndAlso z = x) Then
lblWinStatus.Item(z).Text = "Win"
lblWinStatus.Item(z).Font = UpdateFontBold(lblWinStatus.Item(z).Font, True)
Else
lblWinStatus.Item(z).Text = "Lose"
lblWinStatus.Item(z).Font = UpdateFontBold(lblWinStatus.Item(z).Font, False)
End If
Next z
' Update real-time statistics
UpdateRealTimeStats()
If Not SuppressNotify And Not boolAlreadyKnowGameIsOver Then
' Only write the Stats file when user is first notified of game over
' If user hits undo, then wins again, file WILL be written to again
' However, if user clicks chart more after game is won, file will NOT be written
WriteStatsFile(mGameType, mMaxTeamIndexInGame, mStartTime, mUndoHistory, mUndoHistoryCount)
End If
For z = 0 To mMaxTeamIndexInGame
lblWinStatus.Item(z).Visible = True
Next z
mPauseDelay = LONG_TIME_DELAY
Exit For
Else
If mGameType = gtGameTypeConstants.gtCricket Then
' Find teams with scores higher/lower than this team and mark as Out of Play
For z = 0 To mMaxTeamIndexInGame
If (glbCutThroatMode = 0 AndAlso GetTeamScore(z) > GetTeamScore(x)) OrElse
(glbCutThroatMode = 1 AndAlso GetTeamScore(z) < GetTeamScore(x)) Then
lblWinStatus.Item(z).Text = "Out"
lblWinStatus.Item(z).Font = UpdateFontBold(lblWinStatus.Item(z).Font, True)
lblWinStatus.Item(z).Visible = True
' Create this team's boxes
For I = z * BOXES_PER_COL To CShort((z + 1) * BOXES_PER_COL - 1)
intScoreBoxHitCount = GetScoreBoxHitCount(I)
If intScoreBoxHitCount >= spScorePictureConstants.spZero And intScoreBoxHitCount <= spScorePictureConstants.spThree Then
SetPicture(pctScoreBox.Item(I), intScoreBoxHitCount + SCOREBOX_DIM_ADDON)
End If
Next I
End If
Next z
End If
End If
End If
Next x
Catch ex As Exception
HandleException("CheckForGameOver", ex)
End Try
Return boolGameIsOver
End Function
Private Sub ClearAllBoxes()
Dim x As Short
Try
For x = 0 To MAX_BOX_INDEX
SetPicture(pctScoreBox.Item(x), spScorePictureConstants.spZero)
pctScoreBox.Item(x).Tag = spScorePictureConstants.spZero.ToString().Trim
Next x
Catch ex As Exception
HandleException("ClearAllBoxes", ex)
End Try
End Sub
Private Sub DisableOrEnableRow(ScoreIndex As Short, Disable As Boolean)
' If disable = true then Disable if all closed
' if disable = false then Enable if not all closed
Dim intScoreBoxHitCount As Short
Try
Dim x As Short
Dim RowClosed As Boolean
' Check row for all closed
RowClosed = True
For x = 0 To mMaxTeamIndexInGame
If Not IsClosed(x, ScoreIndex) Then
RowClosed = False
Exit For
End If
Next x
If Disable And RowClosed Then
' Disable these boxes
x = BaseIndexValue(ScoreIndex, BOXES_PER_COL)
Do While x <= mMaxBoxIndexInGame
SetPicture(pctScoreBox.Item(x), spScorePictureConstants.spClosed)
pctScoreBox.Item(x).Enabled = False
x = x + BOXES_PER_COL
Loop
ElseIf Not Disable Then
' Enable these boxes and make sure Correct Picture is Showing
x = BaseIndexValue(ScoreIndex, BOXES_PER_COL)
Do While x <= mMaxBoxIndexInGame
intScoreBoxHitCount = GetScoreBoxHitCount(x)
If intScoreBoxHitCount >= 3 Then
SetPicture(pctScoreBox.Item(x), spScorePictureConstants.spThree)
End If
pctScoreBox.Item(x).Enabled = True
x += BOXES_PER_COL
Loop
End If
Catch ex As Exception
HandleException("DisableOrEnableRow", ex)
End Try
End Sub
Private Sub EnableColumn(intThisTeamIndex As Short)
Dim intThisBoxIndex As Short
Dim eScorePictureIndex As spScorePictureConstants
Dim intScoreBoxHitCount As Short
For intThisBoxIndex = intThisTeamIndex * 7 To intThisTeamIndex * 7 + 6
intScoreBoxHitCount = GetScoreBoxHitCount(intThisBoxIndex)
If intScoreBoxHitCount <= 3 Then
eScorePictureIndex = intScoreBoxHitCount
Else
eScorePictureIndex = spScorePictureConstants.spThree
End If
SetPicture(pctScoreBox.Item(intThisBoxIndex), eScorePictureIndex)
Next intThisBoxIndex
End Sub
Public Sub CompleteGolfTurn()
Dim intCurrentTeamIndex As Short
intCurrentTeamIndex = lstCurrentTeam.SelectedIndex
UpdateTeamScore(intCurrentTeamIndex, GetTeamScore(intCurrentTeamIndex) + intMostRecentGolfScore)
intCurrentHole(intCurrentTeamIndex) += 1
' Check for game over - necessary to save stats
CheckForGameOver(False)
End Sub
Public Sub FillPlayerBoxes()
Dim x, y As Short
Dim SavePlayer As String
Try
For x = 0 To MAX_TEAM_INDEX * 2 + 1
With cboPlayerList.Item(x)
' Save current player
SavePlayer = CStr(.SelectedItem)
If String.IsNullOrEmpty(SavePlayer) Then SavePlayer = String.Empty
.Items.Clear()
For y = 0 To glbPlayerCount
If String.IsNullOrEmpty(glbPlayers(y)) Then
If y = 0 Then
.Items.Add(String.Empty)
End If
Else
.Items.Add(glbPlayers(y))
End If
Next y
' Search list for current player and select
For y = 0 To .Items.Count - 1
If CStr(.Items(y)) = SavePlayer Then
.SelectedIndex = y
Exit For
End If
Next y
If y = .Items.Count Then .SelectedIndex = 0
End With
Next x
Catch ex As Exception
HandleException("FillPlayerBoxes", ex)
End Try
End Sub
Public Function GameInProgress() As Boolean
' Returns true if game in progress, and false otherwise
If mUndoHistoryCount > 0 Then
GameInProgress = True
Else
GameInProgress = False
End If
End Function
Private Function GetBoxIndex(intDartValue As Short, intTeamIndex As Short) As Short
If intDartValue <= 20 And intDartValue >= 15 Then
Return 20 - intDartValue + 7 * intTeamIndex
ElseIf intDartValue = 25 Then
Return 6 + 7 * intTeamIndex
Else
Return -1
End If
End Function
Protected Function GetScoreBoxHitCount(intScoreBoxIndex As Short) As Short
Dim intScoreBoxHitCount As Short
If Short.TryParse(pctScoreBox.Item(intScoreBoxIndex).Tag, intScoreBoxHitCount) Then
Return intScoreBoxHitCount
Else
Return 0
End If
End Function
Public Function GetGameType() As gtGameTypeConstants
Return mGameType
End Function
Protected Function GetTeamScore(intTeamIndex As Integer) As Short
Return CShort(lblScore.Item(intTeamIndex).Text)
End Function
Private Sub HideGameForms(blnCallFormCloseMethod As Boolean)
frmDartBoard.Hide()
HideRealTimeStatistics()
If blnCallFormCloseMethod Then
Me.Close()
End If
Me.Hide()
End Sub
Public Sub HideRealTimeStatistics()
frmRealtimeStatistics.Hide()
End Sub
Public Sub HighlightCurrentPlayer(currentPlayerRow As Short, Optional ByVal boolPlayWaveFile As Boolean = False)
Dim intPlayerListIndex, intPlayerListWorkingIndex As Short
Try
' First color all of the players white
For intPlayerListIndex = 0 To MAX_TEAM_INDEX
Me.cboPlayerList.Item(intPlayerListIndex * 2).BackColor = Color.White
Me.cboPlayerList.Item(intPlayerListIndex * 2 + 1).BackColor = Color.White
Next intPlayerListIndex
' Determine the index to highlight
If Me.lstCurrentTeam.SelectedIndex >= 0 Then
If currentPlayerRow = 1 AndAlso Me.cboPlayerList.Item(Me.lstCurrentTeam.SelectedIndex * 2 + 1).SelectedIndex <> 0 Then
intPlayerListWorkingIndex = Me.lstCurrentTeam.SelectedIndex * 2 + 1
Else
intPlayerListWorkingIndex = Me.lstCurrentTeam.SelectedIndex * 2
End If
End If
' Highlight the player
With Me.cboPlayerList.Item(intPlayerListWorkingIndex)
.BackColor = Color.Yellow
Dim strPlayerName As String
strPlayerName = CStr(.SelectedItem)
frmDartBoard.lblCurrentPlayer.Text = strPlayerName
If glbBoolPlayWaveFileForPlayer And boolPlayWaveFile Then
PlayWaveFileForPlayer(strPlayerName, True, False)
End If
End With
Catch ex As Exception
HandleException("HighlightCurrentPlayer", ex)
End Try
End Sub
Private Function IsClosed(TeamIndex As Short, ScoreBoxIndex As Short) As Boolean
Dim CheckIndex As Short
Dim intScoreBoxHitCount As Short
Try
CheckIndex = BaseIndexValue(ScoreBoxIndex, BOXES_PER_COL) + BOXES_PER_COL * TeamIndex
intScoreBoxHitCount = GetScoreBoxHitCount(CheckIndex)
If intScoreBoxHitCount >= 3 Then
Return True
Else
Return False
End If
Catch ex As Exception
HandleException("IsClosed", ex)
End Try
End Function
Public Function LastThreeDartsTotal() As Integer
' Returns the total score of the last three darts thrown
' Checks to make sure all thrown by same player
' If not, only returns total for the same player
' Uses mUndoHistory() to do this
Dim lngIndex, lngTotalScore As Integer
Dim strPlayerName As String
Try
lngTotalScore = 0
If mUndoHistoryCount >= 1 Then
strPlayerName = mUndoHistory(mUndoHistoryCount).PlayerName
For lngIndex = mUndoHistoryCount To mUndoHistoryCount - 2 Step -1
If lngIndex < 0 Then Exit For
If mUndoHistory(lngIndex).PlayerName = strPlayerName Then
lngTotalScore = lngTotalScore + mUndoHistory(lngIndex).DartValue * mUndoHistory(lngIndex).Multiplier
End If
Next lngIndex
End If
Catch ex As Exception
HandleException("LastThreeDartsTotal", ex)
End Try
Return lngTotalScore
End Function
Private Sub LoadScoreBoxes(MaxBoxIndex As Short, MaxBoxNameIndex As Short)
Dim x As Short
Try
' Note that the pctScoreBox and lblBoxName arrays start off already containing one item, at index 0
For x = 1 To MaxBoxIndex
pctScoreBox.AddNewPictureBox()
Next x
For x = 1 To MaxBoxNameIndex * 2 + 1
lblBoxName.AddNewLabel()
Next x
Catch ex As Exception
HandleException("LoadScoreBoxes", ex)
End Try
End Sub
Private Sub LoadScoreLabels()
Dim x As Short
Try
' Note that these label array classes start off already containing one item, at index 0
For x = 1 To MAX_TEAM_INDEX
lblWinStatus.AddNewLabel()
lblScore.AddNewLabel()
lblAltScore.AddNewLabel()
Next x
For x = 0 To lblWinStatus.Count - 1
lblWinStatus.Item(x).Text = "Win"
Next
Catch ex As Exception
HandleException("LoadScoreLabels", ex)
End Try
End Sub
Private Sub LoadSourcePictures()
Dim intIndex As Integer
' Note that the pctSource and pctSourceSmall arrays start off already containing one item, at index 0
pctSource.Item(0).Visible = False
pctSourceSmall.Item(0).Visible = False
For intIndex = 1 To 9
pctSource.AddNewPictureBox()
pctSourceSmall.AddNewPictureBox()
pctSource.Item(intIndex).Visible = False
pctSourceSmall.Item(intIndex).Visible = False
Next
pctSource.Item(0).Image = _pctSource_0.Image
pctSource.Item(1).Image = _pctSource_1.Image
pctSource.Item(2).Image = _pctSource_2.Image
pctSource.Item(3).Image = _pctSource_3.Image
pctSource.Item(4).Image = _pctSource_4.Image
pctSource.Item(5).Image = _pctSource_5.Image
pctSource.Item(6).Image = _pctSource_6.Image
pctSource.Item(7).Image = _pctSource_7.Image
pctSource.Item(8).Image = _pctSource_8.Image
pctSource.Item(9).Image = _pctSource_9.Image
pctSourceSmall.Item(0).Image = _pctSourceSmall_0.Image
pctSourceSmall.Item(1).Image = _pctSourceSmall_1.Image
pctSourceSmall.Item(2).Image = _pctSourceSmall_2.Image
pctSourceSmall.Item(3).Image = _pctSourceSmall_3.Image
pctSourceSmall.Item(4).Image = _pctSourceSmall_4.Image
pctSourceSmall.Item(5).Image = _pctSourceSmall_5.Image
pctSourceSmall.Item(6).Image = _pctSourceSmall_6.Image
pctSourceSmall.Item(7).Image = _pctSourceSmall_7.Image
pctSourceSmall.Item(8).Image = _pctSourceSmall_8.Image
pctSourceSmall.Item(9).Image = _pctSourceSmall_9.Image
End Sub
Private Sub LoadTeamControls()
Dim x As Short
Try
' Note that the cboPlayerList array starts off already containing one item, at index 0
For x = 1 To MAX_TEAM_INDEX
lblTeamName.AddNewLabel()
' Add two player list combox boxes for each team
cboPlayerList.AddNewComboBox()
cboPlayerList.AddNewComboBox()
Next x
' Add one extra combo box
cboPlayerList.AddNewComboBox()
Catch ex As Exception
HandleException("LoadTeamControls", ex)
End Try
End Sub
Private Sub PositionTeamControls(maxTeamIndex As Short, blnPlayingCricket As Boolean)
Dim intPosTop, x, intPosLeft As Short
Dim intTopRowFinalIndex As Short
Try
Select Case maxTeamIndex
Case 2 To 3
intTopRowFinalIndex = 1
Case Else
' Includes 0, 1, 4, 5
intTopRowFinalIndex = 2
End Select
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Then
lblTeamName.Item(0).Top = 3
Else
lblTeamName.Item(0).Top = 3
End If
cboPlayerList.Item(0).Top = lblTeamName.Item(0).Top + 20
If cboPlayerList.Count > 1 Then
cboPlayerList.Item(1).Top = cboPlayerList.Item(0).Top + 23
End If
For x = 0 To MAX_TEAM_INDEX
If x <= intTopRowFinalIndex Then
intPosTop = lblTeamName.Item(0).Top
intPosLeft = lblTeamName.Item(0).Left + x * DISTANCE_BETWEEN_COLUMNS
Else
If blnPlayingCricket Then
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Then
intPosTop = lblTeamName.Item(0).Top + 360
Else
intPosTop = lblTeamName.Item(0).Top + 267
End If
Else
intPosTop = lblTeamName.Item(0).Top + 167
End If
If x - (intTopRowFinalIndex + 1) < lblTeamName.Count Then
intPosLeft = lblTeamName.Item(x - (intTopRowFinalIndex + 1)).Left
Else
intPosLeft = lblTeamName.Item(0).Left + x * DISTANCE_BETWEEN_COLUMNS
End If
End If
If x < lblTeamName.Count Then
lblTeamName.Item(x).Top = intPosTop
lblTeamName.Item(x).Left = intPosLeft
lblTeamName.Item(x).Text = "Team " & x.ToString
If x <= maxTeamIndex Then
lblTeamName.Item(x).Visible = True
Else
lblTeamName.Item(x).Visible = False
End If
End If
If x * 2 < cboPlayerList.Count Then
cboPlayerList.Item(x * 2).Top = lblTeamName.Item(x).Top + 20
cboPlayerList.Item(x * 2).Left = intPosLeft
cboPlayerList.Item(x * 2).Visible = lblTeamName.Item(x).Visible
End If
If x * 2 + 1 < cboPlayerList.Count Then
cboPlayerList.Item(x * 2 + 1).Top = cboPlayerList.Item(x * 2).Top + 23
cboPlayerList.Item(x * 2 + 1).Left = intPosLeft
cboPlayerList.Item(x * 2 + 1).Visible = lblTeamName.Item(x).Visible
End If
Next x
Catch ex As Exception
HandleException("Cricket->PositionTeamControls", ex)
End Try
End Sub
Private Sub PositionAllControls(Optional ByVal blnClearPictures As Boolean = True)
Dim blnPlayingCricket As Boolean
Dim lngHeightDiff As Integer
If mGameType = gtGameTypeConstants.gtCricket Then
blnPlayingCricket = True
Else
blnPlayingCricket = False
End If
PositionTeamControls(mMaxTeamIndexInGame, blnPlayingCricket)
PositionScoreBoxes(MAX_BOX_INDEX, BOXES_PER_COL, mMaxTeamIndexInGame, blnPlayingCricket, blnClearPictures)
PositionScoreLabels(mMaxTeamIndexInGame, blnPlayingCricket)
' Position Current Hole labels
lblCurrentHoleLabel.Top = lblBoxName.Item(0).Top + 33
lngHeightDiff = Math.Abs((lblCurrentHole.Height - lblCurrentHoleLabel.Height) / 2)
If lblCurrentHole.Height <= lblCurrentHoleLabel.Height Then
lblCurrentHole.Top = lblCurrentHoleLabel.Top + lngHeightDiff + 2
Else
lblCurrentHole.Top = lblCurrentHoleLabel.Top - lngHeightDiff + 2
End If
Me.Refresh()
End Sub
Private Sub PositionScoreBoxes(MaxBoxIndex As Short, BoxesPerCol As Short, MaxTeamIndexInGame As Short, blnPlayingCricket As Boolean, Optional ByVal blnClearPictures As Boolean = True)
Dim intPosTop, x, intPosLeft As Short
Dim intDistanceBetweenScoreBoxes As Short
Dim intLabelOffset As Short
Dim intTargetArrayIndex As Short
Try
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Then
intDistanceBetweenScoreBoxes = 33
intLabelOffset = 8
Else
intDistanceBetweenScoreBoxes = 25
intLabelOffset = 4
End If
For x = 0 To MaxBoxIndex
If x < pctScoreBox.Count Then
If Not blnPlayingCricket Then
pctScoreBox.Item(x).Visible = False
Else
If Math.Floor(x / 7) <= MaxTeamIndexInGame Then
pctScoreBox.Item(x).Visible = True
Else
pctScoreBox.Item(x).Visible = False
End If
If x Mod 7 = 0 Then
' First box in column, position based on Team Player Names position
intTargetArrayIndex = Math.Floor(x / 7) * 2 + 1
If intTargetArrayIndex < cboPlayerList.Count Then
intPosTop = cboPlayerList.Item(intTargetArrayIndex).Top + intDistanceBetweenScoreBoxes
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Then
intPosTop += 200
End If
End If
intTargetArrayIndex = Math.Floor(x / 7) * 2
If intTargetArrayIndex >= cboPlayerList.Count Then
intTargetArrayIndex = 0
End If
With cboPlayerList.Item(intTargetArrayIndex)
intPosLeft = .Left + .Width / 2 - pctScoreBox.Item(x).Width / 2
End With
Else
' Remaining boxes in column, position based on first box in column
intTargetArrayIndex = Math.Floor(x / 7) * 7
If intTargetArrayIndex >= pctScoreBox.Count Then
intTargetArrayIndex = 0
End If
intPosTop = pctScoreBox.Item(intTargetArrayIndex).Top + intDistanceBetweenScoreBoxes * BaseIndexValue(x, BoxesPerCol)
intPosLeft = pctScoreBox.Item(intTargetArrayIndex).Left
End If
pctScoreBox.Item(x).Left = intPosLeft
pctScoreBox.Item(x).Top = intPosTop
pctScoreBox.Item(x).Width = pctScoreBox.Item(0).Width
pctScoreBox.Item(x).Height = pctScoreBox.Item(0).Height
If blnClearPictures Then pctScoreBox.Item(x).Image = pctScoreBox.Item(0).Image
End If
End If
Next x
If blnPlayingCricket Then
For x = 0 To 6
If x < lblBoxName.Count Then
lblBoxName.Item(x).Left = pctScoreBox.Item(x).Left - lblBoxName.Item(0).Width + 2
lblBoxName.Item(x).Top = pctScoreBox.Item(x).Top + intLabelOffset
lblBoxName.Item(x).Width = lblBoxName.Item(0).Width
lblBoxName.Item(x).Height = lblBoxName.Item(0).Height
lblBoxName.Item(x).Text = (20 - x).ToString()
lblBoxName.Item(x).Visible = True
If x = 6 Then
lblBoxName.Item(x).Text = "Bull"
lblBoxName.Item(x).Left = lblBoxName.Item(x).Left - 12
lblBoxName.Item(x).Width = lblBoxName.Item(x).Width + intLabelOffset
End If
End If
Next x
For x = 7 To 13
If x < lblBoxName.Count Then
If MaxTeamIndexInGame > 1 Then
lblBoxName.Item(x).Left = lblBoxName.Item(x - 7).Left
lblBoxName.Item(x).Top = pctScoreBox.Item((x - 7) + Math.Floor(MaxBoxIndex / 2) + 1).Top + intLabelOffset
lblBoxName.Item(x).Width = lblBoxName.Item(x - 7).Width
lblBoxName.Item(x).Height = lblBoxName.Item(x - 7).Height
lblBoxName.Item(x).Text = lblBoxName.Item(x - 7).Text
lblBoxName.Item(x).Visible = True
Else
lblBoxName.Item(x).Visible = False
End If
End If
Next x
Else
For x = 0 To 12
If x < lblBoxName.Count Then
lblBoxName.Item(x).Visible = False
End If
Next x
End If
Catch ex As Exception
HandleException("PositionScoreBoxes", ex)
End Try
End Sub
Private Sub PositionScoreLabels(MaxTeamIndexInGame As Short, blnPlayingCricket As Boolean)
Dim x, intFirstBoxIndex As Short
Dim intLabelTopOffset As Short
Try
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Then
intLabelTopOffset = 3
Else
intLabelTopOffset = 1
End If
For x = 0 To MAX_TEAM_INDEX
intFirstBoxIndex = x * 7
If x < lblWinStatus.Count Then
If x * 2 + 1 < cboPlayerList.Count Then
With cboPlayerList.Item(x * 2 + 1)
lblWinStatus.Item(x).Top = .Top + .Height + intLabelTopOffset
If mScoreAreaSize = sasScoreAreaSizeConstants.sasNormal Or Not blnPlayingCricket Then
lblWinStatus.Item(x).Left = .Left + .Width / 2 - lblWinStatus.Item(x).Width / 2
Else
lblWinStatus.Item(x).Left = pctScoreBox.Item(intFirstBoxIndex).Left + pctScoreBox.Item(intFirstBoxIndex).Width + 2
End If
End With
End If
lblWinStatus.Item(x).Text = "Win"
lblWinStatus.Item(x).Visible = False
End If
If x < lblScore.Count Then
If blnPlayingCricket Then
If intFirstBoxIndex + 6 < pctScoreBox.Count Then
With pctScoreBox.Item(intFirstBoxIndex + 6)
lblScore.Item(x).Top = .Top + .Height + intLabelTopOffset
lblScore.Item(x).Left = .Left + .Width / 2 - lblScore.Item(x).Width / 2
End With
End If
Else
If x < lblWinStatus.Count Then
With lblWinStatus.Item(x)
lblScore.Item(x).Top = .Top + .Height + intLabelTopOffset
lblScore.Item(x).Left = .Left + .Width / 2 - lblScore.Item(x).Width / 2
End With
End If
End If