Jump to content

minesweeper # of mines touching


Recommended Posts

I'm creating a minesweeper game, but it doesn't figure out how many mines are touching each square correctly. It keeps saying that none of them are touching any mines

Func create($width, $height, $mines)
    GUICreate("Mine Sweeper", 15 * $width - 8, 15 * $height + 32, -1, -1)
    $minesleftinput = GUICtrlCreateInput($minesleft, 1, 1, 66, 40, $ES_READONLY)
    $timeinput = GUICtrlCreateInput($minesleft, 1, 1, 66, 40, $ES_READONLY)
    GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
    createbuttons($width, $height)
    
    ;disperse mines
    For $i = 1 To $mines
        $buttonnumber[Random(1, $width, 1)][Random(1, $height, 1)] = "mine"
    Next
    
    ;generate numbers
    For $i = 1 To $width
        For $j = 1 To $height
            
            If $buttonnumber[$i][$j] = "mine" Then ContinueLoop
            
            ;if not lefttopmost then check lefttop
            If $i > 1 Then
                If $j > 1 Then
                    If $buttonnumber[$i - 1][$j - 1] = "mine" Then
                        $buttonnumber[$i][$j] += 1
                    EndIf
                EndIf
            EndIf
            
            ;if not leftmost then check left
            If $i > 1 Then
                If $buttonnumber[$i - 1][$j] = "mine" Then
                    $buttonnumber[$i][$j] += 1
                EndIf
            EndIf
            
            ;if not leftbottommost then check leftbottom
            If $i > 1 Then
                If $j < $height Then
                    If $buttonnumber[$i - 1][$j + 1] = "mine" Then
                        $buttonnumber[$i][$j] += 1
                    EndIf
                EndIf
            EndIf
            
            ;if not bottommost then check botton
            If $j < $height Then
                If $buttonnumber[$i][$j + 1] = "mine" Then
                    $buttonnumber[$i][$j] += 1
                EndIf
            EndIf
            
            ;if not bottomrightmost then check bottomright
            If $i < $width Then
                If $j < $height Then
                    If $buttonnumber[$i + 1][$j + 1] = "mine" Then
                        $buttonnumber[$i][$j] += 1
                    EndIf
                EndIf
            EndIf
            
            ;if not rightmost then check right
            If $i < $width Then
                If $buttonnumber[$i + 1][$j] = "mine" Then
                    $buttonnumber[$i][$j] += 1
                EndIf
            EndIf
            
            ;if not righttopmost then check righttop
            If $i < $width Then
                If $j > 1 Then
                    If $buttonnumber[$i + 1][$j - 1] = "mine" Then
                        $buttonnumber[$i][$j] += 1
                    EndIf
                EndIf
            EndIf
            
            ;if not topmost then check top
            If $j > 1 Then
                If $buttonnumber[$i][$j - 1] = "mine" Then
                    $buttonnumber[$i][$j] += 1
                EndIf
            EndIf
        Next
    Next
    
    
    GUISetState()
EndFunc

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

It works perfectly. I had the bitmaps folder in the wrong place. >_

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...