我正在处理的vb.net程序中有三个问题。我正在创建一个骰子游戏,用户可以点击滚动,它将随机滚动并向他们显示他们掷骰子的图片。他们可以选择他们想要玩多少筹码以及他们打赌的数量。他们每人掷三个骰子。
以下是问题:
重复 - 当用户点击滚动和随机生成的数字时,其中两个是相同的,它不会显示其中一个。它应该显示其中一个
移动到Pictureboxes的图像 - 我试图让骰子图像移动到图片盒中,而不仅仅是让游戏变得可见。
gui图片:http://i.imgur.com/Kn6Nd.png
当前代码:
Dim do1 As Integer = rnd.Next(1, 7)
Dim do2 As Integer = rnd.Next(1, 7)
Dim do3 As Integer = rnd.Next(1, 7)
Dim do4 As Integer = rnd.Next(1, 7)
Dim do5 As Integer = rnd.Next(1, 7)
Dim do6 As Integer = rnd.Next(1, 7)
''Assign the appropriate image based on each die's value.
d1.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d1)), Image)
d2.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d2)), Image)
d3.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d3)), Image)
d4.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d1)), Image)
d5.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d2)), Image)
d6.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", d3)), Image)
Dim iNumber As Integer
Dim iNumber2 As Integer
Dim iNumber3 As Integer
'purpose is to roll the dice and play the game.
'variables and declarations are here.
Dim chips As Integer = 100
If chkBet1.Checked = False And ChkBet2.Checked = False And chkBet3.Checked = False And chkBet4.Checked = False And chkBet5.Checked = False And chkBet6.Checked = False Then
MessageBox.Show("Please select a number to play")
Else
If txtChip1.Text = "" AndAlso txtChip2.Text = "" AndAlso txtChip3.Text = "" AndAlso txtChip4.Text = "" AndAlso txtChip5.Text = "" AndAlso txtChip6.Text = "" Then
MessageBox.Show("You must enter an amount.")
Else
'here we are randomizing the numbers for the game.
'iNumber = Int((6 * rnd()) + 1)
'iNumber2 = Int((6 * rnd()) + 1)
'iNumber3 = Int((6 * rnd()) + 1)
'this will show the dice if the number generated between 1-6 is automatically chosen.
If iNumber = 1 Then
d1.Visible = True
ElseIf iNumber = 2 Then
d2.Visible = True
ElseIf iNumber = 3 Then
d3.Visible = True
ElseIf iNumber = 4 Then
d4.Visible = True
ElseIf iNumber = 5 Then
d5.Visible = True
ElseIf iNumber = 6 Then
d6.Visible = True
End If
'this will show for the second dice.
If iNumber2 = 1 Then
d1.Visible = True
ElseIf iNumber2 = 2 Then
d2.Visible = True
ElseIf iNumber2 = 3 Then
d3.Visible = True
ElseIf iNumber2 = 4 Then
d4.Visible = True
ElseIf iNumber2 = 5 Then
d5.Visible = True
ElseIf iNumber2 = 6 Then
d6.Visible = True
End If
'this will show for the third dice.
If iNumber3 = 1 Then
d1.Visible = True
ElseIf iNumber3 = 2 Then
d2.Visible = True
ElseIf iNumber3 = 3 Then
d3.Visible = True
ElseIf iNumber3 = 4 Then
d4.Visible = True
ElseIf iNumber3 = 5 Then
d5.Visible = True
ElseIf iNumber3 = 6 Then
d6.Visible = True
End If
''this part is for the chips that they win. If they bet one chip, and one dice rolls a one, they got two chips.
If do1 = 1 AndAlso chkBet1.Checked Then
chips = "2"
ElseIf do2 = 2 AndAlso ChkBet2.Checked Then
chips = "4"
ElseIf do3 = 3 AndAlso chkBet3.Checked Then
chips = "6"
ElseIf iNumber = 4 AndAlso chkBet4.Checked Then
chips = "8"
ElseIf iNumber = 5 AndAlso chkBet5.Checked Then
chips = "10"
ElseIf iNumber = 6 AndAlso chkBet6.Checked Then
chips = "12"
End If
''second chip possible winnings.
If iNumber2 = 1 AndAlso chkBet1.Checked Then
chips = "2"
ElseIf iNumber2 = 2 AndAlso ChkBet2.Checked Then
chips = "4"
ElseIf iNumber2 = 3 AndAlso chkBet3.Checked Then
chips = "6"
ElseIf iNumber2 = 4 AndAlso chkBet4.Checked Then
chips = "8"
ElseIf iNumber2 = 5 AndAlso chkBet5.Checked Then
chips = "10"
ElseIf iNumber2 = 6 AndAlso chkBet6.Checked Then
chips = "12"
End If
'third chip possible winnings.
If iNumber3 = 1 AndAlso chkBet1.Checked Then
chips = "2"
ElseIf iNumber3 = 2 AndAlso ChkBet2.Checked Then
chips = "4"
ElseIf iNumber3 = 3 AndAlso chkBet3.Checked Then
chips = "6"
ElseIf iNumber3 = 4 AndAlso chkBet4.Checked Then
chips = "8"
ElseIf iNumber3 = 5 AndAlso chkBet5.Checked Then
chips = "10"
ElseIf iNumber3 = 6 AndAlso chkBet6.Checked Then
chips = "12"
End If
'chips are added up here by all
'chips = iNumber + chips '+ iNumber2 + iNumber3
lblChips.Text = chips
End If
End If
End Sub
答案 0 :(得分:1)
你为每个芯片使用相同的图片框。看起来你应该只有3个图片盒,每个模具一个,它们应该始终可见。然后,当您确定在模具上滚动的值时,请更改图片框中的图像以匹配。将6张图像存储为资源。
表格上有1个按钮和3个图片框。我还有6个图像(每个模具一个)嵌入到我的项目的资源中。我有这个代码在每个图片框上显示正确的图像,基于随机数,每次我点击按钮:
Option Strict On
Public Class Form1
Dim rnd As New Random()
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Get a random digit from 1 to 6 for each die.
Dim die1 As Integer = rnd.Next(1, 7)
Dim die2 As Integer = rnd.Next(1, 7)
Dim die3 As Integer = rnd.Next(1, 7)
'Assign the appropriate image based on each die's value.
PictureBox1.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", die1)), Image)
PictureBox2.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", die2)), Image)
PictureBox3.Image = CType(My.Resources.ResourceManager.GetObject(String.Format("Die{0}", die3)), Image)
End Sub
End Class
其他信息:
I created 6 .png files, one for each side of a die. I named them Die1.png, Die2.png, etc. and then added them as resources to my project.