Ä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/

CPlayer.php
CRoom.php
ISessionDestroy.php
SAction.sql
adventure.php
allrooms.php
common.php
config.php
gameover.php
highlow/
img/
room.php
source.php
source1.php
stylesheet.css
template.php

room.php
<?php
// ===========================================================================================
//
// room.php
//
// Description: Read information of a room from the database and display it as HTML.
//
//
// Author: Mikael Roos
//

require_once('CPlayer.php');            
session_start();


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


// -------------------------------------------------------------------------------------------
//
// Take care of GET variables, and validate them
//

// Get the id of the room
$idRoom = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if($idRoom === FALSE || $idRoom === NULL || $idRoom < 0) die("Felaktig _GET värde."); 

// Get the action-event if any
$actionEvent = isset($_GET['event']) ? $_GET['event'] : "";


// ----------------------------------------------------------------------------
//
// Load room info into room-object
//
require_once('CRoom.php');
$room = new CRoom();
$room->ReadFromDatabase($idRoom);

// Perform the action-event, if any
$_SESSION['player']->PerformActionEvent($actionEvent);

// Keep track on current room and decrease health-meter when entering a new room
$_SESSION['player']->SetCurrentRoomAndDecreaseHealtMeter($idRoom);


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

<div class='wrapper'>

<!-- 
 - Use table to format output, could (and should) use css and <div>,
 - but it is a bit more complex and I do not want to mix with that right now.
 - We deal with that in another course (dbowebb, intro).
 -->
<table>
<tr>
<td style='width: 500px;'>
<h1>Äventyrsspel</h1>
<h2>{$room->iTitle}</h2>
</td>
<td>
<p>
Hälsa: {$_SESSION['player']->iHealthMeter}
</p>
</td>
</tr>
</table>

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

<div class='description'>
<h4>Beskrivning:</h4>
<p class='description'>{$room->iDescription}</p>
</div> <!-- description -->

<div class='action'>
<h4>Riktningar:</h4>
<p class='action'>{$room->iConnections}</p>
<h4>Händelser:</h4>
<p class='action'>{$room->iActions}</p>
</div> <!-- actions -->

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

EOD;


// -------------------------------------------------------------------------------------------
//
// Create and print out the html-page
//
require_once('common.php');
$title         = "Äventyrsspel";
$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