Login   Register  
PHP Classes
elePHPant
Icontem

File: usage.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2013-12-03 09:18
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();
?>