BlackJack Assignment
BlackJack Assignment
php
session_start(); // Start the session to track money and hand across requests
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
if (!isset($_SESSION['dealer'])) {
$_SESSION['dealer'] = rand(14, 21);
}
$money = $_SESSION['money']; // Get the current money value from the session
$deck = [
"2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC", "AC",
"2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD", "AD",
"2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH", "AH",
"2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS", "AS"
];
// Check if the bet is a valid numeric value and if the user has enough money
if (is_numeric($bet) && $bet > 0) {
if ($bet <= $money) {
$session['money'] -= $bet; // Subtract bet from money
$session['bet_placed'] = $bet; // Store the bet in the session
$session['bet_ready'] = 1; // Mark the bet as placed
} elseif ($money == 0) {
echo "You lost.<br>";
$session['money'] = 100; // Reset money if lost
} else {
echo "You don't have enough money to place this bet.<br>";
}
}
}
}
?>
</body>
</html>