Search code examples
vb.netminesweeper

Verify Position VB.NET


So I'm developing a minesweeper game and im assigning the mines, but i'm unable to create a algorithm to stop a mine to go to a place where there's already a mine, here's what i have so far:

Public Sub initflags()

    Dim line, column As Integer
    For line = 0 To 9
        For column = 0 To 9
            mat(line, column) = 0
        Next
    Next
    Dim numbandeiras As Integer
    Dim r, c As Integer

    Do Until numbandeiras = 34



        Randomize()

        line = Int(Rnd() * 10)
        column = Int(Rnd() * 10)
        r = line
        c = column
        If r And c = 1 Then


            mat(line, column) = 0
        Else
            numbandeiras = numbandeiras + 1

            Call avisinhos()

            mat(line, column) = 1
        End If


    Loop

End Sub

Could someone help me? Best regards, joao.


Solution

  • The simplest thing to do is to check before setting, e.g:

    if mat(line, column) = 0 then
        numbandeiras = numbandeiras + 1
    
        avisinhos()
    
        mat(line, column) = 1
    end if