Fairly useless slots game. hehe. can be used on any named webpage, the script will retrieve the name and re-direct blaaa. not much to it really. i was learning functions, and came up with it :P
Example: http://wfs.myartsonline.com/function/
<?php
// PHP Slots Script by Jonesy44 //
// http://www.hawkee.com //
session_start();
echo '<style>
#slots {
border: 1px solid green;
background: lightgreen url(\'slots.jpg\');
padding: 10px;
width: 200px;
text-align:left;
}
#gborder {
border: 1px solid green;
background: lightgreen;
padding: 10px;
width: 200px;
text-align:center;
}
#rborder {
border: 1px solid red;
background: pink;
padding: 10px;
width: 200px;
text-align:center;
}
#border {
border: 1px solid orange;
background: white;
padding: 10px;
width: 200px;
text-align:center;
}
</style>';
function playSlots() {
$r1 = rand(0,9);
$r2 = rand(0,9);
$r3 = rand(0,9);
echo '<div id="slots"><h1> ' .$r1. ' ' .$r2. ' ' .$r3. '</h1></div>';
if ($r1 == $r2) {
if ($r2 == $r3) {
echo '<div id="gborder">Complete win!<br><b> + $2000</b></div>';
$_SESSION["slots"] = $_SESSION["slots"] + 2000;
}
else {
echo '<div id="gborder">First two!<br><b> + $250</b></div>';
$_SESSION["slots"] = $_SESSION["slots"] + 250;
}
}
elseif ($r2 == $r3) {
if ($r1 != $r2) {
echo '<div id="gborder">Second two!<br><b> + $250</b></div>';
$_SESSION["slots"] = $_SESSION["slots"] + 250;
}
}
elseif ($r1 == $r3) {
echo '<div id="gborder">First and last!<br><b> + $250</b></div>';
$_SESSION["slots"] = $_SESSION["slots"] + 250;
}
else {
echo '<div id="rborder">You Lose!<br><i> - $100</i></div>';
$_SESSION["slots"] = $_SESSION["slots"] - 100;
}
}
if ($_GET["play"]) {
if (!isset($_SESSION["slots"])) {
$_SESSION["slots"] = 1000;
}
echo '<center>';
playSlots();
echo '<br><form action=' .$_SERVER['PHP_SELF']. ' method=get>';
echo '<input type=hidden name=play value=slots>
<input type=submit value="Spin Wheels!">
</form>';
}
else {
echo '<form action=' .$_SERVER['PHP_SELF']. ' method=get>';
echo '<input type=hidden name=play value=slots>
<input type=submit value="Play Slots!">
</form>';
exit();
}
echo '<div id="border">Cash: $' .$_SESSION["slots"]. '<hr><a href=http://wfs.myartsonline.com><i>PHP Slots Script By Jonesy44</a> - <a href=http://www.hawkee.com>Hawkee.com</a><hr></div>';
echo '</center>';
?>
This would be neat as an OpenSocial app. You can run it through our Hawkee container to come up with a high score rank with your friends. Here is an example, http://www.hawkee.com/snippet/4818/ - Just create an XML document containing your code and paste the URL into the Test Script box. You can even store the scores on our database.
haha, not at all. I\'m hopin to code an arcade style thing soon, so it will have a login system and all. :P
im looking into to seeing if i can actually grab a completely unique ident for a computer, like a mac address or something. im no genius as server side stuff, apart from i can do some php/sql xD
Yeah, addicting it is, especially with other users to go up against :P Also a short time ago I got an error on the webpage it is on. A whole lot of warning going down the screen and it hasn\'t cleared up yet. It\'s been that way for about 10 minutes or more now. I don\'t know if you are resetting or not, but figured it was worth mentioning.
thanks, i see you\'ve been winning a bit too hehe ! ti\'s addictive. but my server maxxes out at 1,500 connections / hour. so it\'ll reset on the hour. your score is saved :P
im looking into sorting that problem. and when i do, i wil update the script on here. which now runs soeley on sql, rather than the sessions you see here.
hmmkay. also. i\'ve added an sql db to record scores;
function slotsScores() {
$pos = 1;
$ip = ($_SERVER[\'HTTP_X_FORWARDED_FOR\'])
? $_SERVER[\'HTTP_X_FORWARDED_FOR\']
: $_SERVER[\'REMOTE_ADDR\'];
$sql = mysql_query(\"SELECT * FROM `slots` ORDER BY `cash` DESC\");
while ($c = mysql_fetch_array($sql)) {
if ($c[\"ip\"] == $ip) {
echo \'<b>@ \';
}
echo $pos. \' - $\' .$c[\"cash\"]. \'</b><br>\';
$pos = $pos + 1;
}
}
however;
Top Scores;
1 - $8100
2 - $4750
3 - $300
@ 4 - $10800
it orders correctly, apart from my score :s
The numbers don\'t line up properly for me. They\'re kinda all over the place. You should just do something like:
<div style=\"float: left;\">number 1</div>
<div style=\"float: left;\">number 2</div>
<div style=\"float: left;\">number 3</div>
<div style=\"clear: left;\"></div>
Maybe add some padding-right to each of the div\'s to space things out evenly.
Now if you really wanted to take this up a notch you could use AJAX and only refresh the reels upon spinning, not the entire page. In fact you should try this as an Opensocial snippet.