slot game, lines and prizes

Non-platform specific questions.

slot game, lines and prizes

Postby sportmaster » Fri Jun 10, 2011 8:24 pm

When space is pressed the clons have random animpos. I'm requesting for simple code to count the prizes for horizontal and cross lines. hand 10 bells 20 islands 50.
Attachments
slots.jpg
slots.jpg (10.39 KiB) Viewed 2908 times
slotsy.rar
(201.03 KiB) Downloaded 145 times
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby skydereign » Sat Jun 11, 2011 10:03 am

I didn't answer this before because I don't know what you mean by simple code. Simple as in easy to understand, uses basic programming knowledge, or is short? It'd be easier if you had an array, but you can just use getclone functions. Also, what do you mean cross lines? Just horizontal and vertical? Or horizontal and diagonal? Or all three?

-Edit
Well, I'd say this is pretty simple, short, and more or less easy to understand (perhaps a bit tricky but should be understandable). I used an array to represent the board, and actor variables to determine row and col in the array. Put the ged with your data folder to run it.
Attachments
slots.ged
(3.99 KiB) Downloaded 133 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: slot game, lines and prizes

Postby noonenew » Sat Jun 11, 2011 10:39 am

woot very nice. id say its pretty understandable. when i saw this i was thinking youd have to use for loops to check the array but since the size is only 3 this method is far nicer looking.
noonenew
 
Posts: 11
Joined: Sun Nov 14, 2010 11:12 am
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Sat Jun 11, 2011 5:07 pm

when i was writing "simple code" i was thinking about short advanced code and there it is. I see game counts all lines it's fine but what will be the difference when we get rid of vertical lines? It's hard for me to understand all so I don't know what should I change to have prizes only for horizotal and diagonal lines. I need L's explanations :)
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Sat Jun 11, 2011 5:22 pm

...and how can I change the values of prizes ?
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby skydereign » Sat Jun 11, 2011 10:35 pm

If you want an explanation of the code to understand what it is doing (and perhaps be able to change it to how you want) read this, otherwise jump to the bottom code and replace the keyup space event with that.
Okay, well there are 8 possible ways of getting points. 3 horizontal, 3 vertical, and 2 diagonal. You get points if all three in the check work, so if the first square and second square are equal, and the first square and third square are equal.
Code: Select all
(slots[0][0]==slots[0][1] && slots[0][0]==slots[0][2])


That code will return 1 if they are all the same, otherwise zero. But we want to record what type of prize you get, assuming that statement returns a 1. So, multiply it by the type in the value of the square (that way if it is zero it is still zero, but if not each type is different).

Then you go through a for loop that determines what points to give you. To change how much each match gives, just change the values in the bottom code. So if you want the island to give you 100, switch the 50.
Code: Select all
for(i=0;i<8;i++)
{
    switch(prizes[i])
    {
        case 0: // nothing
        break;
 
        case 1: // island
        score+=50;
        break;
 
        case 2: // bell
        score+=20;
        break;
 
        case 3: // hand
        score+=10;
        break;
    }
}




This is the changed code. To change the values of the prizes, change the 50, 20, and/or 10.
Code: Select all
int i;
int prizes[5];

//horizontal
prizes[0]=(slots[0][0]==slots[0][1] && slots[0][0]==slots[0][2])*slots[0][0];
prizes[1]=(slots[1][0]==slots[1][1] && slots[1][0]==slots[1][2])*slots[1][0];
prizes[2]=(slots[2][0]==slots[2][1] && slots[2][0]==slots[2][2])*slots[2][0];

//diagonal
prizes[3]=(slots[0][0]==slots[1][1] && slots[0][0]==slots[2][2])*slots[0][0];
prizes[4]=(slots[2][0]==slots[1][1] && slots[2][0]==slots[0][2])*slots[2][0];

for(i=0;i<5;i++)
{
    switch(prizes[i])
    {
        case 0: // nothing
        break;
 
        case 1: // island
        score+=50;
        break;
 
        case 2: // bell
        score+=20;
        break;
 
        case 3: // hand
        score+=10;
        break;
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Sun Jun 12, 2011 6:55 pm

ok I have own values. looks like you mixed up lines horizontal and vertical nevermind I guessed that without code about horizotal lines there is no vertical ok a have what I want. Now I'd like to have an flashing effect of winning lines. what should i do ? I have an idea :
don't draw , create timer "appear" 100msec
timer "appear" : visibly state enable , create timer "disappear" 100msec
timer "disappear" : don't draw , create timer "appear"
but where i have to put this loop or should i make this effect in another way?
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby skydereign » Mon Jun 13, 2011 12:09 am

Yeah, sorry about that, my comments were off. Try this, it has them flash when they are in line. When it finds a match, it sets an actor variable state which causes them to flash (in their draw event).
Attachments
slots.ged
(4.99 KiB) Downloaded 141 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Mon Jun 13, 2011 12:18 pm

excellent effect ! I'm very grateful :D
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Mon Jun 13, 2011 1:35 pm

another question to you L : what and where will be the changes if I'll add one more sign ??
Attachments
slot4.png
slot4.png (7.77 KiB) Viewed 2816 times
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score

Re: slot game, lines and prizes

Postby skydereign » Mon Jun 13, 2011 5:59 pm

Of course add the frame to your animation. You would also have to change the rand statement in the keydown space. I'd suggest switching this...
Code: Select all
animpos=rand(3);

With this.
Code: Select all
animpos=rand(nframes);


Then in the keyup event for the view, you need to add a case statement for the new image. So like this.
Code: Select all
for(i=0;i<5;i++)
{
    switch(prizes[i])
    {
        case 0: // nothing
        break;
 
        case 1: // island
        score+=50;
        break;
 
        case 2: // bell
        score+=20;
        break;
 
        case 3: // hand
        score+=10;
        break;

       case 4: // new
       score+=5; // or whatever you want it to be
       break;
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: slot game, lines and prizes

Postby sportmaster » Mon Jun 13, 2011 8:16 pm

it's working, i'm very happy :D
User avatar
sportmaster
 
Posts: 32
Joined: Thu Jun 25, 2009 8:29 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest