Dayo Posted June 7, 2013 Posted June 7, 2013 (edited) I had a bit of time spare today so decided to make a simple hi/lo game, it only took 30 odd mins and most of that was the bloody css :P. It uses HTML/CSS + PHP. All data is stored in sessins but can be alreded for databases. <?php session_start(); $guess = $_GET['guess']; $new = mt_rand(1, 13); if (!empty($guess)) { $old = $_SESSION['card']; if (($guess == 'hi' && $old <= $new) || ($guess == 'lo' && $old >= $new)) { $_SESSION['score']=$_SESSION['score']+1; if ($_SESSION['score']>$_SESSION['hiscore']) { $_SESSION['hiscore']=$_SESSION['hiscore']+1; } $new_card = '<div style="color:#009900">You were correct!</div><div class="card n'.$new.' s'.mt_rand(1, 4).'"></div>'; } else { $_SESSION['score'] = 0; $new_card = '<div style="color:#900">You were incorrect!</div><div class="card n'.$new.' s'.mt_rand(1, 4).'"></div>'; } $_SESSION['card'] = $new; } else { $_SESSION['score'] = 0; $new_card = '<div class="card n'.$new.' s'.mt_rand(1, 4).'"></div>'; $_SESSION['card'] = $new; } ?> <html> <head> </head> <body> <style> .card { height:97px; width:72px; background:url("cards.png"); margin-bottom:10px; margin-right:10px; float:left; } .n1 {background-position-x:0px;} .n13 {background-position-x:74px;} .n12 {background-position-x:147px;} .n11 {background-position-x:220px;} .n10 {background-position-x:293px;} .n9 {background-position-x:366px;} .n8 {background-position-x:439px;} .n7 {background-position-x:512px;} .n6 {background-position-x:585px;} .n5 {background-position-x:658px;} .n4 {background-position-x:731px;} .n3 {background-position-x:804px;} .n2 {background-position-x:877px;} .s1 {background-position-y:0px;} .s2 {background-position-y:98px;} .s3 {background-position-y:196px;} .s4 {background-position-y:291ps;} </style> <?php echo $new_card; ?> Your score: <?php echo $_SESSION['score']; ?><br /> Your hi-score: <?php echo $_SESSION['hiscore']; ?><br /> <form method="get" action =""> <input type = "submit" name="guess" value = "hi" /> <input type = "submit" name="guess" value = "lo" /> </form> </body> </html> I used the image from http://www.mickybullock.com/blog/wp-content/uploads/2009/09/classic-playing-cards.png just save it as cards.png in the same directory as this file r change the CSS. Ace is classed as low if you want Ace to be the highest change the css class .n1 to .n14 then chnage $new = mt_rand(1, 13); to $new = mt_rand(2, 14); Edited June 7, 2013 by Dayo Quote
KyleMassacre Posted June 7, 2013 Posted June 7, 2013 looks a lot better than the one I made while I was bored a long time ago haha. Quote
Dayo Posted June 7, 2013 Author Posted June 7, 2013 if i get more time today ill implement JQuery so you dont have to keep doing page loads Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.