電子書籍の厳選無料作品が豊富!

任意の地雷を設置するというプログラムです。

この中で地雷を*に、安全地帯を空白にしたいのですがやり方がわからないので、わかる方お願いします。


Sub mine()
Dim minefield(11, 13) As Integer
Dim i As Integer, a As Integer, b As Integer
Dim c As Integer

c = InputBox("地雷の数を決めます")
Randomize
For i = 1 To c
a = Int(Rnd * 10) + 1
b = Int(Rnd * 12) + 1

If minefield(a, b) = 9 Then i = i - 1

minefield(a, b) = 9
Next i

countMine minefield, 10, 12

showInt minefield, 10, 12
' show minefield, 10, 12

End Sub

Sub countMine(f() As Integer, h As Integer, w As Integer)
Dim i As Integer, j As Integer
Dim a As Integer, b As Integer
Dim x As Integer

For a = 1 To 10
For b = 1 To 12
If f(a, b) < 9 Then
x = 0
If f(a, b - 1) = 9 Then x = x + 1 '左に地雷があるか
If f(a, b + 1) = 9 Then x = x + 1 '右に地雷があるか
' ... この部分に追加したいのだが ...
f(a, b) = x
End If
Next b
Next a

End Sub

Sub showInt(f() As Integer, h As Integer, w As Integer)
Dim i As Integer
Const a As Integer = 7
Const b As Integer = 3
Do While h > 0
For i = 1 To w
Cells(a + h, b + i) = f(h, i)
Next i
h = h - 1
Loop

End Sub

A 回答 (1件)

g(a,b)文字列型を用意して、


f(a,b)に対応する文字を入れる。
f(a,b)は他のg(a,b)の値を計算するときに
利用するので、書き換えてはいけない。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!