2

所以我正在开发一个扫雷游戏并分配地雷,但我无法创建一个算法来阻止地雷去一个已经有地雷的地方,这就是我目前所拥有的:

公共子 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

有人可以帮助我吗?最好的问候,乔奥。

4

2 回答 2

1

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
于 2012-04-30T12:01:43.350 回答
0

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.

于 2012-04-30T12:03:28.173 回答