Jump to content

Recommended Posts

I am working on a final project for my PHP class and I am stuck solving a few key points, and could greatly use some advice and suggestions.  The points I am stuck getting to work correctly are as follows.  Pressing the "Play Button" deducts one credit.  Award 20 credits and display the message if two random numbers match.  We have a winner.  Award 200 credits and display a similar message as before.  Use Javascript and PHP to reset the machine credits and return to the welcome page if not used for 15 seconds.  And lastly the machine needs to keep a running total of credits.  Below is my code up to this point.  Thank you. 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

 

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Cha Ching</title>

    </head>

<body>

<?php // Script slotmachine1.php

 

ini_set ('display_errors', 1);

error_reporting (E_ALL & ~E_NOTICE);

 

if ($GET['ready'] == 'true')// Make sure the user actually hits "Play"

        if($_GET['credits'] > 0) //Ensure user has credits to play

          $credits = $_GET['credits'];

 

$n1 = mt_rand(0, 9);

$n2 = mt_rand(0, 9);

$n3 = mt_rand(0, 9);

//Print out the numbers to show your lucky numbers.

print "Your lucky numbers are the following:<br />

<pre>$n1 $n2 $n3</pre>";

 

?>

<div id="control">

  <form action="slotmachine1.php" method="get" id="lever">

  <div id="betSelector">

 

  <p id="money"> Bank:  </p>

 

  <p id="bet"> Your bet:

 

<select name="machine">

   

  <option>25 </option>

  <option>50 </option>

  <option>100 </option>

  <option>200 </option>

  </select><br><br> <?php 

  $bet = 15;

  if(is_numeric($bet) < 15) {

 

    } else {

    // $bet = 15;

 

}$okay = FALSE

   

 

?>

  </p>

 

  </div> <!-- bet selector -->

 

<div id="spin">

<button class="spin" type="submit" name="spin">SPIN</button>

</div>

<p>

<input type="hidden" name="bank"  value="10"  />

<input type="hidden" name="bet"    value="25"  />

<input type="hidden" name="one"    value="50"  />

<input type="hidden" name="two"    value="100"  />

<input type="hidden" name="three"  value="200"  />

</p>

 

  </form>

 

 

  </div> <!-- control -->

 

<div id="messages">

 

<!-- THE BANK -->

    <!-- bank has 10 ,

  fmt_money($bank) gives $10 -->

 

<?php

$n1 = array (0, 9);

$n2 = array (0, 9);

$n3 = array (0, 9);

 

$one=$slots[$n1];

$two=$slots[$n2];

$three=$slots[$n3];

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

// give the payout

}

 

print ("Congratulations, you won!");

}

else { print("Try Again");

}

 

$test = array(2,3,4);

$var1 = 2;

$var2 = 2;

$var3 = 3;

if (count(array_diff(array($var1,$var2,$var3),$test)) == 0){

echo 'OK';

} else {

echo 'NOT';

}

 

      if ($n1 == $n2 == $n3)

  {

      $credits += 100;

print("Congratulations, you won 100 Credits!"); 

elseif ($n1 == $n2 OR $n2 == $n3 OR $n1 == $n3){ // Make sure to check for $n1 matching $n3!!

{

  $credits += 10;

  print("Big Winner! Here's 100 credits!");            }

else {

print("Sorry! Try Again!");

}

  Subtract credits for playing

  $credits -= 1;

    else {  //The player doesn't have any credits to play

    print ("You don't have any credits left to play with!");

}

  } else { // The user hasn't played yet, give the player 25 credits //

      $credits = 25;

  }

?></p>   

 

</div> <!-- messages -->   

   

    <!-- MACHINE TYPE -->

    <div id="walkAway">

  <form action="slotmachine1.php" method="get" id="machines">

  <p>

You have<input type='text name='credits'  value='<? print($credits); ?>'>

</p>

<p>

<input type="submit" value='PLAY!'>

<input type='hidden' name='player' value='<? print($GET['name']);?>'>

<input type='hidden' name='ready'  value='true'>

</p>

 

    </form>

   

<!-- This is an HTML comment. -->

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/156359-slotmachine-project/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.