diff options
| author | xue <> | 2005-12-10 02:02:10 +0000 | 
|---|---|---|
| committer | xue <> | 2005-12-10 02:02:10 +0000 | 
| commit | 1f1f96b7e143973e7da69fc01ebd6721f62e291c (patch) | |
| tree | 342915f87c904d8a79a853101ad9d176051a588b /demos | |
| parent | 662547dc4c6c493c1c89f888e3ef73667ea783c4 (diff) | |
Diffstat (limited to 'demos')
| -rw-r--r-- | demos/hangman/index.php | 8 | ||||
| -rw-r--r-- | demos/hangman/protected/application.xml | 14 | ||||
| -rw-r--r-- | demos/hangman/protected/data/words.txt | 27 | ||||
| -rw-r--r-- | demos/hangman/protected/pages/HomePage.php | 132 | ||||
| -rw-r--r-- | demos/hangman/protected/pages/HomePage.tpl | 64 | ||||
| -rw-r--r-- | demos/hangman/protected/pages/Layout.php | 7 | ||||
| -rw-r--r-- | demos/hangman/protected/pages/Layout.tpl | 19 | ||||
| -rw-r--r-- | demos/hangman/protected/pages/config.xml | 7 | 
8 files changed, 278 insertions, 0 deletions
| diff --git a/demos/hangman/index.php b/demos/hangman/index.php new file mode 100644 index 00000000..8ec5d000 --- /dev/null +++ b/demos/hangman/index.php @@ -0,0 +1,8 @@ +<?php
 +
 +$basePath=dirname(__FILE__);
 +require_once($basePath.'/../../framework/prado.php');
 +$application=new TApplication($basePath.'/protected/application.xml');
 +$application->run();
 +
 +?>
\ No newline at end of file diff --git a/demos/hangman/protected/application.xml b/demos/hangman/protected/application.xml new file mode 100644 index 00000000..01f60f47 --- /dev/null +++ b/demos/hangman/protected/application.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?>
 +
 +<application id="hangman" mode="Debug">
 +  <paths>
 +    <alias id="Application" path="." />
 +    <alias id="Pages" path="pages" />
 +  </paths>
 +  <services>
 +    <service id="page" BasePath="Pages" DefaultPage="home" />
 +  </services>
 +  <parameters>
 +    <parameter id="wordFile">Application.Data.words</parameter>
 +  </parameters>
 +</application>
\ No newline at end of file diff --git a/demos/hangman/protected/data/words.txt b/demos/hangman/protected/data/words.txt new file mode 100644 index 00000000..80814580 --- /dev/null +++ b/demos/hangman/protected/data/words.txt @@ -0,0 +1,27 @@ +This program is free software; you can redistribute it and/or
 +modify it under the terms of the GNU General Public License
 +as published by the Free Software Foundation.
 +
 +This program is distributed in the hope that it will be useful,
 +but WITHOUT ANY WARRANTY; without even the implied warranty of
 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +GNU General Public License for more details.
 +
 +PRADO is an event-driven and component-based framework
 +for Web application development in PHP 5.
 +
 +Components following the PRADO protocol are highly
 +configurable and reusable. Properties defining
 +the basic features of a component can be configured 
 +in specifications, templates or code. 
 +New components can be developed by either inheriting
 +an existing component class or composing several
 +components together. The work of using a component 
 +amounts to placing the component tag on the page template, 
 +configuring component properties, and writing handler 
 +functions to respond to component events.
 +
 +PRADO shares many similarities with ASP.NET and other
 +RAD tools for Windows GUI development, such as Borland Delphi.
 +In particular, it supports event-driven programming,
 +viewstate maintenance, javascript, template, form validations, etc.
\ No newline at end of file diff --git a/demos/hangman/protected/pages/HomePage.php b/demos/hangman/protected/pages/HomePage.php new file mode 100644 index 00000000..ed030d2f --- /dev/null +++ b/demos/hangman/protected/pages/HomePage.php @@ -0,0 +1,132 @@ +<?php
 +
 +class HomePage extends TPage
 +{
 +	const EASY_LEVEL=10;
 +	const MEDIUM_LEVEL=5;
 +	const HARD_LEVEL=3;
 +
 +	public function selectLevel($sender,$param)
 +	{
 +		if($this->EasyLevel->Checked)
 +			$this->Level=self::EASY_LEVEL;
 +		else if($this->MediumLevel->Checked)
 +			$this->Level=self::MEDIUM_LEVEL;
 +		else if($this->HardLevel->Checked)
 +			$this->Level=self::HARD_LEVEL;
 +		else
 +		{
 +			$this->LevelError->Visible=true;
 +			return;
 +		}
 +		$wordFile=Prado::getPathOfNamespace($this->Application->Parameters['wordFile'],'.txt');
 +		$words=preg_split("/[\s,]+/",file_get_contents($wordFile));
 +		do
 +		{
 +			$i=rand(0,count($words)-1);
 +			$word=$words[$i];
 +		} while(strlen($word)<5 || !preg_match('/^[a-z]*$/i',$word));
 +		$word=strtoupper($word);
 +
 +		$this->Word=$word;
 +		$this->GuessWord=str_repeat('_',strlen($word));
 +		$this->Misses=0;
 +		$this->showPanel('GuessPanel');
 +	}
 +
 +	public function guessWord($sender,$param)
 +	{
 +		$sender->Enabled=false;
 +		$letter=$sender->Text;
 +		$word=$this->Word;
 +		$guessWord=$this->GuessWord;
 +		$pos=0;
 +		$success=false;
 +		while(($pos=strpos($word,$letter,$pos))!==false)
 +		{
 +			$guessWord[$pos]=$letter;
 +			$success=true;
 +			$pos++;
 +		}
 +		if($success)
 +		{
 +			$this->GuessWord=$guessWord;
 +			if($guessWord===$word)
 +				$this->showPanel('WinPanel');
 +		}
 +		else
 +		{
 +			$misses=$this->Misses+1;
 +			$this->Misses=$misses;
 +			if($misses>=$this->Level)
 +				$this->giveUp(null,null);
 +		}
 +	}
 +
 +	public function giveUp($sender,$param)
 +	{
 +		$this->showPanel('LosePanel');
 +	}
 +
 +	public function startAgain($sender,$param)
 +	{
 +		$this->showPanel('IntroPanel');
 +		$this->LevelError->Visible=false;
 +		for($letter=65;$letter<=90;++$letter)
 +		{
 +			$guessLetter='Guess'.chr($letter);
 +			$this->$guessLetter->Enabled=true;
 +		}
 +	}
 +
 +	protected function showPanel($panelID)
 +	{
 +		$this->IntroPanel->Visible=false;
 +		$this->GuessPanel->Visible=false;
 +		$this->WinPanel->Visible=false;
 +		$this->LosePanel->Visible=false;
 +		$this->$panelID->Visible=true;
 +	}
 +
 +	public function setLevel($value)
 +	{
 +		$this->setViewState('Level',$value,0);
 +	}
 +
 +	public function getLevel()
 +	{
 +		return $this->getViewState('Level',0);
 +	}
 +
 +	public function setWord($value)
 +	{
 +		$this->setViewState('Word',$value,'');
 +	}
 +
 +	public function getWord()
 +	{
 +		return $this->getViewState('Word','');
 +	}
 +
 +	public function getGuessWord()
 +	{
 +		return $this->getViewState('GuessWord','');
 +	}
 +
 +	public function setGuessWord($value)
 +	{
 +		$this->setViewState('GuessWord',$value,'');
 +	}
 +
 +	public function setMisses($value)
 +	{
 +		$this->setViewState('Misses',$value,0);
 +	}
 +
 +	public function getMisses()
 +	{
 +		return $this->getViewState('Misses',0);
 +	}
 +}
 +
 +?>
\ No newline at end of file diff --git a/demos/hangman/protected/pages/HomePage.tpl b/demos/hangman/protected/pages/HomePage.tpl new file mode 100644 index 00000000..69f7f4d2 --- /dev/null +++ b/demos/hangman/protected/pages/HomePage.tpl @@ -0,0 +1,64 @@ +<%@ MasterClass="Pages.Layout" Title="Prado Hangman Game" %>
 +<com:TContent ID="body" >
 +<com:TForm>
 +<h1>Prado Hangman Game</h1>
 +
 +<com:TPanel ID="IntroPanel">
 +<p>This is the game of Hangman. You must guess a word, a letter at a time.
 +If you make too many mistakes, you lose the game!</p>
 +<com:TRadioButton ID="EasyLevel" GroupName="level" Text="Easy game; you are allowed 10 misses." /><br/>
 +<com:TRadioButton ID="MediumLevel" GroupName="level" Text="Medium game; you are allowed 5 misses." /><br/>
 +<com:TRadioButton ID="HardLevel" GroupName="level" Text="Hard game; you are only allowed 3 misses." /><br/>
 +<com:TButton Text="Play!" Click="selectLevel" />
 +<com:TLabel ID="LevelError" Text="You must choose a difficulty level!" ForeColor="red" Visible="false" />
 +</com:TPanel>
 +
 +<com:TPanel ID="GuessPanel" Visible="false">
 +<h2>Please make a guess</h2>
 +<h3 style="letter-spacing: 4px;"><%= $this->Page->GuessWord %></h3>
 +<p>You have made <%=$this->Page->Misses %> bad guesses
 +out of a maximum of <%= $this->Page->Level %>.</p>
 +<p>Guess:
 +<com:TLinkButton ID="GuessA" Text="A" Click="guessWord" />
 +<com:TLinkButton ID="GuessB" Text="B" Click="guessWord" />
 +<com:TLinkButton ID="GuessC" Text="C" Click="guessWord" />
 +<com:TLinkButton ID="GuessD" Text="D" Click="guessWord" />
 +<com:TLinkButton ID="GuessE" Text="E" Click="guessWord" />
 +<com:TLinkButton ID="GuessF" Text="F" Click="guessWord" />
 +<com:TLinkButton ID="GuessG" Text="G" Click="guessWord" />
 +<com:TLinkButton ID="GuessH" Text="H" Click="guessWord" />
 +<com:TLinkButton ID="GuessI" Text="I" Click="guessWord" />
 +<com:TLinkButton ID="GuessJ" Text="J" Click="guessWord" />
 +<com:TLinkButton ID="GuessK" Text="K" Click="guessWord" />
 +<com:TLinkButton ID="GuessL" Text="L" Click="guessWord" />
 +<com:TLinkButton ID="GuessM" Text="M" Click="guessWord" />
 +<com:TLinkButton ID="GuessN" Text="N" Click="guessWord" />
 +<com:TLinkButton ID="GuessO" Text="O" Click="guessWord" />
 +<com:TLinkButton ID="GuessP" Text="P" Click="guessWord" />
 +<com:TLinkButton ID="GuessQ" Text="Q" Click="guessWord" />
 +<com:TLinkButton ID="GuessR" Text="R" Click="guessWord" />
 +<com:TLinkButton ID="GuessS" Text="S" Click="guessWord" />
 +<com:TLinkButton ID="GuessT" Text="T" Click="guessWord" />
 +<com:TLinkButton ID="GuessU" Text="U" Click="guessWord" />
 +<com:TLinkButton ID="GuessV" Text="V" Click="guessWord" />
 +<com:TLinkButton ID="GuessW" Text="W" Click="guessWord" />
 +<com:TLinkButton ID="GuessX" Text="X" Click="guessWord" />
 +<com:TLinkButton ID="GuessY" Text="Y" Click="guessWord" />
 +<com:TLinkButton ID="GuessZ" Text="Z" Click="guessWord" />
 +</p>
 +<p><com:TLinkButton Text="Give up?" Click="giveUp" /></p>
 +</com:TPanel>
 +
 +<com:TPanel ID="WinPanel" Visible="false">
 +<h2>You Win!</h2>
 +<p>The word was: <%= $this->Page->Word %>.</p>
 +<p><com:TLinkButton Text="Start Again" Click="startAgain" /></p>
 +</com:TPanel>
 +
 +<com:TPanel ID="LosePanel" Visible="false">
 +<h2>You Lose!</h2>
 +<p>The word was: <%= $this->Page->Word %>.</p>
 +<p><com:TLinkButton Text="Start Again" Click="startAgain" /></p>
 +</com:TPanel>
 +</com:TForm>
 +</com:TContent>
\ No newline at end of file diff --git a/demos/hangman/protected/pages/Layout.php b/demos/hangman/protected/pages/Layout.php new file mode 100644 index 00000000..ba96038b --- /dev/null +++ b/demos/hangman/protected/pages/Layout.php @@ -0,0 +1,7 @@ +<?php
 +
 +class Layout extends TTemplateControl
 +{
 +}
 +
 +?>
\ No newline at end of file diff --git a/demos/hangman/protected/pages/Layout.tpl b/demos/hangman/protected/pages/Layout.tpl new file mode 100644 index 00000000..1f678ba3 --- /dev/null +++ b/demos/hangman/protected/pages/Layout.tpl @@ -0,0 +1,19 @@ +<!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" lang="en" xml:lang="en">
 +
 +<com:THead>
 +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 +</com:THead>
 +
 +<body>
 +<com:TContentPlaceHolder ID="body" />
 +<p>
 +<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" style="border:0"/></a>
 +</p>
 +<p>
 +Powered by <a href="http://www.pradosoft.com/">PRADO</a>.
 +</p>
 +</body>
 +
 +</html>
\ No newline at end of file diff --git a/demos/hangman/protected/pages/config.xml b/demos/hangman/protected/pages/config.xml new file mode 100644 index 00000000..80842300 --- /dev/null +++ b/demos/hangman/protected/pages/config.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?>
 +
 +<configuration>
 +  <pages>
 +    <page id="home" class="HomePage" />
 +  </pages>
 +</configuration>
\ No newline at end of file | 
