-3

我正在处理的 vb.net 程序中有三个问题。我正在创建一个骰子游戏,用户可以单击滚动,它会随机滚动并向他们展示他们滚动的骰子的图片。他们可以选择他们想玩多少筹码以及他们下注的数字。他们每次掷三个骰子。

以下是问题:

Duplicates - 当用户点击滚动和随机生成的数字时,其中两个是相同的,它不会显示其中一个。它应该显示其中之一

图像移入 Pictureboxes - 我试图让骰子图像移入 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
4

1 回答 1

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.
于 2012-10-05T15:08:22.780 回答