Welcome To Gabriel's Online Casino!
We only have one game... Coin Toss! Place a bet on if the toss will be heads or tails.
Good Luck!
You have $3 to bet.
We only have one game... Coin Toss! Place a bet on if the toss will be heads or tails.
You have $3 to bet.
<?php
include('../includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>Welcome To Gabriel\'s Online Casino!</h1>');
echo('<p>We only have one game... Coin Toss! Place a bet on if the toss will be heads or tails.</p>');
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$wallet = isset($_POST['wallet']) ? $_POST['wallet'] : 3;
$bet = isset($_POST['bet']) ? $_POST['bet'] : 0;
$wager = isset($_POST['wager']) ? $_POST['wager'] : 0;
switch ($wallet) {
case ($wallet >= 2 && $wallet < 4):
echo('<H3>Good Luck!</h3>');
break;
case ($wallet >= 5):
echo('<H3>You\'re on a hot streak!</h3>');
break;
case ($wallet >= 1 && $wallet < 2):
echo('<H3>Looks Like you\'re in trouble!</h3>');
break;
case ($wallet = 0):
echo('<H3>Time to call it quits</h3>');
break;
default:
throw new \Exception('Unexpected value');
}
if ($step == 0)
{
echo("<p>You have $$wallet to bet.</p>\n ");
?>
<form action="decisiongame.php" method="POST">
<label for="name">Place Your Bet</label>
<label for="bet"></label><select name="bet" id="bet">
<option value="heads">Heads</option>
<option value="tails">Tails</option>
</select>
<br><br>
<label for="name">Wager</label>
<input type="number" size="3" name="wager" min="1" max="<?= $wallet ?>" required>
<br><br>
<input type="hidden" name="wallet" value="<?= $wallet ?>">
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Toss!">
</form>
<?php
} elseif ($step == 2) {
// Reset wallet if the user chooses "Try Again"
$wallet = 3;
echo("<p>Your wallet has been reset to $$wallet.</p>\n");
?>
<form action="decisiongame.php" method="POST">
<label for="bet">Place Your Bet</label>
<select name="bet" id="bet">
<option value="heads">Heads</option>
<option value="tails">Tails</option>
</select>
<br><br>
<label for="wager">Wager</label>
<input type="number" size="3" name="wager" min="1" max="<?= $wallet ?>" required>
<br><br>
<input type="hidden" name="wallet" value="<?= $wallet ?>"> <!-- Pass reset wallet -->
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Toss!">
</form>
}
<?php
} elseif ($step == 1) {
// Coin toss
$toss = rand(1, 2);
if ($toss == 1) {
$result = 'heads';
} else {
$result = 'tails';
}
echo("<p>The coin came up $result</p>");
if ($result == $bet)
{
$wallet += $wager;
echo('You Win!');
} else {
$wallet -= $wager;
echo('<p>The House Wins!</p>');
}
echo("<p>You now have $$wallet</p>\n");
?>
<form action="decisiongame.php" method="POST">
<input type="hidden" name="wallet" value="<?= $wallet ?>"> <!-- Pass updated wallet -->
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Play Again">
</form>
<form action="decisiongame.php" method="POST">
<input type="hidden" name="wallet" value="3"> <!-- Reset wallet to $3 -->
<input type="hidden" name="step" value="0"> <!-- Restart the game -->
<input type="submit" name="submit" value="Reset">
</form>
<?php
}
include('../includes/footer.php');
?>