我需要帮助一个用于Visual Basic的骰子战斗游戏。
玩家和计算机应该互相争斗。当您单击滚动按钮时,它会生成6个随机图像 - 3个用于PC,3个用于PLAYER。
我把一切都搞定了,但我似乎无法添加3张图片。第一张图片显示,但第二张和第三张图片没有显示,PC也没有显示三张图片。
这是我的代码
//=============================================================================
Public Class Form1
Dim randomObject As New Random() 'Create Random object
Dim BestOfGamesCounter As Integer
Private Sub RollDice_Click(sender As Object, e As EventArgs) Handles RollDice.Click
If GameTextBox.Text <= "0" Then
MsgBox("Number of Games > 0", MsgBoxStyle.Critical)
Application.Restart()
End If
If GameTextBox.Text > "0" Then
BestOfGamesCounter = Convert.ToInt32(GameTextBox.Text)
End If
DisplayDie(d1PictureBox)
DisplayDie(d2PictureBox)
DisplayDie(d3PictureBox)
DisplayDie(UserDice1)
DisplayDie(UserDice2)
DisplayDie(UserDice3)
End Sub
Sub DisplayDie(diePictureBox As PictureBox)
'generate random integer in range 1 to 6
Dim face As Integer = randomObject.Next(1, 7)
'retrieve specific die image from resources
Dim pictureResource = My.Resources.ResourceManager.GetObject(String.Format("die{0}", face))
'Convert pictureResource to type Image and display in ImageBox
diePictureBox.Image = CType(pictureResource, Image)
End Sub ' DisplaDie
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
Dim response As MsgBoxResult
response = MsgBox("Do you want to exit?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
If response = MsgBoxResult.Yes Then
Me.Dispose()
End If
End Sub
Private Sub GameTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles GameTextBox.Validating
If GameTextBox.Text > "0" Then
Do
MsgBox(GameTextBox.Text + " round(s) will be played GOOD LUCK")
Loop While GameTextBox.Text = "STOP"
End If
GameTextBox.Enabled = False
End Sub
结束班