\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > MineSweeper Recursion


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
Okay so im building a minesweeper game in Vb6. The main coding is pretty
\r\nstraightforward however im having trouble making the code behind the zeros buttons (the minespots that have no mines adjacent). I am using two main sub procedures that are recursing off of each other with functions just checking where the minespot is located. I am using a control array and a boolean array. It is a 10*20 grid
\r\ncode of trouble spot is as follows
\r\n
\r\n
\r\n
Code:
\r\n
Private Sub Determine(ByVal index As Integer)\r\n\'declare local variables\r\nDim intCount As Integer\r\n\r\n\'checks if mine swept is on a corner, side or in interior\r\nIf index = 0 Or index = 19 Or index = 180 Or index = 199 Then\r\n    intCount = CornerMine(index)\r\nElseIf isSideMine(index) = "right side" Then \'checks if its on side but not corner\r\n    intCount = RightMine(index)\r\nElseIf isSideMine(index) = "left side" Then\r\n    intCount = LeftMine(index)\r\nElseIf isTopBottom(index) = "top" Then \'sends to appropriate function if on top of mine section\r\n    intCount = TopMine(index)\r\nElseIf isTopBottom(index) = "bottom" Then \' sends to appropriate function if on top of mine section\r\n    intCount = BottomMine(index)\r\nElse\r\n    intCount = Interior(index) \'then button clicked is indeed in the interior\r\nEnd If\r\n    \r\n   \'if zero\r\nIf intCount = 0 Then\r\n    \'complex looping structure with the determine sub procedure that allows indexs adjacent to the zero to be id\'d.\r\n\'disable zero\r\ncmdSpot(index).Enabled = False\r\ncmdSpot(index).Caption = "0"\r\n\'disable or display captions of minespots adjacent to zero\r\nIf index = 0 Then\r\n    Call Determine(index + 1)\r\n    Call Determine(index + 21)\r\n    Call Determine(index + 20)\r\nElseIf index = 19 Then\r\n    Call Determine(index + 20)\r\n    Call Determine(index + 19)\r\n    Call Determine(index - 1)\r\nElseIf index = 180 Then\r\n    Call Determine(index + 1)\r\n    Call Determine(index - 20)\r\n    Call Determine(index - 19)\r\nElseIf index = 199 Then\r\n    Call Determine(index - 1)\r\n    Call Determine(index - 20)\r\n    Call Determine(index - 21)\r\nElseIf isTopBottom(index) = "top" Then\r\n    Call Determine(index + 19)\r\n    Call Determine(index + 20)\r\n    Call Determine(index + 21)\r\n    Call Determine(index + 1)\r\n    Call Determine(index - 1)\r\nElseIf isTopBottom(index) = "bottom" Then\r\n    Call Determine(index - 19)\r\n    Call Determine(index - 20)\r\n    Call Determine(index - 21)\r\n    Call Determine(index - 1)\r\n    Call Determine(index + 1)\r\nElseIf isSideMine(index) = "right side" Then \'check if on far left or far right row\r\n    Call Determine(index - 20)\r\n    Call Determine(inex - 21)\r\n    Call Determine(index - 1)\r\n    Call Determine(index + 19)\r\n    Call Determine(index + 20)\r\nElseIf isSideMine(index) = "left side" Then\r\n    Call Determine(index - 20)\r\n    Call Determine(index - 19)\r\n    Call Determine(index + 1)\r\n    Call Determine(index + 20)\r\n    Call Determine(index + 21)\r\nElse \'means it is interior spot\r\n    Call Determine(index + 19)\r\n    Call Determine(index + 20)\r\n    Call Determine(index + 21)\r\n    Call Determine(index + 1)\r\n    Call Determine(index - 1)\r\n    Call Determine(index - 19)\r\n    Call Determine(index - 20)\r\n    Call Determine(index - 21)\r\nEnd If\r\nElse\r\n    \'determine what caption to display\r\n    cmdSpot(index).Caption = intCount\r\nEnd If\r\n\r\n   \r\n\r\nEnd Sub
\r\n
the functions not displayed are pretty self explanatory i think. this is the problem ive been getting. I might be doing this all wrong as i taught myself recursion, so any thoughts or debugging tips are appreciated.
\r\n \r\n\r\n
\r\n \r\n \r\n
\r\n\r\n \r\n\r\n \r\n\r\n \r\n
\r\n Attached Images\r\n \r\n \r\n \r\n \r\n\r\n
File Type: pngminesweeper.png (75.6 KB, 13 views)
\r\n
\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[1389123] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 12-18-2011, 04:35 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n surfR2911\r\n surfR2911 is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 12-18-2011, 04:02 PM
Minesweeperhelp Minesweeperhelp is offline
Newcomer
 
Join Date: Dec 2011
Posts: 3
Default MineSweeper Recursion


Okay so im building a minesweeper game in Vb6. The main coding is pretty
straightforward however im having trouble making the code behind the zeros buttons (the minespots that have no mines adjacent). I am using two main sub procedures that are recursing off of each other with functions just checking where the minespot is located. I am using a control array and a boolean array. It is a 10*20 grid
code of trouble spot is as follows

Code:
Private Sub Determine(ByVal index As Integer)
'declare local variables
Dim intCount As Integer

'checks if mine swept is on a corner, side or in interior
If index = 0 Or index = 19 Or index = 180 Or index = 199 Then
    intCount = CornerMine(index)
ElseIf isSideMine(index) = "right side" Then 'checks if its on side but not corner
    intCount = RightMine(index)
ElseIf isSideMine(index) = "left side" Then
    intCount = LeftMine(index)
ElseIf isTopBottom(index) = "top" Then 'sends to appropriate function if on top of mine section
    intCount = TopMine(index)
ElseIf isTopBottom(index) = "bottom" Then ' sends to appropriate function if on top of mine section
    intCount = BottomMine(index)
Else
    intCount = Interior(index) 'then button clicked is indeed in the interior
End If
    
   'if zero
If intCount = 0 Then
    'complex looping structure with the determine sub procedure that allows indexs adjacent to the zero to be id'd.
'disable zero
cmdSpot(index).Enabled = False
cmdSpot(index).Caption = "0"
'disable or display captions of minespots adjacent to zero
If index = 0 Then
    Call Determine(index + 1)
    Call Determine(index + 21)
    Call Determine(index + 20)
ElseIf index = 19 Then
    Call Determine(index + 20)
    Call Determine(index + 19)
    Call Determine(index - 1)
ElseIf index = 180 Then
    Call Determine(index + 1)
    Call Determine(index - 20)
    Call Determine(index - 19)
ElseIf index = 199 Then
    Call Determine(index - 1)
    Call Determine(index - 20)
    Call Determine(index - 21)
ElseIf isTopBottom(index) = "top" Then
    Call Determine(index + 19)
    Call Determine(index + 20)
    Call Determine(index + 21)
    Call Determine(index + 1)
    Call Determine(index - 1)
ElseIf isTopBottom(index) = "bottom" Then
    Call Determine(index - 19)
    Call Determine(index - 20)
    Call Determine(index - 21)
    Call Determine(index - 1)
    Call Determine(index + 1)
ElseIf isSideMine(index) = "right side" Then 'check if on far left or far right row
    Call Determine(index - 20)
    Call Determine(inex - 21)
    Call Determine(index - 1)
    Call Determine(index + 19)
    Call Determine(index + 20)
ElseIf isSideMine(index) = "left side" Then
    Call Determine(index - 20)
    Call Determine(index - 19)
    Call Determine(index + 1)
    Call Determine(index + 20)
    Call Determine(index + 21)
Else 'means it is interior spot
    Call Determine(index + 19)
    Call Determine(index + 20)
    Call Determine(index + 21)
    Call Determine(index + 1)
    Call Determine(index - 1)
    Call Determine(index - 19)
    Call Determine(index - 20)
    Call Determine(index - 21)
End If
Else
    'determine what caption to display
    cmdSpot(index).Caption = intCount
End If

   

End Sub
the functions not displayed are pretty self explanatory i think. this is the problem ive been getting. I might be doing this all wrong as i taught myself recursion, so any thoughts or debugging tips are appreciated.
Attached Images
File Type: png minesweeper.png (75.6 KB, 13 views)
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->