1

我正在创建一个小游戏,当用户单击一个按钮时,它会“攻击”怪物,使其损失 5 hp,并使用进度条显示。然后同时怪物也会攻击使玩家失去生命值。但问题是这些事件发生在完全相同的时间,我希望事件之间有 2 秒的间隔。从今天早上开始,我一直在尝试让计时器事件起作用,但它只是不起作用,这是我的代码

   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)           Handles Timer1.Tick

    If Tick = 0 Then
        Timer1.Stop()
        Timer1.Enabled = False
    Else
        Tick -= 1
    End If

End Sub

这是攻击按钮事件

    Private Sub btnAttack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttack.Click
    PlayerAttacks(mhealth, attack)
    textShiftUp(numlines)
    HPBarsAlter(mhealth, health)
    Tick = 2
    Timer1.Start()

    MonsterAttacks(health, mattack, CritRate)
    HPBarsAlter(mhealth, health)
    MobDeath(mhealth, MobNumber)

    Timer1.Stop()

End Sub

如果您需要更多信息,请告诉我谢谢:)

4

1 回答 1

0

基本上,将你的怪物攻击移动到计时器

Private Sub btnAttack_Click(...)
    btnAttack.Enabled = False              ' disable more attacks

    PlayerAttacks(mhealth, attack)
    textShiftUp(numlines)
    HPBarsAlter(mhealth, health)

    MonsterTimer.Interval = 2000
    MonsterTimer.Start()
End Sub


Private Sub MonsterTimer_Tick(...
    ' not sure what the old code was doing

     MonsterTimer.Stop           ' stop the attacks

     MonsterAttacks(health, mattack, CritRate)
     HPBarsAlter(mhealth, health)
     MobDeath(mhealth, MobNumber)

     btnAttack.Enabled = True              ' allow more attacks

End Sub

编辑添加了 2 行来切换等待时攻击的能力。

于 2013-09-28T15:39:20.450 回答