Chapter 3: theHangmanGame will show you how to develop a Web-based HangmanGame ). Some PRADO components are used here. This game clarified that the display status makes the PRADO page highly interactive. Chapter 3: the Hangman Game
This chapter describes how to develop a Web-based Hangman Game ). Some PRADO components are used here. This game clarified that the display status makes the PRADO page highly interactive.
This game only contains one page to achieve the following functions: When a user visits the game for the first time, a user selects three different difficulties to start the game, different levels of difficulty correspond to different number of wrong guesses. After the game starts, the upper part of the page displays the words to guess, and the letters to be guessed are underlined. The lower part of the page lists 26 letters. you can click the corresponding letter to select the expected letter. If the user gives up the game or the number of errors exceeds the difficulty limit, the failure information is displayed. if you guess it is correct, the success information is displayed. Users can start the game any time.
The PRADO components that will be applied in the model include:
- TRadioButton: displays a single worker.
- TPanel: DisplayElement.
- TLabel: displays text.
- TButton: displays a submit button.
- TLinkButton: displays a hyperlink for submission.
- TForm: Display Element.
These defined components have encapsulated many functions through attributes and events. For example, you can setTPanelOfVisible
Attribute to control allWhether the element is visible. You canTButtonComponentOnClickThe event specifies a response function. when you click a button, the response function is called. For more information about these components, see prado api documentation.
Some data in the game needs to be maintained in the game process. Because only one page is used here, the application can display the status without applying session to keep the data. The following data needs to be retained in the display status:
- Word: to guess the Word.
- GuessWord: the word being guessed (no guesses are displayed with an underscore ).
- Level: the difficulty Level of the game.
- Misses: number of guesses.
They are all defined in the page attributes (or not ).
We need to create 6 files. Assume that this exploitation is stored in the root directory of the Web server. these files are:
- Hangman. php: Main imports used;
- WEB-INF/hangman. spec: Configuration file used;
- WEB-INF/hangman/HomePage. php: Page files;
- WEB-INF/hangman/HomePage. spec: Page specification file;
- WEB-INF/hangman/HomePage. tpl: Page template file;
- WEB-INF/data/hangman.txt: Text file containing the words to guess.
Important:HomePageClass three files, other files and 'Hello, world! 'Example is similar.
3.1HomePage. tpl
First, some page template files. This process is also used by PRADO for development. First, combine the PRADO component in the page template, then you can test the display of this page, and finally write the code required in the page class file. This is a typical RAD (rapid development) development process.