Вопрос

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.

Это было полезно?

Решение

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

Другие советы

You need to store all placed "mines" in an array of some sort. This is better in the end if you want to do something with those mines. If you have mines as objects it makes them even better for now they can have states like dead, alive or "?" like MS version.

Just my 2 cents.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top