From 3faa0d7fd4dc3442330c6037886d300412934cd1 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 28 Dec 2005 21:12:54 +0000 Subject: --- .../protected/pages/Fundamentals/Hangman.page | 15 +++ .../protected/pages/Fundamentals/HelloWorld.page | 25 ++++ .../pages/Fundamentals/Samples/Hangman/Home.page | 64 ++++++++++ .../pages/Fundamentals/Samples/Hangman/Home.php | 135 +++++++++++++++++++++ .../Fundamentals/Samples/Hangman/sequence.vsd | Bin 0 -> 157696 bytes .../pages/Fundamentals/Samples/Hangman/words.txt | 27 +++++ .../Fundamentals/Samples/HelloWorld/Home.page | 6 + .../pages/Fundamentals/Samples/HelloWorld/Home.php | 11 ++ .../Fundamentals/Samples/HelloWorld/sequence.gif | Bin 0 -> 5557 bytes .../Fundamentals/Samples/HelloWorld/sequence.vsd | Bin 0 -> 143360 bytes .../pages/Fundamentals/Samples/config.xml | 5 + .../protected/pages/Fundamentals/directory.gif | Bin 0 -> 3967 bytes 12 files changed, 288 insertions(+) create mode 100644 demos/quickstart/protected/pages/Fundamentals/Hangman.page create mode 100644 demos/quickstart/protected/pages/Fundamentals/HelloWorld.page create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.page create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/sequence.vsd create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/words.txt create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.page create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.php create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.gif create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.vsd create mode 100644 demos/quickstart/protected/pages/Fundamentals/Samples/config.xml create mode 100644 demos/quickstart/protected/pages/Fundamentals/directory.gif (limited to 'demos/quickstart/protected/pages/Fundamentals') diff --git a/demos/quickstart/protected/pages/Fundamentals/Hangman.page b/demos/quickstart/protected/pages/Fundamentals/Hangman.page new file mode 100644 index 00000000..d73868a0 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Hangman.page @@ -0,0 +1,15 @@ + + +

Sample: Hangman Game

+

+Having seen the simple "Hello World" application, we now build a more complex application called "Hangman Game". In this game, the player is asked to guess a word, a letter at a time. If he guesses a letter right, the letter will be shown in the word. The player can continue to guess as long as the number of his misses is within a prespecified bound. The player wins the game if he finds out the word within the miss bound, or he loses. +

+

+To facilitate the building of this game, we show the state transition diagram of the gaming process in the following, +

+

+To be continued... +

+ + +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/HelloWorld.page b/demos/quickstart/protected/pages/Fundamentals/HelloWorld.page new file mode 100644 index 00000000..b543afb7 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/HelloWorld.page @@ -0,0 +1,25 @@ + +

Sample: Hello World

+

+"Hello World" perhaps is the simplest interactive PRADO application that you can build. It displays to end-users a page with a submit button whose caption is Click Me. When the user clicks on the button, the button changes the caption to Hello World. +

+

+There are many approaches that can achieve the above goal. One can submit the page to the server, examine the POST variable, and generate a new page with the button caption updated. Or one can simply use JavaScript to update the button caption upon its onclick event. +

+

+PRADO promotes component-based and event-driven Web programming. The button is represented by a TButton object. It encapsulates the button caption as the Text property and associates the user button click action with a server-side Click event. Therefore, the "Hello World" task can be handled intuitively and easily. One simply needs to attach a function to the button's Click event. Within the function, the button's Text property is modified as "Hello World". The following diagram shows the above sequence, +

+ +

+The code that a developer needs to write is merely the following event handler function, where $sender refers to the button object. +

+
+public function buttonClicked($sender,$param)
+{
+	$sender->Text="Hello World";
+}
+
+ + + +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.page b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.page new file mode 100644 index 00000000..31058fa5 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.page @@ -0,0 +1,64 @@ +<%@ Title="Hangman Game" %> + + +

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/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php new file mode 100644 index 00000000..93028573 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php @@ -0,0 +1,135 @@ +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; + } + + $this->Word=$this->generateWord(); + $this->GuessWord=str_repeat('_',strlen($this->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 + { + $this->Misses++; + if($this->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 generateWord() + { + $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)); + return strtoupper($word); + } + + 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/quickstart/protected/pages/Fundamentals/Samples/Hangman/sequence.vsd b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/sequence.vsd new file mode 100644 index 00000000..4a55d8b7 Binary files /dev/null and b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/sequence.vsd differ diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/words.txt b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/words.txt new file mode 100644 index 00000000..80814580 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/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/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.page b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.page new file mode 100644 index 00000000..8931dad6 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.page @@ -0,0 +1,6 @@ +<%@ Title="Hello World" %> + + + + + \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.php b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.php new file mode 100644 index 00000000..b1a7f991 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/Home.php @@ -0,0 +1,11 @@ +Text="Hello World"; + } +} + +?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.gif b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.gif new file mode 100644 index 00000000..a1e51200 Binary files /dev/null and b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.gif differ diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.vsd b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.vsd new file mode 100644 index 00000000..e8c2f5a7 Binary files /dev/null and b/demos/quickstart/protected/pages/Fundamentals/Samples/HelloWorld/sequence.vsd differ diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml b/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml new file mode 100644 index 00000000..ecd29bd4 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/config.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/directory.gif b/demos/quickstart/protected/pages/Fundamentals/directory.gif new file mode 100644 index 00000000..c7d5086d Binary files /dev/null and b/demos/quickstart/protected/pages/Fundamentals/directory.gif differ -- cgit v1.2.3