887Chapter 46A Trivia Game
| $rank | $name | . $answer_count | $credit |
|---|
; $rank++; } $result_string .= ; return($result_string); } else { throw newException( Game display has no database connection ); } } private function _gameStateString () { // The HTML table $correct_answers = $this->_game->getCorrectAnswers(); $credit = round_to_digits($this->_game->getCredit(), 2); $level = $this->_game->getLevel(); return(
. _blueColor> . | Total correct answers: | . $correct_answers |
. _redColor>| Credit remaining: | . $credit |
. _blueColor> . | You have reached level: | . $level |
); } } ?> Note that in the GameDisplayclass we use some object-oriented constructs that are new asof PHP5. The constructor function is called __construct(), rather than having the samename as the class. And we have designated the functions that are not intended for externaluse as private, which will prevent any such use by other classes. Most of the class s private functions involve querying the Gameobject for information that it then wraps up in HTML strings. One of the more interesting functions of this type is distractor_string(), which creates the actual display of alternatives for the answer range. The general division of labor here is: .The upper and lower bounds for the answer are specified in the database, as well ashow many choices should be displayed and how they should be scaled. .The Questionobject takes this information and creates all the intermediate steps ofthe answer range as it is constructed. .The GameDisplayobject queries the game for the current question and then queriesthat question to discover the upper and lower bounds and the intermediate steps. Itthen simply wraps those values in HTML to present radio-button alternatives, with themaximum answer range preselected.
If you are in need for cheap and reliable webhost to host your website, we recommend
http web server services.
This entry was posted
on Friday, March 21st, 2008 at 8:22 am and is filed under Domain.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.