By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

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

Taylor
P: 2
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/0dfe67c781a8cec7ce629db303deb59e
This is the code i used for randomize: (repeated 5 times, 5 dice button boxes/5 dice to roll 3 times)
Expand|Select|Wrap|Line Numbers
  1.         'randomize cmdDice1 background image
  2.         Call Randomize()
  3.         lowernum = 1
  4.         upperNum = 6
  5.         die1 = Int(Rnd() * (upperNum - lowernum + 1)) + lowernum
  6.         If die1 = 1 Then
  7.             cmdDice1.BackgroundImage = My.Resources.dice1Dot
  8.         ElseIf die1 = 2 Then
  9.             cmdDice1.BackgroundImage = My.Resources.dice2Dot1
  10.  
  11.         ElseIf die1 = 3 Then
  12.             cmdDice1.BackgroundImage = My.Resources.dice3Dot
  13.         ElseIf die1 = 4 Then
  14.             cmdDice1.BackgroundImage = My.Resources.dice4Dot
  15.         ElseIf die1 = 5 Then
  16.             cmdDice1.BackgroundImage = My.Resources.dice5Dot
  17.         ElseIf die1 = 6 Then
  18.             cmdDice1.BackgroundImage = My.Resources.dice6Dot
  19.         End If
  20.  
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
Expand|Select|Wrap|Line Numbers
  1.   Private Sub cmdPlayer1Roll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayer1Roll.Click
  2.  
  3.         'Attempt at limiting rolls to 3 for player 1 
  4.         lowernum = 1
  5.         upperNum = 6
  6.         roll = 1
  7.         rollsleft = 3
  8.         rollsleft = rollsleft - roll
  9.         If rollsleft = 0 Then
  10.             cmdPlayer1Roll.Enabled = False
  11.         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.
Oct 23 '14 #1
Share this Question
Share on Google+
3 Replies


iam_clint
Expert 100+
P: 1,208
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.
Oct 23 '14 #2

Taylor
P: 2
Thanks for the tip on the randomize code. Though how do i store the amount of rolls as a public variable?
Oct 23 '14 #3

iam_clint
Expert 100+
P: 1,208
Declare it outside of any function. Generally at the top of the code but still inside the class.
Oct 23 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.