Page 1 of 1

slot game, lines and prizes

PostPosted: Fri Jun 10, 2011 8:24 pm
by sportmaster
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.

Re: slot game, lines and prizes

PostPosted: Sat Jun 11, 2011 10:03 am
by skydereign
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.

Re: slot game, lines and prizes

PostPosted: Sat Jun 11, 2011 10:39 am
by noonenew
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.

Re: slot game, lines and prizes

PostPosted: Sat Jun 11, 2011 5:07 pm
by sportmaster
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 :)

Re: slot game, lines and prizes

PostPosted: Sat Jun 11, 2011 5:22 pm
by sportmaster
...and how can I change the values of prizes ?

Re: slot game, lines and prizes

PostPosted: Sat Jun 11, 2011 10:35 pm
by skydereign
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;
    }
}

Re: slot game, lines and prizes

PostPosted: Sun Jun 12, 2011 6:55 pm
by sportmaster
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?

Re: slot game, lines and prizes

PostPosted: Mon Jun 13, 2011 12:09 am
by skydereign
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).

Re: slot game, lines and prizes

PostPosted: Mon Jun 13, 2011 12:18 pm
by sportmaster
excellent effect ! I'm very grateful :D

Re: slot game, lines and prizes

PostPosted: Mon Jun 13, 2011 1:35 pm
by sportmaster
another question to you L : what and where will be the changes if I'll add one more sign ??

Re: slot game, lines and prizes

PostPosted: Mon Jun 13, 2011 5:59 pm
by skydereign
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;
    }
}

Re: slot game, lines and prizes

PostPosted: Mon Jun 13, 2011 8:16 pm
by sportmaster
it's working, i'm very happy :D