home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / fMinesweep255998302001.psc / Grid.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-01-14  |  37.5 KB  |  952 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Grid 
  3.    CanGetFocus     =   0   'False
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   4800
  8.    ScaleHeight     =   3600
  9.    ScaleWidth      =   4800
  10.    Begin VB.Image imgCell 
  11.       Height          =   375
  12.       Index           =   0
  13.       Left            =   390
  14.       Top             =   210
  15.       Visible         =   0   'False
  16.       Width           =   435
  17.    End
  18. Attribute VB_Name = "Grid"
  19. Attribute VB_GlobalNameSpace = False
  20. Attribute VB_Creatable = True
  21. Attribute VB_PredeclaredId = False
  22. Attribute VB_Exposed = False
  23. '********************************************************************
  24. 'Name:              Grid
  25. 'Created:           13-Jun-2000
  26. 'Description:       Short description of what it does
  27. 'Copyright:         Copyright 2000 Pieter van Vuuren. All Rights Reserved.
  28. 'Dependant On:
  29. 'Used By:
  30. 'Changes
  31. '--------------------------------------------------------------------
  32. 'Developer:         Pieter van Vuuren
  33. 'Date:              15-Jun-2000
  34. 'Description:       Description of changes made
  35. '--------------------------------------------------------------------
  36. '********************************************************************
  37. Option Explicit
  38. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  39. Public Event GridEvent(TileID As Long, GridEvents As GridEventsEnum)
  40. Public Event MouseDown(TileID As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  41. Public Event MouseUp(TileID As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  42. Public Event Resize()
  43. Public Event Click()
  44. Public Enum GridEventsEnum
  45.     geNew
  46.     geBombed
  47.     geFlagged
  48.     geQuestion
  49.     geUnQuestion
  50.     geExposed
  51.     geDone
  52. End Enum
  53. Private Enum BombCounters
  54.     BombCounter0 = 202
  55.     BombCounter1 = 301
  56.     BombCounter2 = 302
  57.     BombCounter3 = 303
  58.     BombCounter4 = 304
  59.     BombCounter5 = 305
  60.     BombCounter6 = 306
  61.     BombCounter7 = 307
  62.     BombCounter8 = 308
  63. End Enum
  64. Private Enum Tiles
  65.     Tile = 201
  66.     EmptyTile = 202
  67.     Bomb = 203
  68.     ExplodedBomb = 204
  69.     Flag = 205
  70.     FlagWrong = 206
  71.     Question = 207
  72.     QuestionDown = 208
  73. End Enum
  74. Private m_TwipsPerPixelX  As Long
  75. Private m_TwipsPerPixelY  As Long
  76. Private m_Height          As Long
  77. Private m_Width           As Long
  78. Private m_TilesFlagged    As Long
  79. Private m_TilesQuestioned As Long
  80. Private m_TilesExposed    As Long
  81. Private m_oGrid           As cGrid
  82. Private m_lShift          As Long
  83. Private m_fLeftButton     As Boolean
  84. 'Default Property Values:
  85. Const m_def_Bombs = 10
  86. Const m_def_Rows = 8
  87. Const m_def_Cols = 8
  88. 'Property Variables:
  89. Dim m_Bombs               As Long
  90. Dim m_Rows                As Long
  91. Dim m_Cols                As Long
  92. '*******************************************************************************
  93. ' TilesFlagged (PROPERTY GET)
  94. '*******************************************************************************
  95. Public Property Get TilesFlagged() As Long
  96.     TilesFlagged = m_TilesFlagged
  97. End Property
  98. '*******************************************************************************
  99. ' TilesQuestioned (PROPERTY GET)
  100. '*******************************************************************************
  101. Public Property Get TilesQuestioned() As Long
  102.     TilesQuestioned = m_TilesQuestioned
  103. End Property
  104. '*******************************************************************************
  105. ' TilesExposed (PROPERTY GET)
  106. '*******************************************************************************
  107. Public Property Get TilesExposed() As Long
  108.     TilesExposed = m_TilesExposed
  109. End Property
  110. '*******************************************************************************
  111. ' imgCell_Click (SUB)
  112. ' PARAMETERS:
  113. ' (In/Out) - Index - Integer -
  114. ' DESCRIPTION:
  115. ' ***Description goes here***
  116. '*******************************************************************************
  117. Private Sub imgCell_Click(Index As Integer)
  118.     RaiseEvent Click
  119. End Sub
  120. '*******************************************************************************
  121. ' imgCell_MouseDown (SUB)
  122. ' PARAMETERS:
  123. ' (In/Out) - Index  - Integer -
  124. ' (In/Out) - Button - Integer -
  125. ' (In/Out) - Shift  - Integer -
  126. ' (In/Out) - X      - Single  -
  127. ' (In/Out) - Y      - Single  -
  128. ' DESCRIPTION:
  129. ' ***Description goes here***
  130. '*******************************************************************************
  131. Private Sub imgCell_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  132. Dim oCell   As cCell
  133. Dim lIdx    As Integer
  134.     m_lShift = 0
  135.     'For simultanaeous click of both the L and R mouse buttons
  136.     If Shift = 0 _
  137.     And Button = vbLeftButton Then
  138.         m_fLeftButton = True
  139.     End If
  140.     If (Shift = vbShiftMask _
  141.     And Button = vbLeftButton) _
  142.     Or (m_fLeftButton _
  143.     And Button = vbRightButton) Then
  144.         With m_oGrid
  145.             If Not .Item(Index).Exposed Then
  146.                 m_lShift = 1
  147.             Else
  148.                 m_lShift = 2
  149.             End If
  150.             
  151.             'N
  152.             lIdx = .Item(Index).N
  153.             If lIdx <> 0 Then
  154.                 Set oCell = .Item(lIdx)
  155.                 If Not oCell.Exposed _
  156.                 And Not oCell.Questioned _
  157.                 And Not oCell.Flagged Then
  158.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  159.                 ElseIf oCell.Questioned Then
  160.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  161.                 End If
  162.                 Set oCell = Nothing
  163.             End If
  164.             
  165.             'NE
  166.             lIdx = .Item(Index).NE
  167.             If lIdx <> 0 Then
  168.                 Set oCell = .Item(lIdx)
  169.                 If Not oCell.Exposed _
  170.                 And Not oCell.Questioned _
  171.                 And Not oCell.Flagged Then
  172.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  173.                 ElseIf oCell.Questioned Then
  174.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  175.                 End If
  176.                 Set oCell = Nothing
  177.             End If
  178.             
  179.             'E
  180.             lIdx = .Item(Index).E
  181.             If lIdx <> 0 Then
  182.                 Set oCell = .Item(lIdx)
  183.                 If Not oCell.Exposed _
  184.                 And Not oCell.Questioned _
  185.                 And Not oCell.Flagged Then
  186.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  187.                 ElseIf oCell.Questioned Then
  188.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  189.                 End If
  190.                 Set oCell = Nothing
  191.             End If
  192.             
  193.             'SE
  194.             lIdx = .Item(Index).SE
  195.             If lIdx <> 0 Then
  196.                 Set oCell = .Item(lIdx)
  197.                 If Not oCell.Exposed _
  198.                 And Not oCell.Questioned _
  199.                 And Not oCell.Flagged Then
  200.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  201.                 ElseIf oCell.Questioned Then
  202.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  203.                 End If
  204.                 Set oCell = Nothing
  205.             End If
  206.             
  207.             'S
  208.             lIdx = .Item(Index).S
  209.             If lIdx <> 0 Then
  210.                 Set oCell = .Item(lIdx)
  211.                 If Not oCell.Exposed _
  212.                 And Not oCell.Questioned _
  213.                 And Not oCell.Flagged Then
  214.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  215.                 ElseIf oCell.Questioned Then
  216.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  217.                 End If
  218.                 Set oCell = Nothing
  219.             End If
  220.             
  221.             'SW
  222.             lIdx = .Item(Index).SW
  223.             If lIdx <> 0 Then
  224.                 Set oCell = .Item(lIdx)
  225.                 If Not oCell.Exposed _
  226.                 And Not oCell.Questioned _
  227.                 And Not oCell.Flagged Then
  228.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  229.                 ElseIf oCell.Questioned Then
  230.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  231.                 End If
  232.                 Set oCell = Nothing
  233.             End If
  234.             
  235.             'W
  236.             lIdx = .Item(Index).W
  237.             If lIdx <> 0 Then
  238.                 Set oCell = .Item(lIdx)
  239.                 If Not oCell.Exposed _
  240.                 And Not oCell.Questioned _
  241.                 And Not oCell.Flagged Then
  242.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  243.                 ElseIf oCell.Questioned Then
  244.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  245.                 End If
  246.                 Set oCell = Nothing
  247.             End If
  248.             
  249.             'NW
  250.             lIdx = .Item(Index).NW
  251.             If lIdx <> 0 Then
  252.                 Set oCell = .Item(lIdx)
  253.                 If Not oCell.Exposed _
  254.                 And Not oCell.Questioned _
  255.                 And Not oCell.Flagged Then
  256.                     imgCell(lIdx).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  257.                 ElseIf oCell.Questioned Then
  258.                     imgCell(lIdx).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  259.                 End If
  260.                 Set oCell = Nothing
  261.             End If
  262.         
  263.             If Not .Item(Index).Exposed _
  264.             And Not .Item(Index).Flagged Then
  265.                 If Not .Item(Index).Questioned Then
  266.                     imgCell(Index).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  267.                 Else 'If .Item(Index).Questioned Then
  268.                     imgCell(Index).Picture = LoadResPicture(QuestionDown, vbResBitmap)
  269.                 End If
  270.             End If
  271.         End With
  272.     Else
  273.         If Not m_oGrid.Item(Index).Exposed _
  274.         And Not m_oGrid.Item(Index).Flagged _
  275.         And Button = vbLeftButton Then
  276.             imgCell(Index).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  277.         End If
  278.     End If
  279.     RaiseEvent MouseDown(CLng(Index), Button, Shift, X, Y)
  280. End Sub
  281. '*******************************************************************************
  282. ' CheckButtons (SUB)
  283. ' PARAMETERS:
  284. ' (In/Out) - Index - Integer -
  285. ' DESCRIPTION:
  286. ' ***Description goes here***
  287. '*******************************************************************************
  288. Private Sub CheckButtons(Index As Integer)
  289.     CheckButtons2 m_oGrid.Item(Index).N
  290.     CheckButtons2 m_oGrid.Item(Index).NE
  291.     CheckButtons2 m_oGrid.Item(Index).E
  292.     CheckButtons2 m_oGrid.Item(Index).SE
  293.     CheckButtons2 m_oGrid.Item(Index).S
  294.     CheckButtons2 m_oGrid.Item(Index).SW
  295.     CheckButtons2 m_oGrid.Item(Index).W
  296.     CheckButtons2 m_oGrid.Item(Index).NW
  297. End Sub
  298. '*******************************************************************************
  299. ' CheckButtons2 (SUB)
  300. ' PARAMETERS:
  301. ' (In/Out) - iID - Integer -
  302. ' DESCRIPTION:
  303. ' Recursive routine to clear grid cells after an empty cell was clicked
  304. '*******************************************************************************
  305. Private Sub CheckButtons2(iID As Integer)
  306.     If iID > 0 Then
  307.         If Not m_oGrid.Item(iID).Bomb _
  308.         And Not m_oGrid.Item(iID).Exposed Then
  309.             imgCell_MouseUp iID, vbLeftButton, 0, 0, 0
  310.         End If
  311.     End If
  312. End Sub
  313. '*******************************************************************************
  314. ' imgCell_MouseUp (SUB)
  315. ' PARAMETERS:
  316. ' (In/Out) - Index  - Integer -
  317. ' (In/Out) - Button - Integer -
  318. ' (In/Out) - Shift  - Integer -
  319. ' (In/Out) - X      - Single  -
  320. ' (In/Out) - Y      - Single  -
  321. ' DESCRIPTION:
  322. ' ***Description goes here***
  323. '*******************************************************************************
  324. Private Sub imgCell_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  325. Dim lBC     As Long
  326. Dim oCell   As cCell
  327. Dim lIdx    As Integer
  328.     If m_lShift <> 0 Then
  329.         With m_oGrid
  330.             'N
  331.             lIdx = .Item(Index).N
  332.             If lIdx <> 0 Then
  333.                 Set oCell = .Item(lIdx)
  334.                 With oCell
  335.                     If Not .Exposed _
  336.                     And Not .Questioned _
  337.                     And Not .Flagged Then
  338.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  339.                     ElseIf .Questioned Then
  340.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  341.                     End If
  342.                 End With
  343.                 Set oCell = Nothing
  344.             End If
  345.             
  346.             'NE
  347.             lIdx = .Item(Index).NE
  348.             If lIdx <> 0 Then
  349.                 Set oCell = .Item(lIdx)
  350.                 With oCell
  351.                     If Not .Exposed _
  352.                     And Not .Questioned _
  353.                     And Not .Flagged Then
  354.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  355.                     ElseIf .Questioned Then
  356.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  357.                     End If
  358.                 End With
  359.                 Set oCell = Nothing
  360.             End If
  361.             
  362.             'E
  363.             lIdx = .Item(Index).E
  364.             If lIdx <> 0 Then
  365.                 Set oCell = .Item(lIdx)
  366.                 With oCell
  367.                     If Not .Exposed _
  368.                     And Not .Questioned _
  369.                     And Not .Flagged Then
  370.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  371.                     ElseIf .Questioned Then
  372.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  373.                     End If
  374.                 End With
  375.                 Set oCell = Nothing
  376.             End If
  377.             
  378.             'SE
  379.             lIdx = .Item(Index).SE
  380.             If lIdx <> 0 Then
  381.                 Set oCell = .Item(lIdx)
  382.                 With oCell
  383.                     If Not .Exposed _
  384.                     And Not .Questioned _
  385.                     And Not .Flagged Then
  386.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  387.                     ElseIf .Questioned Then
  388.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  389.                     End If
  390.                 End With
  391.                 Set oCell = Nothing
  392.             End If
  393.             
  394.             'S
  395.             lIdx = .Item(Index).S
  396.             If lIdx <> 0 Then
  397.                 Set oCell = .Item(lIdx)
  398.                 With oCell
  399.                     If Not .Exposed _
  400.                     And Not .Questioned _
  401.                     And Not .Flagged Then
  402.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  403.                     ElseIf .Questioned Then
  404.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  405.                     End If
  406.                 End With
  407.                 Set oCell = Nothing
  408.             End If
  409.             
  410.             'SW
  411.             lIdx = .Item(Index).SW
  412.             If lIdx <> 0 Then
  413.                 Set oCell = .Item(lIdx)
  414.                 With oCell
  415.                     If Not .Exposed _
  416.                     And Not .Questioned _
  417.                     And Not .Flagged Then
  418.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  419.                     ElseIf .Questioned Then
  420.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  421.                     End If
  422.                 End With
  423.                 Set oCell = Nothing
  424.             End If
  425.             
  426.             'W
  427.             lIdx = .Item(Index).W
  428.             If lIdx <> 0 Then
  429.                 Set oCell = .Item(lIdx)
  430.                 With oCell
  431.                     If Not .Exposed _
  432.                     And Not .Questioned _
  433.                     And Not .Flagged Then
  434.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  435.                     ElseIf .Questioned Then
  436.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  437.                     End If
  438.                 End With
  439.                 Set oCell = Nothing
  440.             End If
  441.             
  442.             'NW
  443.             lIdx = .Item(Index).NW
  444.             If lIdx <> 0 Then
  445.                 Set oCell = .Item(lIdx)
  446.                 With oCell
  447.                     If Not .Exposed _
  448.                     And Not .Questioned _
  449.                     And Not .Flagged Then
  450.                         imgCell(lIdx).Picture = LoadResPicture(Tile, vbResBitmap)
  451.                     ElseIf .Questioned Then
  452.                         imgCell(lIdx).Picture = LoadResPicture(Question, vbResBitmap)
  453.                     End If
  454.                 End With
  455.                 Set oCell = Nothing
  456.             End If
  457.             
  458.             If m_lShift = 1 Then
  459.                 imgCell(Index).Picture = LoadResPicture(Tile, vbResBitmap)
  460.             ElseIf m_lShift = 2 Then
  461.             
  462.             End If
  463.         End With
  464.     End If
  465. Dim lFlagged As Long
  466.     If Not (m_oGrid.Item(Index).Exposed) Or (m_lShift <> 1) Then
  467.         If m_lShift = 2 Then
  468.             'Check if there is any flagged tiles
  469.             lFlagged = 0
  470.             With m_oGrid
  471.                 'N
  472.                 lIdx = .Item(Index).N
  473.                 If lIdx <> 0 Then
  474.                     If .Item(lIdx).Flagged Then
  475.                         lFlagged = lFlagged + 1
  476.                     End If
  477.                 End If
  478.                 
  479.                 'NE
  480.                 lIdx = .Item(Index).NE
  481.                 If lIdx <> 0 Then
  482.                     If .Item(lIdx).Flagged Then
  483.                         lFlagged = lFlagged + 1
  484.                     End If
  485.                 End If
  486.                 
  487.                 'E
  488.                 lIdx = .Item(Index).E
  489.                 If lIdx <> 0 Then
  490.                     If .Item(lIdx).Flagged Then
  491.                         lFlagged = lFlagged + 1
  492.                     End If
  493.                 End If
  494.                 
  495.                 'SE
  496.                 lIdx = .Item(Index).SE
  497.                 If lIdx <> 0 Then
  498.                     If .Item(lIdx).Flagged Then
  499.                         lFlagged = lFlagged + 1
  500.                     End If
  501.                 End If
  502.                 
  503.                 'S
  504.                 lIdx = .Item(Index).S
  505.                 If lIdx <> 0 Then
  506.                     If .Item(lIdx).Flagged Then
  507.                         lFlagged = lFlagged + 1
  508.                     End If
  509.                 End If
  510.                 
  511.                 'SW
  512.                 lIdx = .Item(Index).SW
  513.                 If lIdx <> 0 Then
  514.                     If .Item(lIdx).Flagged Then
  515.                         lFlagged = lFlagged + 1
  516.                     End If
  517.                 End If
  518.                 
  519.                 'W
  520.                 lIdx = .Item(Index).W
  521.                 If lIdx <> 0 Then
  522.                     If .Item(lIdx).Flagged Then
  523.                         lFlagged = lFlagged + 1
  524.                     End If
  525.                 End If
  526.                 
  527.                 'NW
  528.                 lIdx = .Item(Index).NW
  529.                 If lIdx <> 0 Then
  530.                     If .Item(lIdx).Flagged Then
  531.                         lFlagged = lFlagged + 1
  532.                     End If
  533.                 End If
  534.                 
  535.                 'If the BombCount = Nr of tiles flagged
  536.                 'Then click on all the other tiles
  537.                 If .BombCount(Index) = lFlagged Then
  538.                     m_lShift = 0
  539.                     With .Item(Index)
  540.                         If .N <> 0 Then imgCell_MouseUp .N, vbLeftButton, 0, 0, 0
  541.                         If .NE <> 0 Then imgCell_MouseUp .NE, vbLeftButton, 0, 0, 0
  542.                         If .E <> 0 Then imgCell_MouseUp .E, vbLeftButton, 0, 0, 0
  543.                         If .SE <> 0 Then imgCell_MouseUp .SE, vbLeftButton, 0, 0, 0
  544.                         If .S <> 0 Then imgCell_MouseUp .S, vbLeftButton, 0, 0, 0
  545.                         If .SW <> 0 Then imgCell_MouseUp .SW, vbLeftButton, 0, 0, 0
  546.                         If .W <> 0 Then imgCell_MouseUp .W, vbLeftButton, 0, 0, 0
  547.                         If .NW <> 0 Then imgCell_MouseUp .NW, vbLeftButton, 0, 0, 0
  548.                     End With
  549.                 End If
  550.             End With
  551.         ElseIf Not (m_fLeftButton _
  552.         And Button = vbRightButton) Then
  553.             Select Case Button
  554.             Case vbLeftButton
  555.                 If Not m_oGrid.Item(Index).Flagged Then
  556.                     m_oGrid.Item(Index).Exposed = True
  557.                     If m_oGrid.Item(Index).Bomb Then
  558.                         imgCell(Index).Picture = LoadResPicture(ExplodedBomb, vbResBitmap)
  559.                         FinishGrid
  560.                         RaiseEvent GridEvent(CLng(Index), geBombed)
  561.                     Else
  562.                         Select Case m_oGrid.BombCount(Index)
  563.                         Case 0
  564.                             lBC = BombCounter0
  565.                         Case 1
  566.                             lBC = BombCounter1
  567.                         Case 2
  568.                             lBC = BombCounter2
  569.                         Case 3
  570.                             lBC = BombCounter3
  571.                         Case 4
  572.                             lBC = BombCounter4
  573.                         Case 5
  574.                             lBC = BombCounter5
  575.                         Case 6
  576.                             lBC = BombCounter6
  577.                         Case 7
  578.                             lBC = BombCounter7
  579.                         Case 8
  580.                             lBC = BombCounter8
  581.                         End Select
  582.                         imgCell(Index).Picture = LoadResPicture(lBC, vbResBitmap)
  583.                         If lBC = BombCounter0 Then
  584.                             CheckButtons Index
  585.                         End If
  586.                         CheckIfWon
  587.                     End If
  588.                 End If
  589.             Case vbRightButton
  590.                 If Not m_oGrid.Item(Index).Exposed Then
  591.                     If m_oGrid.Item(Index).Questioned Then
  592.                         m_TilesQuestioned = m_TilesQuestioned - 1
  593.                         m_oGrid.Item(Index).Questioned = False
  594.                         imgCell(Index).Picture = LoadResPicture(Tile, vbResBitmap)
  595.                         RaiseEvent GridEvent(CLng(Index), geUnQuestion)
  596.                     ElseIf m_oGrid.Item(Index).Flagged Then
  597.                         m_TilesFlagged = m_TilesFlagged - 1
  598.                         m_oGrid.Item(Index).Flagged = False
  599.                         m_TilesQuestioned = m_TilesQuestioned + 1
  600.                         m_oGrid.Item(Index).Questioned = True
  601.                         imgCell(Index).Picture = LoadResPicture(Question, vbResBitmap)
  602.                         RaiseEvent GridEvent(CLng(Index), geQuestion)
  603.                     Else
  604.                         m_TilesFlagged = m_TilesFlagged + 1
  605.                         m_oGrid.Item(Index).Flagged = True
  606.                         imgCell(Index).Picture = LoadResPicture(Flag, vbResBitmap)
  607.                         RaiseEvent GridEvent(CLng(Index), geFlagged)
  608.                     End If
  609.                 End If
  610.             End Select
  611.         End If
  612.     End If
  613.     RaiseEvent MouseUp(CLng(Index), Button, Shift, X, Y)
  614.     m_lShift = 0
  615.     'For simultanaeous click of both the L and R mouse buttons
  616.     If Shift = 0 _
  617.     And Button = vbLeftButton Then
  618.         m_fLeftButton = False
  619.     End If
  620. End Sub
  621. '*******************************************************************************
  622. ' UserControl_Initialize (SUB)
  623. ' PARAMETERS:
  624. ' None
  625. ' DESCRIPTION:
  626. ' ***Description goes here***
  627. '*******************************************************************************
  628. Private Sub UserControl_Initialize()
  629.     m_TwipsPerPixelY = Screen.TwipsPerPixelY
  630.     m_TwipsPerPixelX = Screen.TwipsPerPixelX
  631.     Set m_oGrid = New cGrid
  632.     imgCell(0).Move -17 * m_TwipsPerPixelX, -17 * m_TwipsPerPixelY, 16 * m_TwipsPerPixelX, 16 * m_TwipsPerPixelY
  633. End Sub
  634. '*******************************************************************************
  635. ' UserControl_Paint (SUB)
  636. ' PARAMETERS:
  637. ' None
  638. ' DESCRIPTION:
  639. ' ***Description goes here***
  640. '*******************************************************************************
  641. Private Sub UserControl_Paint()
  642.     m_TwipsPerPixelY = Screen.TwipsPerPixelY
  643.     m_TwipsPerPixelX = Screen.TwipsPerPixelX
  644.     UserControl.Cls
  645.     UserControl.Line (0, 0)-(UserControl.Width, 0), QBColor(8)
  646.     UserControl.Line (0, m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX, m_TwipsPerPixelY), QBColor(8)
  647.     UserControl.Line (0, m_TwipsPerPixelY + m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX - m_TwipsPerPixelX, m_TwipsPerPixelY + m_TwipsPerPixelY), QBColor(8)
  648.     UserControl.Line (0, 0)-(0, UserControl.Height), QBColor(8)
  649.     UserControl.Line (m_TwipsPerPixelX, 0)-(m_TwipsPerPixelX, UserControl.Height - m_TwipsPerPixelY), QBColor(8)
  650.     UserControl.Line (m_TwipsPerPixelX + m_TwipsPerPixelX, 0)-(m_TwipsPerPixelX + m_TwipsPerPixelX, UserControl.Height - m_TwipsPerPixelY - m_TwipsPerPixelY), QBColor(8)
  651.     UserControl.Line (m_TwipsPerPixelX, UserControl.Height - m_TwipsPerPixelY)-(UserControl.Width, UserControl.Height - m_TwipsPerPixelY), RGB(255, 255, 255)
  652.     UserControl.Line (m_TwipsPerPixelX + m_TwipsPerPixelX, UserControl.Height - (m_TwipsPerPixelY + m_TwipsPerPixelY))-(UserControl.Width, UserControl.Height - (m_TwipsPerPixelY + m_TwipsPerPixelY)), RGB(255, 255, 255)
  653.     UserControl.Line (m_TwipsPerPixelX + m_TwipsPerPixelX + m_TwipsPerPixelX, UserControl.Height - m_TwipsPerPixelY - m_TwipsPerPixelY - m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX, UserControl.Height - (m_TwipsPerPixelY + m_TwipsPerPixelY + m_TwipsPerPixelY)), RGB(255, 255, 255)
  654.     UserControl.Line (UserControl.Width - m_TwipsPerPixelX, m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX, UserControl.Height), RGB(255, 255, 255)
  655.     UserControl.Line (UserControl.Width - m_TwipsPerPixelX - m_TwipsPerPixelX, m_TwipsPerPixelY + m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX - m_TwipsPerPixelX, UserControl.Height), RGB(255, 255, 255)
  656.     UserControl.Line (UserControl.Width - m_TwipsPerPixelX - m_TwipsPerPixelX - m_TwipsPerPixelX, m_TwipsPerPixelY + m_TwipsPerPixelY + m_TwipsPerPixelY)-(UserControl.Width - m_TwipsPerPixelX - m_TwipsPerPixelX - m_TwipsPerPixelX, UserControl.Height), RGB(255, 255, 255)
  657. End Sub
  658. '*******************************************************************************
  659. ' Rows (PROPERTY GET)
  660. '*******************************************************************************
  661. Public Property Get Rows() As Long
  662.     Rows = m_Rows
  663. End Property
  664. '*******************************************************************************
  665. ' Rows (PROPERTY LET)
  666. '*******************************************************************************
  667. Public Property Let Rows(ByVal New_Rows As Long)
  668. Attribute Rows.VB_Description = "Number of Rows"
  669.     If New_Rows < 8 Then
  670.         New_Rows = 8
  671.     End If
  672.     m_Rows = New_Rows
  673.     m_Height = (m_Rows * imgCell(0).Height) + (6 * m_TwipsPerPixelY)
  674.     UserControl.Height = m_Height
  675.     PropertyChanged "Rows"
  676. End Property
  677. '*******************************************************************************
  678. ' Cols (PROPERTY GET)
  679. '*******************************************************************************
  680. Public Property Get Cols() As Long
  681. Attribute Cols.VB_Description = "Number of Columns"
  682.     Cols = m_Cols
  683. End Property
  684. '*******************************************************************************
  685. ' Cols (PROPERTY LET)
  686. '*******************************************************************************
  687. Public Property Let Cols(ByVal New_Cols As Long)
  688.     If New_Cols < 8 Then
  689.         New_Cols = 8
  690.     End If
  691.     m_Cols = New_Cols
  692.     m_Width = (m_Cols * imgCell(0).Width) + (6 * m_TwipsPerPixelX)
  693.     UserControl.Width = m_Width
  694.     PropertyChanged "Cols"
  695. End Property
  696. '*******************************************************************************
  697. ' UserControl_InitProperties (SUB)
  698. ' PARAMETERS:
  699. ' None
  700. ' DESCRIPTION:
  701. ' ***Description goes here***
  702. '*******************************************************************************
  703. Private Sub UserControl_InitProperties()
  704.     'Initialize Properties for User Control
  705.     m_TwipsPerPixelY = Screen.TwipsPerPixelY
  706.     m_TwipsPerPixelX = Screen.TwipsPerPixelX
  707.     Rows = m_def_Rows
  708.     Cols = m_def_Cols
  709.     Bombs = m_def_Bombs
  710.     DrawGrid
  711. End Sub
  712. '*******************************************************************************
  713. ' UserControl_ReadProperties (SUB)
  714. ' PARAMETERS:
  715. ' (In/Out) - PropBag - PropertyBag -
  716. ' DESCRIPTION:
  717. ' Load property values from storage
  718. '*******************************************************************************
  719. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  720.     Rows = PropBag.ReadProperty("Rows", m_def_Rows)
  721.     Cols = PropBag.ReadProperty("Cols", m_def_Cols)
  722.     Bombs = PropBag.ReadProperty("Bombs", m_def_Bombs)
  723.     DrawGrid
  724.     UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
  725. End Sub
  726. '*******************************************************************************
  727. ' UserControl_Resize (SUB)
  728. ' PARAMETERS:
  729. ' None
  730. ' DESCRIPTION:
  731. ' ***Description goes here***
  732. '*******************************************************************************
  733. Private Sub UserControl_Resize()
  734.     If UserControl.Width <> m_Width Then
  735.         UserControl.Width = m_Width
  736.     End If
  737.     If UserControl.Height <> m_Height Then
  738.         UserControl.Height = m_Height
  739.     End If
  740. End Sub
  741. '*******************************************************************************
  742. ' UserControl_Terminate (SUB)
  743. ' PARAMETERS:
  744. ' None
  745. ' DESCRIPTION:
  746. ' ***Description goes here***
  747. '*******************************************************************************
  748. Private Sub UserControl_Terminate()
  749.     Set m_oGrid = Nothing
  750. End Sub
  751. '*******************************************************************************
  752. ' UserControl_WriteProperties (SUB)
  753. ' PARAMETERS:
  754. ' (In/Out) - PropBag - PropertyBag -
  755. ' DESCRIPTION:
  756. ' Write property values to storage
  757. '*******************************************************************************
  758. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  759.     Call PropBag.WriteProperty("Rows", m_Rows, m_def_Rows)
  760.     Call PropBag.WriteProperty("Cols", m_Cols, m_def_Cols)
  761.     Call PropBag.WriteProperty("Bombs", m_Bombs, m_def_Bombs)
  762.     Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
  763. End Sub
  764. '*******************************************************************************
  765. ' Bombs (PROPERTY GET)
  766. '*******************************************************************************
  767. Public Property Get Bombs() As Long
  768.     Bombs = m_Bombs
  769. End Property
  770. '*******************************************************************************
  771. ' Bombs (PROPERTY LET)
  772. '*******************************************************************************
  773. Public Property Let Bombs(ByVal New_Bombs As Long)
  774. Attribute Bombs.VB_Description = "The number of Mines"
  775.     m_Bombs = New_Bombs
  776.     PropertyChanged "Bombs"
  777. End Property
  778. '*******************************************************************************
  779. ' DrawGrid (SUB)
  780. ' PARAMETERS:
  781. ' None
  782. ' DESCRIPTION:
  783. ' Draw the grid
  784. '*******************************************************************************
  785. Public Sub DrawGrid()
  786. Dim cell    As cCell
  787. Dim iID     As Integer
  788. Dim iCol    As Integer
  789. Dim iRow    As Integer
  790. Dim iWidth  As Integer
  791. Dim iHeight As Integer
  792. Dim ID      As Long
  793.     Screen.MousePointer = vbHourglass
  794.     m_TilesFlagged = 0
  795.     m_TilesQuestioned = 0
  796.     m_TilesExposed = 0
  797.     m_oGrid.Initialize m_Rows, m_Cols, m_Bombs
  798.     iWidth = imgCell(0).Width
  799.     iHeight = imgCell(0).Height
  800.     For ID = 1 To imgCell.UBound
  801.         Unload imgCell(ID)
  802.     Next 'ID
  803.         
  804.     For Each cell In m_oGrid
  805.         iID = cell.ID
  806.         iCol = cell.Col
  807.         iRow = cell.Row
  808.         
  809.         Load imgCell(iID)
  810.         With imgCell(iID)
  811.             .Move (iCol - 1) * (iWidth) + (3 * m_TwipsPerPixelX), (iRow - 1) * (iHeight) + (3 * m_TwipsPerPixelY), iWidth, iHeight
  812.             .Picture = LoadResPicture(Tile, vbResBitmap)
  813.             .Visible = True
  814.         End With 'imgCell(iID)
  815.     Next 'cell
  816.     Enabled = True
  817.     RaiseEvent Resize
  818.     RaiseEvent GridEvent(0, geNew)
  819.     Screen.MousePointer = vbDefault
  820. End Sub
  821. '*******************************************************************************
  822. ' FinishGrid (SUB)
  823. ' PARAMETERS:
  824. ' (In/Out) - ShowAll - Boolean -
  825. ' DESCRIPTION:
  826. ' After a bomb was clicked show where all the bombs are
  827. '*******************************************************************************
  828. Private Sub FinishGrid(Optional ShowAll As Boolean = False)
  829. Dim oCell As cCell
  830.     Screen.MousePointer = vbHourglass
  831.     For Each oCell In m_oGrid
  832.         With oCell
  833.             If Not .Exposed Then
  834.                 If .Bomb Then
  835.                     If Not .Flagged Then
  836.                         imgCell(.ID).Picture = LoadResPicture(Bomb, vbResBitmap)
  837.                     End If
  838.                 Else
  839.                     If .Flagged Then
  840.                         imgCell(.ID).Picture = LoadResPicture(FlagWrong, vbResBitmap)
  841.                     End If
  842.                     .Flagged = False
  843.                     If ShowAll Then
  844.                         imgCell_MouseDown .ID, vbLeftButton, 0, 0, 0
  845.                     End If
  846.                 End If
  847.             End If
  848.         End With 'oCell
  849.     Next 'oCell
  850.     Enabled = False
  851.     Screen.MousePointer = vbDefault
  852. End Sub
  853. '*******************************************************************************
  854. ' CheckIfWon (SUB)
  855. ' PARAMETERS:
  856. ' None
  857. ' DESCRIPTION:
  858. ' ***Description goes here***
  859. '*******************************************************************************
  860. Private Sub CheckIfWon()
  861. Dim oCell       As cCell
  862. Dim fWon        As Boolean
  863.     fWon = True
  864.     For Each oCell In m_oGrid
  865.         With oCell
  866.             If (Not .Exposed _
  867.             And Not .Bomb) _
  868.             Or (.Flagged _
  869.             And Not .Bomb) Then
  870.                 fWon = False
  871.                 Exit For
  872.             End If
  873.         End With 'oCell
  874.     Next 'oCell
  875.     If fWon Then
  876.         Enabled = False
  877.         RaiseEvent GridEvent(0, geDone)
  878.     End If
  879. End Sub
  880. '*******************************************************************************
  881. ' Enabled (PROPERTY GET)
  882. '*******************************************************************************
  883. Public Property Get Enabled() As Boolean
  884.     Enabled = UserControl.Enabled
  885. End Property
  886. '*******************************************************************************
  887. ' Enabled (PROPERTY LET)
  888. '*******************************************************************************
  889. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  890. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  891.     UserControl.Enabled() = New_Enabled
  892.     PropertyChanged "Enabled"
  893. End Property
  894. '*******************************************************************************
  895. ' Hint (SUB)
  896. ' PARAMETERS:
  897. ' (In/Out) - DoHint - Boolean - If True will perform the mouseup event
  898. ' DESCRIPTION:
  899. ' ***Description goes here***
  900. '*******************************************************************************
  901. Public Sub Hint(Optional DoHint As Boolean = False)
  902. Dim oCell  As cCell
  903. Dim fFound As Boolean
  904.     Screen.MousePointer = vbHourglass
  905.     For Each oCell In m_oGrid
  906.         With oCell
  907.             If Not .Exposed Then
  908.                 If Not .Bomb Then
  909.                     If Not .Flagged Then
  910.                         If m_oGrid.BombCount(.ID) = 0 Then
  911.                             If DoHint Then
  912.                                 imgCell_MouseUp .ID, vbLeftButton, 0, 0, 0
  913.                             Else
  914.                                 imgCell(.ID).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  915.                                 DoEvents
  916.                                 Sleep 200
  917.                                 imgCell(.ID).Picture = LoadResPicture(Tile, vbResBitmap)
  918.                             End If
  919.                             fFound = True
  920.                             Exit For
  921.                         End If
  922.                     End If
  923.                 End If
  924.             End If
  925.         End With 'oCell
  926.     Next 'oCell
  927.     If Not fFound Then
  928.         fFound = False
  929.         For Each oCell In m_oGrid
  930.             With oCell
  931.                 If Not .Exposed Then
  932.                     If Not .Bomb Then
  933.                         If Not .Flagged Then
  934.                             If DoHint Then
  935.                                 imgCell_MouseUp .ID, vbLeftButton, 0, 0, 0
  936.                             Else
  937.                                 imgCell(.ID).Picture = LoadResPicture(EmptyTile, vbResBitmap)
  938.                                 DoEvents
  939.                                 Sleep 200
  940.                                 imgCell(.ID).Picture = LoadResPicture(Tile, vbResBitmap)
  941.                             End If
  942.                             fFound = True
  943.                             Exit For
  944.                         End If
  945.                     End If
  946.                 End If
  947.             End With 'oCell
  948.         Next 'oCell
  949.     End If
  950.     Screen.MousePointer = vbDefault
  951. End Sub
  952.