VBA炸弹游戏

Option Explicit
Sub RePlay()
    Dim rng As Range, i As Long, j As Long
    Set rng = Worksheets(1).Range("B2:J11")
    rng.ClearContents
    rng.Interior.Color = xlNone
    For i = 2 To 11
        For j = 2 To 10
            If Rnd() > 0.9 Then Cells(i, j) = 1
        Next j
    Next i
End Sub

Sub SinglePlay()
    Dim i As Long, j As Long, rng As Range
    i = Round(2 + 9 * Rnd())
    j = Round(2 + 8 * Rnd())
    Cells(i, j).Select
    Set rng = Union(Range(Cells(i, 2), Cells(i, 10)), Range(Cells(2, j), Cells(11, j)))
    rng.Interior.Color = vbRed
    rng.Value = ""
        
End Sub

Sub Play()
    Dim rng As Range, num As Long
    Set rng = Worksheets(1).Range("B2:J11")
    
    Do While Application.WorksheetFunction.Sum(rng) <> 0
        Application.Wait Now + TimeValue("00:00:01")
        Call SinglePlay
        num = num + 1
    Loop
    Debug.Print "总共发射了" & num & "枚炸弹!"
End Sub


上一篇:MySQL查询表中最近7天数据(无数据自动补0,不含本天)


下一篇:浅谈JDBC部分知识及优化使用