Jump to content

Is it possible to make a slot machine?


Molarmite

Recommended Posts

I'm looking to make a slot machine with php.  I have a general script but it's only one line and all text.  I would like to know if it's possible to get pictures associated with each variable, and possibly see them spinning like a real slot machine or would that last part require flash? 

 

I'm just curious if it's possible to build a good looking slot machine before I advance any farther.  My MSN is [email protected], my AIM is juicebox3313, either post here or it would be easier to send me a message on either one of those if you want to help.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/165321-is-it-possible-to-make-a-slot-machine/
Share on other sites

I'm not the most experienced at this, I don't mind reading a few articles to get this done.  The main thing I'm wondering is, does this sound like something complicated?  Hopefully it's something I can do as a beginner.

<?php

/*


*/

$faces = array ('Cherry', 'Bar', 'Double Bar', 'Triple Bar', 'Diamond', 'Seven');

$payouts = array (
    'Bar|Bar|Bar' => '5',
    'Double Bar|Double Bar|Double Bar' => '10',
    'Triple Bar|Triple Bar|Triple Bar' => '15',
    

'Cherry|Cherry|Cherry' => '20',
    'Seven|Seven|Seven' => '70',
    'Diamond|Diamond|Diamond' => '100',
);




$wheel1 = array();
foreach ($faces as $face) 
{
       $wheel1[] = $face;
}
$wheel2 = array_reverse($wheel1);

$wheel3 = $wheel1;


if (isset($_POST['payline'])) 
{
    list($start1, $start2, $start3) = unserialize($_POST['payline']);
} 

else {
    list($start1, $start2, $start3) = array(0,0,0);
}



$stop1 = rand(count($wheel1)+$start1, 10*count($wheel1)) % count($wheel1);

$stop2 = rand(count($wheel1)+$start2, 10*count($wheel1)) % count($wheel1);

$stop3 = rand(count($wheel1)+$start3, 10*count($wheel1)) % count($wheel1);



$result1 = $wheel1[$stop1];

$result2 = $wheel2[$stop2];

$result3 = $wheel3[$stop3];



echo "Result: " . $result1 . ' ' . $result2 . ' ' . $result3 . "<br />";



if (isset($payouts[$result1.'|'.$result2.'|'.$result3])) 

{
    // give the payout
    echo "You won : " . $payouts[$result1.'|'.$result2.'|'.$result3];
}
?>

<br />

<form method='post'>
<input type='hidden' name='payline' value='<?php echo serialize(array($stop1, $stop2, $stop3)) ?>' 

/>
<input type='submit' value='spin the wheel' />
</form>

 

This is what I got so far.  Let me know if it gets more complicated than this or not.

My skill level is bare minimum.  I know general stuff like how to make variables, if/else statements, echo statements, mostly just basic stuff like that.  I know that I'll have some reading to do, but it would be nice to know ahead of time how much I will need to know.

You can just integrate the images with a simple html-based echo within your php, that would be by far the easiest. However, for a smooth alternative I'd use a javascript/ajax system. Also you may want to consider preloading all images or else it'll take too long to load them all.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.