Äventyrsspel | Visa källkod | XHTML | CSS | How to become a hacker | Hangman | Tärning | HighLow | Sök Kompis

Visa källkod

Nedanstående filer finns i denna katalogen. Klicka på en fil för att visa dess innehåll.

adventure08/highlow

CCard.php
CCardHand.php
CDeck.php
CHighCardLowCard.php
ISessionDestroy.php
card.php
common.php
deck.php
hand.php
highlow.php
session.php
source.php
template.php

highlow.php
<?php
// ===========================================================================================
//
// highlow.php
//
// Description: My testprogram for my class implementing the card game "High Card Low Card".
// Used to show off that it works as expected.
//
//
// Author: Mikael Roos
//


// -------------------------------------------------------------------------------------------
//
// Error handling on/off
//
error_reporting(E_ALL | E_STRICT);
$debug = "";
$debugEnable = TRUE;  // TRUE to enable debugging, FALSE to not print out debug information


// -------------------------------------------------------------------------------------------
//
// Prepare the page content
//
$html = "";

// Include class definitions
require_once('CHighCardLowCard.php');

// Load class definitions before calling session_start
session_start();


// -------------------------------------------------------------------------------------------
//
// Take care of GET variables
//
$doGame    = (empty($_GET['game']) ? FALSE : $_GET['game']);
$gameOver = FALSE;

switch($doGame) {
    case 'init': { // Destroy and then initiate the session
        //require('ISessionDestroy.php');
        //
        // Initiating a session and storing an object in the session variable
        //
        // http://php.net/manual/en/function.session-start.php
        // http://php.net/manual/en/function.session-regenerate-id.php
        //
        //session_start();          // Must call again if we just destroyed
                                     // the session.
        //session_regenerate_id();  // To avoid problems

        $_SESSION['game']   = new CHighCardLowCard();
        $_SESSION['game']->StartGame();

        $debug .= 'Game initiated.';
        $debug .= 'Current session id is: ' . session_id() . '<br />';
    }
    break;

    case 'high':
    case 'low':   { // Guess next card is high/low card
        if($_SESSION['game']->GuessAndPickCard($doGame) == FALSE) {
            $gameOver = TRUE;
        }

        $debug .= 'Made a guess. <br />';
    }
    break;

/*    
    case 'destroy': { // Only destroy the session
        require('ISessionDestroy.php');
        $debug .= 'Session destroyed.';
        $debug .= 'Current session id is: ' . session_id() . '<br />';
    }
    break;
*/
    
    default: 
    break;
}


// -------------------------------------------------------------------------------------------
//
// Play the CHighCardLowCard-class
//
//
$htmlGame = "";
if(isset($_SESSION['game'])) {

    $htmlGame .= $_SESSION['game']->ShowGameStatus();
    
    if($gameOver) {
        $points = $_SESSION['game']->GetPoints();
        $_SESSION['game']->StartGame();
        $htmlGame .= "<p>Game over. Du lyckades med {$points} kort.</p>";
        
        if($points >= 3) {
            $htmlGame .= "<p>GRATTIS, du har låst upp den hemliga passagen. ";
            $htmlGame .= "<a href='../room.php?id=13'>Gå vidare via den hemliga passagen!</a></p>";
        }
    } else {
        $htmlGame .= <<<EOD
<p>
<a href='highlow.php?game=high'>Nästa kort är högre...</a><br/>
<a href='highlow.php?game=low'>Nästa kort är lägre...</a>
</p>
EOD;
    }
}    

$debug .= 'Current session id is: ' . session_id() . '<br />';


// -------------------------------------------------------------------------------------------
//
// The content of the page
//
$html = <<<EOD

<div class='wrapper'>
<h1>Äventyrsspel</h1>
<h2>Spela High Card Low Card</h2>

<div class='gamearea'>
{$htmlGame}
</div> <!-- gamearea -->

<div class='description'>
<h4>Beskrivning:</h4>
<p class='description'>
Spela spelet HighLow, lyckas gissa rätt på 3 kort för att komma vidare i spelet.
</p>
</div> <!-- description -->

<div class='action'>
<h4>Riktningar:</h4>
<p class='action'>
<a href='../room.php?id=10'>Avsluta spelet och gå tillbaka till rummet</a>
</p>
<h4>Händelser:</h4>
<p class='action'>
<a href='highlow.php?game=init'>Starta ett nytt spel och försök igen</a><br/>
</p>
</div> <!-- actions -->

</div> <!-- wrapper -->

EOD;


// -------------------------------------------------------------------------------------------
//
// Create and print out the html-page
//
require_once('common.php');
$title         = "Äventyrsspel, spela kortspelet High Card Low Card";
$charset     = "iso-8859-1";
$language    = "sv";
$stylesheet = "";
$debug = $debugEnable ? $debug : "";

$html = <<< EOD
<?xml version="1.0" encoding="{$charset}" ?> 
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$language}" lang="{$language}">  
    <head>
        <meta http-equiv="Content-Type" content="text/html; {$charset};" />
        <title>{$title}</title>
        <style type="text/css">{$stylesheet}</style>
        <link rel='stylesheet' href='../stylesheet.css' type='text/css' media='screen' />
    </head>
    <body>
        {$header}
        {$html}
        {$footer}
        {$debug}
    </body>
</html>
EOD;

header("Content-Type: application/xhtml+xml; charset={$charset}");
echo $html;
exit;

?>
 .                        
..:    © Mikael Roos, 2009