PHP Classes

File: usage.php

Recommend this page to a friend!
  Classes of Ali Sami  >  PHP Blackjack Simulator  >  usage.php  >  Download  
File: usage.php
Role: Example script
Content type: text/plain
Description: Usage of the class
Class: PHP Blackjack Simulator
Simulate a Blackjack game with one player
Author: By
Last change:
Date: 8 years ago
Size: 1,303 bytes
 

Contents

Class file image Download
<?php
   
require 'class.blackjack.php';
   
session_start();
   
   
$action = 'new';
    if(isset(
$_GET['action'])) $action = $_GET['action'];
   
    if(
$action == 'new') {
       
$_SESSION['game'] = new Blackjack();
       
$_SESSION['game']->addCard('Player');
       
$_SESSION['game']->addCard('Bank');
    }
   
    if(
$action == 'hit') {
        if(
$_SESSION['game']->Scores['Player'] < 21) {
           
$_SESSION['game']->addCard('Player', 1);
            if(
$_SESSION['game']->Scores['Player'] > 21) $_SESSION['game']->playBank();
        }
    }
   
    if(
$action == 'stand') {
       
$_SESSION['game']->playBank();
    }
   
    echo
"Player Cards:<br>";
    foreach(
$_SESSION['game']->Cards['Player'] as $card)
        echo
"<img src='cards/{$card['Suit'][0]}{$card['Face']}.png'>";
    echo
"<br>Player Score: ".$_SESSION['game']->Scores['Player'];
   
    echo
"<br><br>Bank Cards:<br>";
    foreach(
$_SESSION['game']->Cards['Bank'] as $card)
        echo
"<img src='cards/{$card['Suit'][0]}{$card['Face']}.png'>";
    echo
"<br>Bank Score: ".$_SESSION['game']->Scores['Bank'];
   
   
// Options
   
if($_SESSION['game']->Scores['Player'] < 21) echo "<br><a href='?action=hit'>[Hit]</a>";
    echo
"<br><a href='?action=stand'>[Stand]</a><br><a href='?action=new'>[New]</a>";
   
    if(
$_SESSION['game']->GameEnd == 1)
    echo
"<br>Game Result: ".$_SESSION['game']->getResult();
?>

For more information send a message to info at phpclasses dot org.