HTML & PHP - Lucky 7 - a simple game
Article Metadata
This article explains how to create a simple game of Lucky 7 with HTML and embedded PHP
Contents |
Introduction
In this example we will create a simplified version of a popular casino game called Lucky 7. You could easily extend it to conform the other gaming options of that device and even add "virtual money" to be consumed.
Prerequisites
- A web browser
- PHP installed
Implementation
We will only need to implement one HTML file, you could name it e.g. index.html, or whatever you wish. The required PHP code is embedded in the HTML page.
Example code
<?PHP
$game_message = "Example game of Lucky 7 - Hit ROLL!";
if (isset($_POST['submit']))
{
$slot1 = rand(1, 10);
$slot2 = rand(1, 10);
$slot3 = rand(1, 10);
if($slot1 == 7 || $slot2 == 7 || $slot3 == 7)
{
$game_message = "YOU WIN!";
}
else
{
$game_message = "YOU LOSE!";
}
}
$slot1 = "?";
$slot2 = "?";
$slot3 = "?";
}
?>
<html>
<body>
<center>
<h2>Game of Lucky 7 - simple version</h2>
<form method="POST" Action=""><?PHP echo $_SERVER['PHP_SELF'];?">
<table border="1">
<tr>
<td width="15" align="center"><?PHP echo $slot1; ?></td>
<td width="15" align="center"><?PHP echo $slot2; ?></td>
<td width="15" align="center"><?PHP echo $slot3; ?></td>
</tr>
</table>
<input type="submit" value="Roll" name="submit">
</form>
<?PHP echo $game_message; ?>
</center>
</body>
</html>
Tested on
Google Chrome 19.0.1084.52 m
Summary
Feel free to add some "virtual money" betting and posible other winning options to create an interesting past-time for your webpage.


(no comments yet)