access slot machine algorithm

woknick

Registered User.
Local time
Today, 00:42
Joined
Sep 25, 2004
Messages
85
I am building a slot machine game in access. So far i have a semi functional game. When you click on the spin button, 3 slots spin and display random images. My question is I need to write an algorithm or some sort of loop to determine the winning combinations. Below are the winning combinations. Each number corresponds to a pic, and each group of three numbers equal a different amount of winnings.

111
222
333
444
555
666

113 131 311
223 232 322
443 434 344
553 535 355
663 636 366

The number 3 is a wild card

How do I go about checking if the slot produces a win or not.

Thanks in advance..

Nick
Ill post the final game when it is finished..
 
after update of each textbox:



dim winningstring as string

winningstring = trim(str(me.textbox1.value) & str(me.textbox2.value) &
str(me.textbox2.value))

if winningstring = 111 or winningstring = 333 etc
then msgbox "won"
 
is there a way i could use arrays? The problem im having is that each wheel has a random number associated to it and that number displays the picture. I need to take all 3 numbers and put them together to form a one by three.

here is some of my code for one wheel and one pic

Dim MRandomNumber As Integer
MRandomNumber = Int((6 - 1 + 1) * Rnd + 1)

If (MRandomNumber = 1) Then
safe2.Visible = True

Else
End If
 
I'm a little confused about all the words of threes and ones I am seeing, so I dont understand what you are trying to do.

If you could send me your program, please.
 
Let me explain. When you spin the slot machine a random number is created for each wheel. those random numbers repersent a picture. So if I click on spin the result would be 3 numbers, for example 3 1 2, where the 3 is the left most wheel, the 1 is the middle wheel and the 2 is the right most wheel. What im trying to develop is a way to decide based on the three number sequence if it is a winning combonation or not.
 
There is no easy way to do this. A few tedious ways, yes. Easy, no.

The most DIRECT way is to write some code that runs after your spin is finished. In it, find a way to represent the spin as an integer, perhaps by concatenating the individual digits to form a number from 111 through 666 and all possible combinations in between.

Then in the code, write a case statement based on your integer.

Select funky-number
Case 111: winner
Case 222: winner
Case 311: winner
Case 322: winner
...
case else loser
end select

(or whatever is the correct syntax; I'm shooting from the hip here and have been writing in Ada recently...)

The other way to do that is to build a winning combinations table and do an outer join of the spin code to that table. If you get back anything but nulls in the fields that come from the winning-combo table, you have a winner. If you get a null, it is a loser.
 
Could I create a 1 by 3 array and then use that array and compare it to the winning combinations 1 by 3 arrays? If so how would I go about doing that?
 
If your concern is how to associate the photos with the winning number combination, I would probably have a table with two fields, NumberSpin as Integer and Link as String,

your photo files must be in the link as stated in the field.

OR you can take a look at the Categories table/form if you do not want to use a link but a direct image. - Create a field ole object, then double click on the field to put the image directly to the table.


From then you can use the recordset to look into the values, or whatever.

Heres a sample.

Of course you can use an array too.

two arrays, one for the integer, one for the photo. if the index is the same, then refresh form with the photo array.

But why bother with array when you can use the table/recordset.
 

Attachments

My problem is determining the winning combinations. I have the picture animation already functional.

Ok my program outputs three numbers, lets say 342, There is a list of numbers and this list determins if the output numbers is a winner.

sample list

334
314
346
456
342

So the program needs to take the output numbers and compare them to the list. If it is in the list, then it is a winning combination..
 
Assuming the list is in a table along with the value of the "winnings" associated with each, a simple DLookup() or recordset can check the output against that table to determine if it's a winner (and if so, how much).
 
Option Compare Database
Dim Num1 As Integer, Num2 As Integer, Num3 As Integer
Dim CompareStringtoArray As String, WINarray(6) As String

Sub DECLAREARRAY()

WINarray(1) = "334"
WINarray(2) = "314"
WINarray(3) = "346"
WINarray(4) = "456"
WINarray(5) = "342"


End Sub







Sub GETThreeStrings()

Num1 = Nz(Me.Text1.Value, 0)
Num2 = Nz(Me.Text2.Value, 0)
Num3 = Nz(Me.Text3.Value, 0)

CompareStringtoArray = Trim(Str(Num1)) & Trim(Str(Num2)) & Trim(Str(Num3))
MsgBox CompareStringtoArray
End Sub

Private Sub Command0_Click()
DECLAREARRAY

Dim x As Integer, ThereisAMatch As Boolean

ThereisAMatch = False

GETThreeStrings

For x = 1 To 5
If WINarray(x) = CompareStringtoArray Then
ThereisAMatch = True
Exit for
End If
Next x

If ThereisAMatch = True Then MsgBox "You WON" Else MsgBox "TRY AGAIN"
End Sub
 
Last edited:
Slot Machine

How are you going to handle 'Nudges' and 'Holds'?
 

Users who are viewing this thread

Back
Top Bottom