但是,我正在尝试设置此子手游戏,到目前为止,它仅适用于步进模式。
按Play键后发生的情况是,如果我选择了错误的字母,则在我做出正确的猜测之前它不会显示“ hang子手”的形状。
因此,例如,如果我做出2个错误的猜测(因此在重复循环之前应该显示2个形状),直到我的第3个猜测正确之后,什么都不会发生,然后它会同时显示两个形状。
代码在步进模式下工作正常,如果我使用F8进行代码检查,则没有问题,形状会按顺序显示。不太确定这里可能是什么问题。
Option Explicit
Dim wks As Worksheet
Dim word As Range
Dim rect As Shape
Sub Hangman()
Dim fletter As Variant
Dim myLetter As String
Dim i As Byte
Set wks = ThisWorkbook.ActiveSheet
Set word = wks.Range("B1:J1")
i = 1
Do Until wks.Range("b1:j1").Font.Color = VBA.ColorConstants.vbBlack Or i = 9
myLetter = VBA.InputBox("What is the next letter")
Set word = Range("B1:J1").Find(myLetter)
If Not word Is Nothing Then
word.Font.Color = VBA.ColorConstants.vbBlack
fletter = word.Address
Do
Set word = Range("B1:J1").FindNext(word)
word.Font.Color = VBA.ColorConstants.vbBlack
If word.Address = fletter Then Exit Do
Loop
Else
Set rect = ThisWorkbook.ActiveSheet.shapes("Shape" & i)
rect.Visible = msoTrue
i = i + 1
End If
Loop
End Sub