Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

HTML & PHP - Lucky 7 - a simple game

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Maveric (27 Jun 2012)
Last edited: BuildNokia (12 Jun 2014)

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.

This page was last modified on 12 June 2014, at 23:29.
393 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×