Jag och Hangman

Show sourcecode

The following files exists in this folder. Click to view.

hangman/

img/
index.php
playhangman.php
src/
theme/
viewsource.php

playhangman.php

42 lines ASCII Unix (LF)
<?php
include("src/hangman/class_hangman.php");

$game = new Hangman();

// Get value from form if submitted
$game->GetGameInputFromForm();

// Do all the game logic, check guessed chars, return game status
// 1 if valid guess, not gameover
// 2 if gameover with success
// 3 if gameover with failure
$state $game->ProcessGameLogic();

// Check the state of the game and take appropriate action
$restartMessage "<p><a href='playhangman.php'>Start a new game!</a></p>";
$gameOverMessage="";
if(
$state == 2) {
  
$gameOverMessage  "<p style='font-size: x-large; color: green'>Nice, you rescued Mr. Hangman! High Five!</p>" $restartMessage;
} else if(
$state==3) {
  
$gameOverMessage  "<p style='font-size: x-large; color: red'>Sorry, you did not manage to save Mr. Hangman...</p>" $restartMessage;
}

// Get all the htmlparts of the gameplan
$type = isset($_GET['type']) && $_GET['type'] == 'plain' 'plain' 'button';
$form    $game->GetHTMLForForm($type);
$chars  $game->GetHTMLForGuessedChars();
$svg     $game->GetHTMLForSVGImage();
$style   $game->GetStyleForSVGImage();

$html "<div id=left>$form $chars $gameOverMessage</div><div>$svg</div>";


//
// Print out the resulting page
//
$pageTitle    "Play Hangman";
$pageId       "playhangman";
$pageStyle    $style;
$pageContent  $html;
include(
"theme/page.tpl.php");

Follow me on twitter. View the sourcecode.

© by me 2011. ™ by me. ® by me. all by me.