Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Rolling Dice


Anyone having some VB code or DLL for rolling dice. I'm making a little game for my boy and I don't want to invent 'the wheel again'?

Thanks in advance.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Rolling The Dice
i am tring to create a game where i roll the dice 36000 times and then want to print the total number of combonations that i got. here is some of my code but i cant get it to work.

[vbcode]

Dim total(2 To 12)


Private Sub Command1_Click()

For a = 1 To 36000
die1 = (1 + Int(Rnd * 6))
die2 = (1 + Int(Rnd * 6))
roll = die1 + die2

total(roll) = total(roll) + 1

Next a

End Sub

Private Sub Command2_Click()

For a = 0 To roll - 1
Print total(a)
Next a


[vbcode]

Dice Rolling
how would i have my program choose a random number, either 1, 2, 3, 4, 5, or 6?

Find Sum Of Two Rolling Dice
I have a question about finding two rolling dice. Here is my program. But my output come out :

2 0 0 8
3 0 0 8
4 0 0 8
5 0 0 8
6 0 0 8
7 0 0 8
8 0 0 8
9 0 0 8
10 0 0 8
11 0 0 8
12 0 0 8


May someone help me?? Thank



Option Explicit

Dim x As Integer
Dim sum As Integer
Dim roll1 As Integer
Dim roll2 As Integer
Dim proper As Integer
Dim roll As Integer


Dim freq(2 To 12) As Integer

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdRoll_Click()

Dim count As Double

Call Randomize

sum = 0
roll1 = 0
roll2 = 0
count = 0


roll1 = 1 + Int(Rnd() * 6)
roll2 = 1 + Int(Rnd() * 6)
roll1 = roll1
roll2 = roll2

sum = roll1 + roll2
roll = sum

Select Case sum
Case 2
proper = 1 / 36
Case 3
proper = 2 / 36
Case 4
proper = 3 / 36
Case 5
proper = 4 / 36
Case 6
proper = 5 / 36
Case 7
proper = 6 / 36
Case 8
proper = 5 / 36
Case 9
proper = 4 / 36
Case 10
proper = 3 / 36
Case 11
proper = 2 / 36
Case 12
proper = 1 / 36

End Select


For x = LBound(freq) To UBound(freq)
lstList1.AddItem x & vbTab & freq(x) & vbTab & vbTab & Format$(freq(x)) & vbTab & sum

Next x

End Sub

Dice Rolling Game. Very Challenging, HELP!
i need code for a game where you roll a die, shows the number rolled (Random!) , and if the number is even, the player loses $20 and if odd, the player wins $20. The player must be able to play many times, with their winnings accumulating, with the winnings displayed. I'm stuck, can anyone please help me out?


SKM

NEED A DICE SPRITE - ROLLING DICES
I am searching for a dice sprite
i mean all the pictures of the dice
1,2,3,4,5,6

so i can run them all after another to get a rolling way

thank you

Rolling Menu.
How can i create a menu such as the rolling osX menu macs have at the bottom of the screen. where my mouse over the image makes it biggar, and when my mouse reaches the last visable menu item it will scroll automatically in that direction. im not sure if i am making sence to anybody but myself. anyhelp would be awesome as i am a newbie programmer.

Rolling Arrays
Hi everyone,
I am doing a project where I put my data into arrays..Let's say DataX and DataY arrays.I do a calculation every minute and add one element into an array. DataX(0)= 1 (minute) DataY(0)=3.05 and so on..
I am displaying this data in an XY graph. Then I use ReDim Preserve and do second minute calculation and add the result into Y array again and so on..In my plotting window, I would like to show, let's say, 360 min worth of data all the time.When I dis calculation on the 360th minute then I would like to ged rid of, let's say, initial 180 minutes worth of data from my array and add new 180 minutes worth.So I will always display last 360 minutes of the calculations.
I assign the array pointers back to 0 when I reach 360, then I lost the continuity (the trend rather). How can I go about this??Any suggestion would helpful.
Thanks alot!
Hudai

Rolling Back Changes
I have Character defined as a collection at the module level. MyCharacter is an instance of the class, also defined at the module level. The question is would this logic work:


Code:
Public Sub DoThis()
Dim OldCharacter as New Character

Set OldCharacter = MyCharacter

'This should mean that OldCharacter is now an exact copy of MyCharacter

'Make a lot of changes here. Here is the real question. If I make changes
'MyCharacter, are those changes carried through to OldCharacter?

'If program decides that the changes where not appropriate then I
'would say:

Set MyCharacter = OldCharacter

'The effect would be to undo all of the changes that have been made
'to MyCharacter. Becuase now, MyCharacter becomes a copy of
'OldCharacter. Right?
End Sub?

Using A 'Rolling Variable'
Hi,

I'm using 16 combo menus on a form, Monday1 - Monday16

What I want to do is go through these, checking each value contained in the menu.

I had this as an idea of what to do, but it doesnt work.

--------------
Dim i as integer

Do While i < 16
i = i + 1

If monday(i).text = 0 Then
mcconttxt = 0
Else
mcconttxt = 1
End If
Loop
--------------

The idea uses a counter to change the number which effects the variable.

It saves doing something like this:

If monday1.text = 0 Then
mcconttxt = 0
Else
mcconttxt = 1
End If
If monday2.text = 0 Then
mcconttxt = 0
Else
mcconttxt = 1
End If
If monday3.text = 0 then...
...
and so on...

Any thoughts on how this would be achieved?

Neil.

Rolling Over A Scrollbar
I would like to have a (horizontal) scrollbar such that when it has reached its maximum value and the slider is at the righmost position, click on the right arrow makes the scrollbar value equal to the minimum value.

Likewise, when the slider is on the leftmost position and you click on the left arrow it should take its maximum value.

I thought it was easy to implement but I don't really know how to start.

Rolling Averages
Hi People.

I have data coming in 5 times per second through a comm port, i would like to average the data, however i need to do it and display it in real time... rather than taking perhaps 25 lots of data and then averaging, i need to do it each time up to around 25. Whats the best way?, i am sure it can be done using an array somehow, although when i start to try my head explodes and its not pretty!, please help. Cheers

Rolling 24 Month Interval
I have a database set up that has dates on the left, which are sorted chronologically, but there are missing spaces. For example, row 1 may have 10/20/2005. Row 2 could have 8/15/2005, then row 3 would have 7/2/2005, etc. Then I have columns for each date called FF,EFF, etc. The only thing that will go in these fields is a number. 0,1,2,3, etc. I want either another spreadsheet that I can chart from, or a chart that can do a 24 month rolling interval. I want it so when you are looking at 8/15/2005, and then you go out and look at a column called "24 month FF", it totals up the FF column for the past 24 months. But here's the really tricky part. I need the chart to be sorted by months. So that if i were to look back at January of 2005, it would add up all FFs in january of 2005 plus all previous FFs from 24 months behind it. HELP!!

Rolling Values Through Textboxes??
Couldnt figure out how to switch between textboxes..
I created an controlarray txtbox(1 to 16) and i get randomized inputs every 30 second.... (Barcodes) what i want is now that the first input i get is displayed in txt(1) the next input also will be displayed in txt(1) thats no problem but the first input have to move down to txt(2) at the next input txt1 => txt2 txt2=>txt3 and so on i tried to lay the input in an array to but that didnt work the way i wnated..:-( but that does it never:-) but i think thats programming, heh
how can i do that that it rolls between the textboxes? I'll try further but i would appreciate any hints.

Greatz

Rolling 6 Month Period
I have a table that records login and logout entries for the reps that work in our phone department. When a rep misses a day, it is considered an negative performance occurrence. Each rep is given a warning when he/she reaches 4 occurrences within a 6 month rolling period. For example, the rep is late on 1/1/2005, 2/3/2005, and 3/2/2005. If the rep misses a day after 7/1/2005, the rep will still only have 3 occurrences within the 6 month rolling period (2/3/2005, 3/2/2005, and the newest entry). I'm trying to design a query that captures this dynamic environment, but I can't seem to find a good start. I've tried searching for the count of entries using a subquery. The main query searches for a date that meets the absence criteria (displayed field), then returns a count of entries that contain the absence criteria between the date of the first entry and a date 6 months in the future. Any ideas?

Fast Number Rolling ?
Hello,
I need to make something for rolling number's betwen 1 - 2000.
Only when press start / stop to give me some number and again
start rolling. I plan to make something for customers, like small tombola.
Can someone help?

Rolling Over Text Box Snatches It!!!
I create a hyperlink via some code that I got some good help with from a member (sorry forgot who you are...)...that when rolling on the text box a hand appears and allows the text to be clicked to open the application. Now all of a sudden im using that same code somewhere else and it simply grabs the entire text box and moves it around rather than the hand image for the mouse icon to appear. heres the code:


Code:
Private Sub txtHyperlink_DragDrop(Source As Control, X As Single, Y As Single)
On Error GoTo Err_Handler
'sub procedure that has a link in the
'text field to the euro calc sheet
If Me.txtFilePath.Text = "" Then
Exit Sub
End If

ShellExecute Me.hwnd, vbNullString, Me.txtFilePath, vbNullString, Me.txtFileName.Text, SW_SHOWNORMAL

Done:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Done


End Sub

Private Sub txtHyperLink_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
On Error Resume Next
If Me.txtFilePath.Text = "" Then
Exit Sub
End If

If State = vbLeave Then
With txtHyperlink
.Drag vbEndDrag
End With
End If
End Sub

Private Sub txtHyperlink_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If Me.txtFilePath.Text = "" Then
Exit Sub
End If

Me.Image1.Visible = True
With txtHyperlink
.DragIcon = Image1.Picture
.Drag vbBeginDrag
End With

End Sub


And in the form move event i have:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Me.MousePointer = vbDefault
End Sub

Whats the deal with this? Its not working like it should be...

Jon

Simulate A Frame Rolling Up...?
Can someone get me started in the right direction. I would like to give the simulation of a frame rolling up to "nothing".

Rolling Ball On A Slop Surface
hey pepole
i need help with my project
im trying to programe a game like in Xp-Plus the game with the maze and the ball
i wanna know how to roll a ball on a slope surface
i mean that the ball getting more speed when the surface getting more slope.
(sorry about the english)
anyone that can help me plz do it
10x
=]

Rolling Back Adding New User?
Hello,

I add a new user by adding him/her to the ADOX.Users collection. Then, I need to the add him/her to some groups by ADOX.Users.Groups.Append and to a table of user personal data (standard MS Access XP table). I use a similar code to edit the user, ie. change permissions etc.

This is a complicated procedure that can fail for several reasons. Is there any way to make all of this to be a transaction or some other action that can be easily rolled back in case of error?

Thanks.

Dice
i m making snakes and ladders
so i am using a dice..
and every time the user rolls, the new random number will be added to the previous sum...
how do i get it to add..
i have
roll & sum as variables

roll=int(rnd*6)+1
sum = sum + roll

sum is the final number where the player should be rite now..

Dice
How can i make a dice to count from one to six?
Of course the numbers will be ramdon.

Following On From The Dice
hi,

i used this code

Private Sub Command1_Click()
Dim Num1%, Num2%
Randomize Timer
Num1 = Int((6 * Rnd) + 1)
Num2 = Int((6 * Rnd) + 1)
Image2.Picture = LoadPicture("C:My DocumentsvbTotal Dominationdicedice " & Num1 & ".jpg")
Image3.Picture = LoadPicture("C:My DocumentsvbTotal Dominationdicedice " & Num2 & ".jpg")
End Sub
to create the random dice

but now i need something that adds up the dice and displays the answer in a label, i am leading this to once the label has the number it has to move an object to set of co-ordinated, that coincide with the number on the dice

PLEASE HELP ME !!!

Thanks

Merlin ?

Does VB6 Support Scroll Button Rolling Event?
I would like to try to use my rolling scroll button to change a vertical scroll bar value.

I haven't been able to identify that event with a control.

Depressing the scroll button causes a MouseDown event, with Button=4, but is there a way to read the scroll value?

I've done a search, but to no avail.

Thanks.
SchMan

Need Help With Dice Roller....
Hello Everyone...

I'm trying to make a dice roller program that can be use for pen and paper role-playing games. So far everything works the way its suppose to. What I'm having trouble with is, there's a feature I want to include in my program called Wild Die and I'm not sure how to make it work. The Wild Die feature should only be available when rolling 6 sided dice. Now let me explain what the wild die is and what it does.

When rolling some 6 sided dice one and only one die is pick to be the wild die (If your only rolling one 6 sided die then it's the wild die). If this die rolls a six its added to the total and is rolled again, if it comes up 6 again you add it to the total, and you keep rolling the die if it comes up six. If it comes up as something besides six you add up all the rolls and your done.

Now if on the first roll the die should come up as a 1...I need it to add all the dice rolled together and add a * next to the total. That way you know that the wild die came up as a 1 on the first roll.

I hope that makes sense.

I'm still pretty new to VB, this has got me stumped. If any one can help me I would be very grateful.

I have attached my program so you can see my source code and form.

Thanks...

Dumpster Tom

Dice Program, Help Please?
I have to create a dice rolling program. When clicked, a button with the caption, Roll Dice, generates random numbers (1 through 6) for two dice on the form. I've got this part working. However, I have to make it so that when I click Roll Dice, it will keep rolling the two dice every couple of seconds or so without me having to keep clicking the button. Any ideas?

I feel stupid asking this actually. It should be pretty simple.

Any help would be appreciated. I'll try to post my code tomorrow. It's on my hard drive at school.

Dice Roll
how can i make a dice and it displays what is rolled in my chat menu

ex.it rolls a 3
Says "Raptrex has rolled a 3"

i looked at dice source codes but none of them is text

Can Anyone Help Me Out With A Dice Game?
Hi, I made this dicegame and it works sort of
but the sides with the marks on it change every 4,5 clicks while they have to change everytime you click the throw button.

What do I have to do to make the sides of the dice change everytime?



Private Sub CmdDobbel_Click()
'Throw with two dices to get random eyes

Dim Dobbel1
Dim Dobbel2

Dobbel1 = Int((6 * Rnd) + 1)
Dobbel2 = Int((6 * Rnd) + 1)

If Dobbel1 = 1 Then PicSide1.Visible = Not PicSide1.Visible
If Dobbel2 = 1 Then PicZijde1.Visible = Not PicZijde1.Visible
If Dobbel1 = 2 Then PicSide2.Visible = Not PicSide2.Visible
If Dobbel2 = 2 Then PicZijde2.Visible = Not PicZijde2.Visible
If Dobbel1 = 3 Then PicSide3.Visible = Not PicSide3.Visible
If Dobbel2 = 3 Then PicZijde3.Visible = Not PicZijde3.Visible
If Dobbel1 = 4 Then PicSide4.Visible = Not PicSide4.Visible
If Dobbel2 = 4 Then PicZijde4.Visible = Not PicZijde4.Visible
If Dobbel1 = 5 Then Picside5.Visible = Not Picside5.Visible
If Dobbel2 = 5 Then PicZijde5.Visible = Not PicZijde5.Visible
If Dobbel1 = 6 Then Picside6.Visible = Not Picside6.Visible
If Dobbel2 = 6 Then PicZijde6.Visible = Not PicZijde6.Visible

End Sub

Private Sub Form_Load()
MsgBox "Press the throw button to throw"
End Sub

Need Help With Dice Roller....
Hello Everyone...

I'm trying to make a dice roller program that can be use for pen and paper role-playing games. So far everything works the way its suppose to. What I'm having trouble with is, there's a feature I want to include in my program called Wild Die and I'm not sure how to make it work. The Wild Die feature should only be available when rolling 6 sided dice. Now let me explain what the wild die is and what it does.

When rolling some 6 sided dice one and only one die is pick to be the wild die (If your only rolling one 6 sided die then it's the wild die). If this die rolls a six its added to the total and is rolled again, if it comes up 6 again you add it to the total, and you keep rolling the die if it comes up six. If it comes up as something besides six you add up all the rolls and your done.

Now if on the first roll the die should come up as a 1...I need it to add all the dice rolled together and add a * next to the total. That way you know that the wild die came up as a 1 on the first roll.

I hope that makes sense.

I'm still pretty new to VB, this has got me stumped. If any one can help me I would be very grateful.

I have attached my program so you can see my source code and form.

Thanks...

Dumpster Tom

Dice Game
Yeah we have to make a dice game not actually showing graphics of dice moving or anything just you click it shows you in textboxes how many of what number you rolled and a text box that shows you how many times you rolled.

sugesstions?

Random Dice
hi,

i am trying to write a program that has six pictures of the six sides of a dice, and when i click on a button i want the program to randomally choose one of these pictures, and display it

can anyone help me

Merlin ?

Dice Program Help!
This program will have a starting form which will branch to a dice rolling form whose appearance and actions will depend on the settings made in the starting form.

Your starting form should contain a set of option buttons (use a control array) to allow the choice of a background color for the dice rolling form (at least 5 color choices). It should also contain a scroll bar that allows you to select the number of dice to roll (1 minimum to 6 maximum). Clicking a command button will bring up the dice rolling form.

The Dice Rolling form will immediately start rolling the selected number of dice when it receives the focus. Use a Timer control to flash a series of randomly generated dice on the screen every 100 milliseconds to simulate the rolling of the dice. You can write the program to stop the dice rolling by clicking on a Stop button, or after an elapsed time. Use a close button to return focus to the starting form. The sum of the dice should appear on the starting form.

what I have ... (starting form)

Option Explicit
Private Sub Form_Load()
With VScroll1
.Min = 1
.Max = 6
End With
End Sub

Private Sub VScroll1_Change()
Label1.Caption = VScroll1.Value
End Sub


Private Sub CMDROLL_Click()

If Optioncolor(0) = True Then
FRMROLL.BackColor = vbRed
ElseIf Optioncolor(1) = True Then
FRMROLL.BackColor = vbBlue
ElseIf Optioncolor(2) = True Then
FRMROLL.BackColor = vbYellow
ElseIf Optioncolor(3) = True Then
FRMROLL.BackColor = vbGreen
ElseIf Optioncolor(4) = True Then
FRMROLL.BackColor = vbBlack
End If

FRMMAIN.Visible = False
FRMROLL.Visible = True
End Sub

(Rolling form)
Option Explicit
Private Sub Form_Load()
Me.Show
Image1.Move -Image1.Width, Me.Height
Image2.Move -Image2.Width, Me.Height
End Sub
Private Sub CMDresult_Click()
FRMMAIN.Visible = True
FRMROLL.Visible = False
End Sub

Private Sub Timer1_Timer()
Static dice1 As Boolean
If Image1.Left &gt; Me.Width Or _
Image1.Top + Image1.Height &lt; 0 Then
Image1.Move -Image1.Width, Me.Height
Image2.Move -Image2.Width, Me.Height
End If
dice1 = Not dice1
If dice1 Then
Image1.Move Image2.Left + Rnd * Image1.Width, _
Image2.Top - Rnd * 0.5 * Image1.Height
Else
Image2.Move Image1.Left + Rnd * Image2.Width, _
Image1.Top - Rnd * 0.5 * Image2.Height
End If

Image1.Visible = dice1
Image2.Visible = Not dice1

End Sub

Please HELP

Finished Dice Game
Dear,

Under the help of this forum, my dice game finally finished!

Here is the link:
http://www.acad.polyu.edu.hk/~002118...P_HTML/hp.html

You can donwload the game, of course, free.

The game will generate some .txt files.
It is great for you to send me back all the files in a zip file by:
00211855d@polyu.edu.hk

Thanks
Enjoy the game, hopefully

A Betting Dice Game...
ok ive given up on the sliding ouzzle game and poker machine game and now im making a dice betting game... as always theres something wrong...

ive got it attached so u can see wat ive done wrong...

there r 2 errors

the first.... ive got it to u roll 2 dice... and ive got another label showing the addition of the 2 dice... and for some reason watever i do it doesnt work...

the second.... ive got a label and a vscrollbar for choosing the number u bet on... 2 to 12... so for 7... the odds r 2 to 1.. for 6 and 8 its 3 to 1... for 5 and 9 its 4 to 1 and etc and i dont know y wat i did doesnt work.... it will do 3 to 1 for 6 and 8 and 2 to 1 for 7... but nothing else...

any ideas?
thx

Yahtzee Dice Game--Take A Look
Here is a version of Yahtzee that I threw together in about 2 and a half hours. Looking back, I realize that I could've made it better & more efficient by using control arrays. However, here is the code so that you can see what I did.

I always appreciate feedback, positive or negative...

Help For Progamming A Dice Game!
OK, i am a beginner with vb and need to do an assignment for a dice game. right now i have no idea of how to code this.
well, this game is a simple dice game. Its a game where there's 5 dices and i need to roll the dice,if a 2 or 5 appear then that dice would disappear, the dice im showing its an image. I really need help at how to randomise the 5 dice and hide the dice if a 2 or 5 appear.

Ok I Give Up. Need Help. {Dice Rolls}
after doing this since yesterday, i give up.

Code:
Private Sub BtnRoll_Click()

If ComboDiceSide.Text = "" Then
MsgBox "Select dice sides", vbOKOnly

BtnRoll.SetFocus
Exit Sub
End If
Dim i As Integer, randomeD As Integer, P As Integer, countit As Integer

Randomize
P = 1



Select Case randomeD 'countit

Case ComboDiceSide.Text = "4"
randomeD% = (Rnd * (ComboDiceSide.Text - 1)) + 1
LBLResult.Caption = randomeD
Case ComboDiceSide.Text = "6"
randomeD% = (Rnd * (ComboDiceSide.Text - 1)) + 1
LBLResult.Caption = randomeD
Case ComboDiceSide.Text = "8"
randomeD% = (Rnd * (ComboDiceSide.Text - 1)) + 1
LBLResult.Caption = randomeD
Case ComboDiceSide.Text = "10"
randomeD% = (Rnd * (ComboDiceSide.Text - 1)) + 1
LBLResult.Caption = randomeD
Case ComboDiceSide.Text = "12"
randomeD% = (Rnd * (ComboDiceSide.Text - 1)) + 1
LBLResult.Caption = randomeD

End Select
End Sub
the thing is, if i select from the number of rolls (1 to 30) and number of sides ( 4...., 10, 12), i want to add up all the result. what i want to happen is select from the number of rolls, then throw the dice, then add up the sum for each dice thrown...

sorry if im so weak at this one cuz i only got a couple hrs of sleep
thanx

edit: sorry forgot to put attachment

Dice Roll Gameboard Help
Hey, I'm creating a VB game board that has 16 command buttons (in a square that are spots where the user would go) Then there is 100 dice rolls button that when the user clicks, numbers show up on each command button of how many times each were landed on. out of 100 rolls of 2 dice) im totally lost with the control arrays, the 2 call buttons, etc. the game starts at tab index 0 and ends at 15
do u think u can help me out?

This is the code i have so far, I have no clue how to go about this.

[quote]Option Explicit

Private Sub cmd100dicerolls_Click()
Dim intarray(0 To 15) As Integer
Dim intcount As Integer
Dim inttotal As Integer
Dim intnew As Integer
Dim intdice1 As Integer
Dim intdice2 As Integer


intcount = 0
For intarray = 0 To 15

If (inttotal + intarray) > 15 Then
intnew = intcount


End Sub

Private Sub cmddone_Click()
Unload Me
End Sub

Private Sub Form_Load()
Randomize
End Sub
[quote]

Craps Dice Games
hi all

I have to Write a Visual Basic Project to simulate a dice game known as ‘Craps’.
The rules of the game are

A player rolls two dice. Each die has six faces, These faces contain 1, 2, 3, 4, 5 and 6 spots.
The dice are rolled and after the dice have come to rest, the sum of the spots on the two upward faces is calculated.
If the sum on the first throw is 7 or 11 then the player wins.
If the sum on the first throw is 2 ("snake eyes"), 3 ("trey") or 12 ("boxcars") then the player loses (ie the house wins).
If the sum on the first throw is 4, 5, 6, 8, 9 or 10, then that sum becomes the player's "point".
To win in this case the player must continue rolling the dice until he makes his "point".
If the player rolls a 7 before he has made his point then he loses and the house wins.

how do i on the first throw when the sum = 4,5,6,8,9,10 get the sum to become the players point and continue rolling the dice unitl the player makes is point or if 7 is rolled during this time the player loses.
this is my code so far

Dim txt As Integer
Dim number As Integer
Dim number1 As Integer
Dim numbertotal As Integer
Dim RandomNum As Integer
Dim RandomNum2 As Integer

Private Sub point_Click()

End Sub

Private Sub play_Click()
roll.Visible = True

End Sub

Private Sub roll_Click()
Randomize Timer
RandomNum = Int(Rnd * 6) + 1
RandomNum2 = Int(Rnd * 6) + 1
Text1 = RandomNum
Text2 = RandomNum2
Select Case Text1
Case 1
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice1.bmp")
Case 2
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice2.bmp")
Case 3
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice3.bmp")
Case 4
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice4.bmp")
Case 5
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice5.bmp")
Case 6
dice1.Visible = True
dice1.Picture = LoadPicture("C:university workvisual basiccrapsdice6.bmp")
End Select
Select Case Text2
Case 1
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice1.bmp")
Case 2
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice2.bmp")
Case 3
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice3.bmp")
Case 4
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice4.bmp")
Case 5
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice5.bmp")
Case 6
dice2.Visible = True
dice2.Picture = LoadPicture("C:university workvisual basiccrapsdice6.bmp")
End Select
number = Text1
number1 = Text2
numbertotal = number + number1

Select Case numbertotal
Case 7, 11
total.Caption = "Your Point is" & Space(1) & numbertotal
info.Caption = "You Win!"
roll.Visible = False
Case 2, 3, 12
total.Caption = "Your Point is" & Space(1) & numbertotal
info.Caption = "You Lose"
roll.Visible = False
Case 4, 5, 6, 8, 9, 10
total.Caption = "Your Point is" & Space(1) & numbertotal
info.Caption = "Roll Again!"
End Select

End Sub

any help would be greatley appreciated

john

Sigh* The Dice Game
Public Sub cmdguess_Click()
Text1.Text = RollDice()

End Sub

Private Function RollDice() As Integer
Randomize
RollDice = Int((6 * Rnd) + 1)
End Function

I need it to be displayed so it says in a text box for each number how many times each number was rolled. say for examp. 6 was rilled 3 time and 4 was rolled twice along with all the numbers also rolled were rolled blahblahalahl

Yatzee/dice Problem
Ok, im makeing a yatzee type game and i'm having a little trouble with checking for matches. If you have any ideas on how i can get it work or just improve my code, that would be great. here's what i have so far:

dim matches(5)
for i =cmddice.lbound to cmddice.ubound
for j=cmddice.lbound to cmddice.ubound
if i&lt;&gt;j and cmddice(i).caption = cmddice(j).caption then
matches(cmddice(i).caption)=matches(cmddice(i).caption)+1
end if
next i
next i

Thats what im trying to use to determine how many dice i have of each value. what should i do?

How Can I Make This Dice Work?
Hi,

I am making a game in VB. I have an image box which will be a dice (ImgDice) - which the player can use by clicking a button marked "roll". I have 6 other image boxes - one for each number with bitmaps loaded in - they are called ImgDice1 .. through to ImgDice6.

What I want to know is the code that I can attach to the `roll` button o RANDOMLY load up one of the dice numbers, but I want it to be completely random.

Any code for this...

Thanks

Mark

Numbered Dice Roll + Average
Hey there.
I'm 16 and pretty new to VB so I decided to sign up here for help.
I have a standard dice rolling program, when I click a certain command button it randomizes the image of a dice from 1-6. I now want to give the user the option of how many times they want to roll the dice. I then want The dice program to display (somewhere) the average roll number.
With little previous programming experience I need help
My code so far is ...


Code:
Private Sub CmdRoll_Click()

Dim lngCatch As Long
Dim intCounter As Integer
Dim intRandom As Integer

Randomize

intRandom = Int(Rnd * 6) + 1
If intRandom = 1 Then
ImgDice.Picture = LoadPicture("one.GIF")
ElseIf intRandom = 2 Then
ImgDice.Picture = LoadPicture("two.GIF")
ElseIf intRandom = 3 Then
ImgDice.Picture = LoadPicture("three.GIF")
ElseIf intRandom = 4 Then
ImgDice.Picture = LoadPicture("four.GIF")
ElseIf intRandom = 5 Then
ImgDice.Picture = LoadPicture("five.GIF")
ElseIf intRandom = 6 Then
ImgDice.Picture = LoadPicture("six.GIF")
End If

End Sub

Help appreciated with coding + anything else I need to add to the form.

Rnd Used For Dice Throws && Card Shuffling.
Does anybody know of a pseudo random number generator and/or algorithm suitable for the following?

I recently developed a Visual Basic application which simulates Casino Craps (Dice) and simulates dealing from a 52 card deck. The application does only a fair job with the dice, and does a poor job with the cards.

I used the standard pseudo random number generator provided by VB. See code below for shuffling algorithm.

The results were interesting.

The Dice throwing simulation got the following results after about 10 million pass line bets (about 34 million dice throws).Each die simulation indicated the correct probabilities to about 5 digits of precision. True probability for each digit is 1/6 (.1666666666 . . .). Simulation indicated .16666xx for most numbers.The simulated totals were precise to about 5-6 digits.The probabilities of making various points were precise to slightly less than 3 digits.The overall probability of winning a pass line bet was wrong in the third digit.
True probability: .4929292929 . . . Simulated probability: .4937xxxxThe above results seemed to have stabilized after 3-5 millions pass line bets, not getting more precise as the number of dice throws increased.

The above suggests that the pseudo random number generator did a good, but not excellent job of simulating dice throw probabilities. If it was excellent, the precision would continue to improve as the number of throws increased. It did a poor job of simulating the overall probability of wining a pass line bet.

BTW: I wrote a similar application many years ago using a different version of the Basic language. That simulation indicated that the player should expect to beat the casino, due to bad simulation of the probabilities of making a point. For that simulation, the other simulated probabilities were fairly good. Apparently, the Rnd Function was improved significantly some time in the past 10-15 years.

Making a point requires throwing a particular total before throwing a seven. Although the simulated frequencies for the various totals are fairly precise, the simulated probabilities of making a point are poor. It is like a trick question about train schedules for which the less likely event is very likely to occur first, due to unexpected clustering.

Suppose there are ten trains each hour from Philadelphia to New York and only one train per hour from Philadelphia to Washington. Now suppose that the New York trains leave every minute starting on the hour, while the single Washington train leaves at one minute before each hour. If you arrive at a random time, the next train to leave is far more likely to be a Washington train than a New York train.

Probability, random number generation, and simulations are fraught with subtleties, which are counter intuitive.

The card dealing simulation was only precise to about 3 digits. This application simulated the dealing of 5-card poker hands & 13 card bridge hands. It also simulated drawing a single card from a 52 card deck. The Visual Basic pseudo random number generator does not do a good job of simulating the dealing of cards. Perhaps using the Rnd Function in a different manner might help.
VB Code:
Private Sub Shuffler()Dim J As IntegerDim K As IntegerDim ThisCard As Integer For J = 0 To 51  'Make pseudo random swaps in array of 52 cards.        ThisCard = Card(J)        K = Int(Rnd * 52)        Card(J) = Card(K)        Card(K) = ThisCard   Next J For J = 51 To 0 Step -1  'Backwards in case Rnd is biased toward either high or low values.        ThisCard = Card(J)        K = Int(Rnd * 52)        Card(J) = Card(K)        Card(K) = ThisCard   Next J End Sub
Note there is a nonzero probability (1/52 ?) of any particular card staying in the same place in the deck. This suggests that for most shuffles at least one card stays in the same place. I do not think this is a serious problem.

Dice Game : Help Me With My Rotten Code Please.
Hey, I'm trying to make a dice game and its not working for me! Heres the code and the project is attached.
Code:Dim Dpage As String
Dim x As Integer
Dim strStart As Integer, strFinish As Integer

Private Sub Form_Load()
For u = 0 To 3
YourDice(u).Picture = YourDice0.Picture
Next
YouQualifier1.Picture = QualifierDice1.Picture
YouQualifier4.Picture = QualifierDice4.Picture
End Sub

Private Sub PlayButton_Click()
   RollDie
End Sub
Private Function RollDie()
Dim x As Integer, w As Integer, v As String
    v = GetSetString(Dpage, "name='index' value='", "'>", True)
    Do Until Len(v) <> "1"
        Select Case v
            Case "1"
                w = 0
            Case "2"
                w = 1
            Case "3"
                w = 2
            Case "4"
                w = 3
            Case "5"
                w = 4
            Case "6"
                w = 5
        End Select
        v = GetSetString(Dpage, "name='index' value='", "'>")
        NewDice(x).Picture = Dice(w).Picture
        x = x + 1
    Loop
    TakeDice
End Function
Private Function TakeDice()
For y = 0 To 5
    If NewDice(y).Picture = Dice(0).Picture And YouQualifier1.Picture = QualifierDice1.Picture Then
        YouQualifier1.Picture = NewDice(y).Picture
    End If
    If (NewDice(y).Picture = Dice(3).Picture And YouQualifier4.Picture = QualifierDice4.Picture) = True Then
        YouQualifier4.Picture = NewDice(y).Picture
    End If
    For u = 0 To 3
    If YourDice(u).Picture = YourDice0.Picture Then
            Select Case y
            Case 5
               YourDice(u).Picture = NewDice(y).Picture
               'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
            Case 4
                YourDice(u).Picture = NewDice(y).Picture
                'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
            Case 3
               YourDice(u).Picture = NewDice(y).Picture
                'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
            Case 2
                YourDice(u).Picture = NewDice(y).Picture
                'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
            Case 1
                YourDice(u).Picture = NewDice(y).Picture
                'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
            Case 0
                YourDice(u).Picture = NewDice(y).Picture
                'MsgBox ("Your Dice " & u & " is equal to NewDice " & y)
        End Select
    End If
Next
Next
End Function


Public Function GetSetString(SourceString As String, FirstString As String, SecondString As String, Optional NewString As Boolean) As String
If strFinish = 0 Then: strFinish = 1
If NewString = True Then: strFinish = 1
strStart = InStr(strFinish, SourceString, FirstString) + Len(FirstString)
strFinish = InStr(strStart, SourceString, SecondString)
GetSetString = Mid(SourceString, strStart, strFinish - strStart)
End Function




edit by johnminkjan: topic title



Edited by - johnminkjan on 9/11/2004 7:32:58 AM

Complex Dice Roller (compare And Add Like Numbers)
I have written a pen and pape type RPG game and was making a dice roller for it.

The basic mechanic goes "Roll X Dice. Take the highest die. If any dice are alike, combine them." so if you rolled 5 dice getting 2,2,2,4,5, your result would be 6. Likewise 1, 1, 3 would be 3, and so on.

This is simple to do if few dice are rolled (between 1 and 4) just by taking into account all possibilities. (ie. If Die1 = Die2 AND Die1 + Die2 > Die3 Then...) but as the number of dice increase, the number of possibilites become to numerous to hand code, especially since I want to include up to 12 dice rolled.

Is there a simplere way to go about this?

Help Making A Dice Game Work (Easy Question)
I am creating a dice game for my visual basic final project. It is relatively simple and only requires an array, a counter or accumulator, and some other easy stuff (lol like an if...then statement). So I'm making the game and the code is skipping over a variable. It is like assigning it a value of 0 even though I am giving it a specific value in a text box.

edit--- the variable that seems to keep getting reset to 0 is 'intmoney2guess'. I have never had this problem, but it seems like whenever it gets passed through an if..then statement or a subprocedure it just seems to reset its value to 0. Is it possible that this is because of the text box somehow getting reset? normally, txtmoney2guess gets its value from user input, but when cmdRoll_click event is undergone, the text box resets to 0 all by itself...

Im so confuzzled


Code:
Option Explicit
Dim intmoney As String
Dim strguess As String
Dim lngindex As Long
Dim x(1 To 3) As Integer
Dim strtryagain As String
Dim intmoney2guess As Currency

Private Sub cmdLeave_Click()
Unload Me
End Sub

Private Sub cmdRoll_Click()

x(1) = Int((6 - 1 + 1) * Rnd + 1)
x(2) = Int((6 - 1 + 1) * Rnd + 1)
x(3) = Int((6 - 1 + 1) * Rnd + 1)

txtmoney2guess.Text = intmoney2guess

If intmoney2guess > intmoney Then
MsgBox "You cannot bet more money than you have!"
ElseIf intmoney2guess <= 0 Then
MsgBox "You must bet a positive amount of money!"
Else
If cboType = "Sequential" Then
Call Similar
ElseIf cboType = "3 in a row" Then
Call ThreeInARow
ElseIf cboType = "2 in a row" Then
Call TwoInARow
Else
MsgBox "Please enter one of the 3 options"
End If
End If
End Sub

Private Sub Form_Load()
Randomize

intmoney = 200
txtMoney.Text = intmoney

MsgBox "Good evening. Thank you for coming to our casino. You start with $200 and can start a new game whenever you run out of money."
MsgBox "Have fun!"

End Sub

Public Sub Similar()
lblNum(0).Caption = x(1)
lblNum(1).Caption = x(2)
lblNum(2).Caption = x(3)


If x(1) = x(2) And x(2) = x(3) Then
intmoney2guess = intmoney2guess * 5
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney + intmoney2guess
txtMoney.Text = intmoney
MsgBox "You hit the jackpot!!! You win " & intmoney2guess & " dollars!"
Else
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney - intmoney2guess
MsgBox "No Good. You lose " & intmoney2guess & " dollars. TOO BAD"
If intmoney <= 0 Then
Select Case MsgBox("Would you like to add more money?", vbYesNo)
Case vbYes
intmoney = intmoney + 200
MsgBox "You now have $200 more than you had before"
Case vbNo
MsgBox "Out of money? Well goodnight."
Unload Me
End Select
Else
End If
End If
txtmoney2guess.Text = intmoney2guess
End Sub

Public Sub ThreeInARow()
lblNum(0).Caption = x(1)
lblNum(1).Caption = x(2)
lblNum(2).Caption = x(3)

If x(2) = x(1) + 1 And x(3) = x(2) + 1 Then
intmoney2guess = intmoney2guess * 3
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney + intmoney2guess
txtMoney.Text = intmoney
MsgBox "You hit the jackpot!!! You win " & intmoney2guess & " dollars!"
Else
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney - intmoney2guess
MsgBox "No Good. You lose " & intmoney2guess & " dollars. TOO BAD"
If intmoney <= 0 Then
Select Case MsgBox("Would you like to add more money?", vbYesNo)
Case vbYes
intmoney = intmoney + 200
MsgBox "You now have $200 more than you had before"
Case vbNo
MsgBox "Out of money? Well goodnight."
Unload Me
End Select
Else
End If
End If
txtmoney2guess.Text = intmoney2guess
End Sub

Public Sub TwoInARow()
lblNum(0).Caption = x(1)
lblNum(1).Caption = x(2)
lblNum(2).Caption = x(3)


txtmoney2guess.Text = intmoney2guess

If x(2) = x(1) + 1 Or x(3) = x(2) + 1 Or x(2) = x(3) - 1 Or x(1) = x(2) - 1 Then
intmoney2guess = intmoney2guess * 2
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney + intmoney2guess
txtMoney.Text = intmoney
MsgBox "You hit the jackpot!!! You win " & intmoney2guess & " dollars!"
Else
txtmoney2guess.Text = intmoney2guess
intmoney = intmoney - intmoney2guess
MsgBox "No Good. You lose " & intmoney2guess & " dollars. TOO BAD"
If intmoney <= 0 Then
Select Case MsgBox("Would you like to add more money?", vbYesNo)
Case vbYes
intmoney = intmoney + 200
MsgBox "You now have $200 more than you had before"
Case vbNo
MsgBox "Out of money? Well goodnight."
Unload Me
End Select
Else
End If
End If
txtmoney2guess.Text = intmoney2guess
End Sub


NOTE --- I was messing with vbyesno options on message boxes. Bonus points if you can explain to me how they work or if I did them right!

Setting The Dice To Roll In The Direction Its Been Thrown Using The Cursor
I used these codes in a dice rolling game to pick the dice up using the cursor and roll it when let go:


Code:

Private Sub Dice1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
moveMe = True
End Sub

_________________________________________________________
Private Sub Dice1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If moveMe = True Then
Dice1.Top = Dice1.Top + Y
Dice1.Left = Dice1.Left + X
End If
End Sub

__________________________________________________________

Private Sub Dice1_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
moveMe = False
End Sub



and this simple code is used to "roll" the dice:



Code:
Private Sub Timer1_Timer()
Randomize
d1num = Int(Rnd * 6) + 1

If d1num = 1 Then
Dice1.Picture = LoadPicture("C:...Dice001.gif")
ElseIf d1num = 2 Then
Dice1.Picture = LoadPicture("C:...Dice002.gif")
ElseIf d1num = 3 Then
Dice1.Picture = LoadPicture("C:...Dice003.gif")
ElseIf d1num = 4 Then
Dice1.Picture = LoadPicture("C:...Dice004.gif")
ElseIf d1num = 5 Then
Dice1.Picture = LoadPicture("C:...Dice005.gif")
ElseIf d1num = 6 Then
Dice1.Picture = LoadPicture("C:...Dice006.gif")
End If

d1top = frmRollingDice.Dice1.Top
d1top = d1top - 5
End Sub


Is there a way to set the dice to move in the same direction that the user drag it and "throw" it using the cursor?

thnx in advance

Calculations On "rolling Window" Of Data
I have an array filled with numbers & would like to calculate and store the number of positive numbers that occur in a moving window of a given size, e.g., for elements 1..5, 2..6, 3..7, etc. through the end of the array (window size = 5).

Can someone help me find the most efficient way to code an operation like this?

Many thanks!

Help! "Rolling Doubles"
I have a test tomorrow, & my teacher gave us this practice application to do to prepare for it.. the instructions are:

"Create a Rolling Doubles application that displays in a list box the value of each die for every roll of a pair of dice until doubles are rolled. The number of rolls required to get doubles should also be displayed."

My program code also needs to include 2 dynamic integer variable arrays that each store die values, and AddItem procedure, a display procedure that displays the contents of each array with the same index seperated by a tab character in a list box.

Here's what I have so far:

Code:
Option Explicit

Private Sub cmdDone_Click()
Unload Me
End Sub

Private Sub cmdRoll_Click()
Dim intDie1Array() As Integer
Dim intDie2Array() As Integer
Dim intDie1 As Integer, intDie2 As Integer
Dim intCount1 As Integer, intCount2 As Integer

intDie1 = Int(Rnd * 6 + 1)
intDie2 = Int(Rnd * 6 + 1)

End Sub

Private Sub Form_Load()
Randomize
End Sub
Sub AddItem(ByRef intDie1Array() As Integer, ByRef intDie2Array() As Integer)


End Sub
Sub DisplayData(ByRef intDie1Array() As Integer, ByRef intDie2Array() As Integer)

End Sub
I'm pretty sure I'm supposed to use a For...Next statement, but I don't know what to put in it.. any help appreciated.

Copyright © 2005-08 www.BigResource.com, All rights reserved