From 1f1f96b7e143973e7da69fc01ebd6721f62e291c Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 10 Dec 2005 02:02:10 +0000 Subject: --- .gitattributes | 8 ++ demos/hangman/index.php | 8 ++ demos/hangman/protected/application.xml | 14 +++ demos/hangman/protected/data/words.txt | 27 +++++ demos/hangman/protected/pages/HomePage.php | 132 +++++++++++++++++++++ demos/hangman/protected/pages/HomePage.tpl | 64 ++++++++++ demos/hangman/protected/pages/Layout.php | 7 ++ demos/hangman/protected/pages/Layout.tpl | 19 +++ demos/hangman/protected/pages/config.xml | 7 ++ framework/TODO.txt | 4 +- framework/Web/UI/TControl.php | 22 +++- framework/Web/UI/WebControls/TContent.php | 2 + .../Web/UI/WebControls/TContentPlaceHolder.php | 5 +- 13 files changed, 314 insertions(+), 5 deletions(-) create mode 100644 demos/hangman/index.php create mode 100644 demos/hangman/protected/application.xml create mode 100644 demos/hangman/protected/data/words.txt create mode 100644 demos/hangman/protected/pages/HomePage.php create mode 100644 demos/hangman/protected/pages/HomePage.tpl create mode 100644 demos/hangman/protected/pages/Layout.php create mode 100644 demos/hangman/protected/pages/Layout.tpl create mode 100644 demos/hangman/protected/pages/config.xml diff --git a/.gitattributes b/.gitattributes index 2acc62e8..ff2c1273 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,6 +17,14 @@ demos/controls/themes/BlueTheme/buttons.skin -text demos/controls/themes/BlueTheme/icon_profile.gif -text demos/controls/themes/BlueTheme/labels.skin -text demos/controls/themes/BlueTheme/simple.css -text +demos/hangman/index.php -text +demos/hangman/protected/application.xml -text +demos/hangman/protected/data/words.txt -text +demos/hangman/protected/pages/HomePage.php -text +demos/hangman/protected/pages/HomePage.tpl -text +demos/hangman/protected/pages/Layout.php -text +demos/hangman/protected/pages/Layout.tpl -text +demos/hangman/protected/pages/config.xml -text demos/personal/index.php -text demos/personal/protected/Modules/DataModule.php -text demos/personal/protected/Pages/HomePage.php -text 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 @@ +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 @@ + + + + + + + + + + + + Application.Data.words + + \ 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 @@ +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" %> + + +

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/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 @@ + \ 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 @@ + + + + + + + + + +

+Valid XHTML 1.0 Strict +

+

+Powered by PRADO. +

+ + + \ 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 @@ + + + + + + + \ No newline at end of file diff --git a/framework/TODO.txt b/framework/TODO.txt index ff3c2598..658bbc12 100644 --- a/framework/TODO.txt +++ b/framework/TODO.txt @@ -1,15 +1,13 @@ +how to properly encode a URL (e.g. used in javascript or css includes) how to display context information for template parsing and instantiation? File name? line number? how to do this for Theme (skin files)? -how to correctly highlight source code displayed for exception context? -checkbox if checked, posted, unchecked and then post, it will be checked. think more about encoding/decoding <%@ MasterClass="Pages.MasterPage" %> Features to be implemented later: - SmartNavigation: TForm, TPage -- DefaultButton: TForm, TClientScriptManager Main Problems: 1. How to solve viewstate ID mapping problems? What if a control has changed its ID before saving viewstate? diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index ce343925..7a123ed2 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -790,7 +790,7 @@ class TControl extends TComponent * The current naming container is either the control itself * if it implements {@link INamingContainer} or the control's naming container. * The ID path is an ID sequence separated by {@link TControl::ID_SEPARATOR}. - * For example, 'Repeater1:Item1:Button1' looks for a control with ID 'Button1' + * For example, 'Repeater1.Item1.Button1' looks for a control with ID 'Button1' * whose naming container is 'Item1' whose naming container is 'Repeater1'. * @param string ID of the control to be looked up * @return TControl|null the control found, null if not found @@ -798,6 +798,7 @@ class TControl extends TComponent */ public function findControl($id) { + $id=strtr($id,'.',self::ID_SEPARATOR); $container=($this instanceof INamingContainer)?$this:$this->getNamingContainer(); if(!$container || !$container->getHasControls()) return null; @@ -842,6 +843,25 @@ class TControl extends TComponent $this->_rf[self::RF_NAMED_OBJECTS][$name]=$object; } + /** + * Unregisters an object by name. + * @param string name of the object + * @see registerObject + */ + public function unregisterObject($name) + { + unset($this->_rf[self::RF_NAMED_OBJECTS][$name]); + } + + /** + * @return boolean whether an object has been registered with the name + * @see registerObject + */ + public function isObjectRegistered($name) + { + return isset($this->_rf[self::RF_NAMED_OBJECTS][$name]); + } + /** * This method is invoked after the control is instantiated by a template. * When this method is invoked, the control should have a valid TemplateControl diff --git a/framework/Web/UI/WebControls/TContent.php b/framework/Web/UI/WebControls/TContent.php index 20cd1dc5..d02d3b4d 100644 --- a/framework/Web/UI/WebControls/TContent.php +++ b/framework/Web/UI/WebControls/TContent.php @@ -39,6 +39,8 @@ class TContent extends TControl implements INamingContainer */ public function createdOnTemplate($parent) { + if(($id=$this->getID())==='') + throw new TConfigurationException('content_id_required'); $this->getTemplateControl()->registerContent($this); parent::createdOnTemplate($parent); } diff --git a/framework/Web/UI/WebControls/TContentPlaceHolder.php b/framework/Web/UI/WebControls/TContentPlaceHolder.php index 32106e82..a13e85bc 100644 --- a/framework/Web/UI/WebControls/TContentPlaceHolder.php +++ b/framework/Web/UI/WebControls/TContentPlaceHolder.php @@ -39,8 +39,11 @@ class TContentPlaceHolder extends TControl */ public function createdOnTemplate($parent) { + if(($id=$this->getID())==='') + throw new TConfigurationException('contentplaceholder_id_required'); $loc=$parent->getHasControls()?$parent->getControls()->getCount():0; - $this->getTemplateControl()->registerContentPlaceHolder($this->getID(),$parent,$loc); + $this->getTemplateControl()->registerContentPlaceHolder($id,$parent,$loc); + $parent->unregisterObject($id); } } -- cgit v1.2.3