Sign in to follow this  
Marz

Algorithm problem for slot machine

Recommended Posts

Hi I'm using VB6 to create a slot machine. So far it's working well but I have 1 small problem. The slot machine has nine boxes. It pays out if any 3 of these boxes rolls 7. I can't figure out how to check for this. if i use the following it keeps finding the same 7 over 3 times. for i = 0 to 8 if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then you win end if next i I am sure this is simple for you long time programers but for a newbie like me it's got me baffeled. I would greatly appreciate some insight. Please use layman's terms. thank you.

Share this post


Link to post
Share on other sites
Just count how many sevens you've got. Your code only tests for a single box being a 7 (if box i is a 7, then all 3 box(i).picture == imaage(7) are true!)

count = 0
for i = 0 to 8
if box(i).picture == imaage(7) Then count = count + 1
next i

if count >= 3 Then
you win
end if

Share this post


Link to post
Share on other sites
[edit] Good God you have fast typing skills Fruny [lol] And it's in VB code [sad]

Quote:
Original post by Marz
if i use the following it keeps finding the same 7 over 3 times.

for i = 0 to 8

if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then
you win
end if
next i


Right now this is what's happening:

You start by looping through from 0 - 8
for i = 0 to 8

Howeverm then you check to see if that box's image is 7, to which if it is, then you display that the player has won:
if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then you win

So if the first box is a 7, then:
box(i).picture == 7
box(i).picture == 7
box(i).picture == 7


You are checking the same index 3 times.

To solve this, what you need to do is something like this - I don't know VB that well so this is pseudo code:

ctr = 0
FOR i 0 to 8
if box(i).picture = imaage(7) Then
ctr = ctr + 1
end if
next i

if ctr > 0 then
you win


Instead you will keep track of the total number of 7's or in this case, just the fact the player rolled one.

Share this post


Link to post
Share on other sites
darn that does let me know when the player has turned up any 3 sevens but I also need to know where they are so I can light up the squares around them.

sorry darn I thought we had it.

Share this post


Link to post
Share on other sites
i would assume that all the pictures you are drawing have coordaninths (y wouldnt they) so all you have to do is

if box(i).picture == imaage(7) Then count = count + 1

then

box(i).picture = Light_Up_7Box.

i think this is what your asking (i dont know VB but hopefully you can inturpret what i mean

Share this post


Link to post
Share on other sites
Quote:
Original post by Marz
darn that does let me know when the player has turned up any 3 sevens but I also need to know where they are so I can light up the squares around them.

sorry darn I thought we had it.


If the current box is a 7, you need to increment the count and also light up that box - just do that in one step:


for i = 0 to 8

if box(i).picture == imaage(7) Then
count = count + 1
box(i).picture = 'fill in whatever image index here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this