我目前正在使用VB进行项目,我在btnPull_Click函数中遇到了两个问题。
首先是让3个轮子模仿老虎机的旋转。我有.sleep在那里你会看到延迟,但我似乎无法让它在最终停止之前闪现其他图像。我不认为这是项目的要求,但我想知道如何做到这一点。
我遇到的主要问题是我的if / then声明。我有我的数组(项目要求),但我遇到的问题是我无法将图像转换为字符串。我试图将NumOfSpins(1,2,3)设置为等于Slots(INDEX)并从那里确定支付的价值。
我尝试使用我的For语句并创建一个私有函数,但我也无法使用它。我想我真的被困住了,并且会感激我能得到的任何建议。
Const Slot_Size As Integer = 7
Dim Slots() As Image = {My.Resources.Slot_Cherry, My.Resources.Slot_7, My.Resources.Slot_Bar, My.Resources.Slot_Bell, My.Resources.Slot_Grapes, My.Resources.Slot_Lemon, My.Resources.Slot_Orange}
Dim slotImages() As String = {"cherry", "seven", "bar", "bell", "grapes", "lemon", "orange"}
Dim slotOrder() As Integer = {1, 2, 3}
Private Function RandomNumber(ByVal low As Integer, ByVal high As Integer)
Randomize()
Return Convert.ToInt32(((high - low) * Rnd() + low))
End Function
Private Sub Clear()
For counter = 0 To Slot_Size - 1 Step 1
Slots(counter) = My.Resources.Slot_Bar
Next
End Sub
Private Sub btnPull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPull.Click
'Spins the 3 slot wheels
Dim NumOfSpins1 As Integer = RandomNumber(Slot_Size * 5, Slot_Size * 10)
Dim NumOfSpins2 As Integer = RandomNumber(Slot_Size * 5, Slot_Size * 10)
Dim NumOfSpins3 As Integer = RandomNumber(Slot_Size * 5, Slot_Size * 10)
lblBalance.Text = "$" & balance
For spin = 0 To NumOfSpins1 Step 1
Slot1.Image = Slots(spin Mod Slot_Size)
Next
For spin = 0 To NumOfSpins2 Step 1
Slot2.Image = Slots(spin Mod Slot_Size)
Next
For spin = 0 To NumOfSpins3 Step 1
Slot3.Image = Slots(spin Mod Slot_Size)
Next
Return
System.Threading.Thread.Sleep(100)
Slot1.Refresh()
Slot2.Refresh()
Slot3.Refresh()
'Determine if the user wins or loses money
If NumOfSpins1 = slotImages(0) Then
balance += 2
End If
End Sub
结束班