Limit dice rolls? Add points when clicking a "dice" as background Image on button?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Taylor
    New Member
    • Oct 2014
    • 2

    Limit dice rolls? Add points when clicking a "dice" as background Image on button?

    I have to do a project where there are 5 die, and each player gets 3 rolls per turn. The player then hits cmdPlayer1Roll, which randomizes the die 1-5. The player can randomize the die 3 time but at the end of the 3 rolls they need to have selected 3 numbers from the die. The first player to 1000 wins. I have to what i believe, successfully coded the randomize on the click of cmdPlayer1roll.
    Here is a very fast gyazo gif of what i have coded overall, http://gyazo.com/0dfe67c781a8cec 7ce629db303deb5 9e
    This is the code i used for randomize: (repeated 5 times, 5 dice button boxes/5 dice to roll 3 times)
    Code:
            'randomize cmdDice1 background image
            Call Randomize()
            lowernum = 1
            upperNum = 6
            die1 = Int(Rnd() * (upperNum - lowernum + 1)) + lowernum
            If die1 = 1 Then
                cmdDice1.BackgroundImage = My.Resources.dice1Dot
            ElseIf die1 = 2 Then
                cmdDice1.BackgroundImage = My.Resources.dice2Dot1
    
            ElseIf die1 = 3 Then
                cmdDice1.BackgroundImage = My.Resources.dice3Dot
            ElseIf die1 = 4 Then
                cmdDice1.BackgroundImage = My.Resources.dice4Dot
            ElseIf die1 = 5 Then
                cmdDice1.BackgroundImage = My.Resources.dice5Dot
            ElseIf die1 = 6 Then
                cmdDice1.BackgroundImage = My.Resources.dice6Dot
            End If
    I have 2 issues, here they are:

    1.) I am struggling to determine where and how to add in the limit of rolls. Today i just learned counters, though i do not know how to go about saying a buttonclick is a roll. Here is my attempt
    Code:
      Private Sub cmdPlayer1Roll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayer1Roll.Click
    
            'Attempt at limiting rolls to 3 for player 1 
            lowernum = 1
            upperNum = 6
            roll = 1
            rollsleft = 3
            rollsleft = rollsleft - roll
            If rollsleft = 0 Then
                cmdPlayer1Roll.Enabled = False
            End If
    2.) i have made no progress on figuring out how to make the buttons add the amount of dots the randomized picture in the box has, my teacher, did try to explain that when i wrote the randomize code i included part of it, but as i am a unit ahead of my class she had no time to explain it to me.

    Thanks for any of the help i will get, it is very much appreciated.
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Store the amount of rolls in a public variable. In your attempt to limit it you are resetting it to 3 every time you click the button.. and in your random dice function it would look cleaner using select case instead of a bunch of if statements. Instead of repeating the randomize code 5 times. Turn it into a function and call the function 5 times each one passing the control to change.

    Comment

    • Taylor
      New Member
      • Oct 2014
      • 2

      #3
      Thanks for the tip on the randomize code. Though how do i store the amount of rolls as a public variable?

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        Declare it outside of any function. Generally at the top of the code but still inside the class.

        Comment

        Working...