From 925c51d0b63b61340ef89462e32e5fb784165428 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 23 Dec 2005 03:33:21 +0000 Subject: --- demos/hangman/index.php | 5 +- demos/hangman/protected/pages/Home.page | 64 ++++++++++++++ demos/hangman/protected/pages/Home.php | 132 +++++++++++++++++++++++++++++ demos/hangman/protected/pages/HomePage.php | 132 ----------------------------- demos/hangman/protected/pages/HomePage.tpl | 64 -------------- demos/hangman/protected/pages/words.txt | 27 ++++++ 6 files changed, 225 insertions(+), 199 deletions(-) create mode 100644 demos/hangman/protected/pages/Home.page create mode 100644 demos/hangman/protected/pages/Home.php delete mode 100644 demos/hangman/protected/pages/HomePage.php delete mode 100644 demos/hangman/protected/pages/HomePage.tpl create mode 100644 demos/hangman/protected/pages/words.txt (limited to 'demos') diff --git a/demos/hangman/index.php b/demos/hangman/index.php index af488b0a..97d015b6 100644 --- a/demos/hangman/index.php +++ b/demos/hangman/index.php @@ -1,8 +1,7 @@ run(); ?> \ No newline at end of file diff --git a/demos/hangman/protected/pages/Home.page b/demos/hangman/protected/pages/Home.page new file mode 100644 index 00000000..03aed1d3 --- /dev/null +++ b/demos/hangman/protected/pages/Home.page @@ -0,0 +1,64 @@ +<%@ MasterClass="Application.pages.Layout" Title="Prado Hangman Game" %> + + +

Prado Hangman Game

+ + +

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!

+
+
+
+ + +
+ + +

Please make a guess

+

<%= $this->Page->GuessWord %>

+

You have made <%=$this->Page->Misses %> bad guesses +out of a maximum of <%= $this->Page->Level %>.

+

Guess: + + + + + + + + + + + + + + + + + + + + + + + + + + +

+

+
+ + +

You Win!

+

The word was: <%= $this->Page->Word %>.

+

+
+ + +

You Lose!

+

The word was: <%= $this->Page->Word %>.

+

+
+
+
\ No newline at end of file diff --git a/demos/hangman/protected/pages/Home.php b/demos/hangman/protected/pages/Home.php new file mode 100644 index 00000000..0c87d12f --- /dev/null +++ b/demos/hangman/protected/pages/Home.php @@ -0,0 +1,132 @@ +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=dirname(__FILE__).'/words.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.php b/demos/hangman/protected/pages/HomePage.php deleted file mode 100644 index 6e0388bc..00000000 --- a/demos/hangman/protected/pages/HomePage.php +++ /dev/null @@ -1,132 +0,0 @@ -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=dirname(__FILE__).'/words.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 deleted file mode 100644 index 69f7f4d2..00000000 --- a/demos/hangman/protected/pages/HomePage.tpl +++ /dev/null @@ -1,64 +0,0 @@ -<%@ MasterClass="Pages.Layout" Title="Prado Hangman Game" %> - - -

Prado Hangman Game

- - -

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!

-
-
-
- - -
- - -

Please make a guess

-

<%= $this->Page->GuessWord %>

-

You have made <%=$this->Page->Misses %> bad guesses -out of a maximum of <%= $this->Page->Level %>.

-

Guess: - - - - - - - - - - - - - - - - - - - - - - - - - - -

-

-
- - -

You Win!

-

The word was: <%= $this->Page->Word %>.

-

-
- - -

You Lose!

-

The word was: <%= $this->Page->Word %>.

-

-
-
-
\ No newline at end of file diff --git a/demos/hangman/protected/pages/words.txt b/demos/hangman/protected/pages/words.txt new file mode 100644 index 00000000..80814580 --- /dev/null +++ b/demos/hangman/protected/pages/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 -- cgit v1.2.3