Lab4 Deadline: 18 Oct 2017 Information about php: Variable $_SERVER[ PHP_SELF ] Description The filename of the current script (relative to the root directory) Function string htmlspecialchars(string $s) int intval($var) int rand(int $m, int $n) Description Convert all special characters in the variable $s to HTML entities Return the integer value of $var Return a random integer number between $m and $n inclusively. Question 1 An overview of question 1 is given in Figure Q1_1. (non-first time visit: redirect to GuessingA.php) Start playgamea. php (First-time visit: redirect to settinga.html) settinga.html & setcookiesa.php GuessingA.php Figure Q1_1 Players first go to playgamea.php. In playgamea.php, cookie is searched to check if players have done the setting before. If player has not done the setting before, player will be redirected to settinga.html. In settinga.html, player will be required to set two parameters: the color channel for guessing (called c) and the maximum number of guesses (called maxno). These two parameters will be sent to setcookiesa.php when the submit button is clicked. In setcookiesa.php, the two parameters are stored as cookies. After that, player will be redirected to GuessingA.php. If player has cookies that contain c and maxno, player will be redirected to GuessingA.php. In GuessingA.php, player will have maxno maximum number of chances to guess the value for the color component c of a button. The color of the button can be specified by setting the RGB component. For example, if user has chosen green channel for guessing, GuessingA.php will generate a random number in between 0 and 255. The button s color can be set as
rgb(100,random number, 100). Player will then input his/her guess in a textbook and see if the guess is correct or not. Part A Create and complete playgamea.php. Note that this php file only aims to check if player has set c and maxno before. If so, player will be redirect to GuessingA.php. Otherwise, player will be redirected to settinga.html. Save your answer as playgamea.php. Part B The file settinga.html is given. You will need to create and complete the file setcookiesa.php. In setcookiesa.php, the two parameters input by the player in settinga.html will be saved as cookies. The cookies will be stored for one year in client s computer. After setting the cookies, player will be redirected to GuessingA.php. Save your answer as setcookiesa.php. Part C A partially completed GuessingA.php is given. In GuessingA.php, player will have maxno maximum number of chances to guess the value for the color component c of a button. As shown in Figure Q1_2, you have to get the user preferences from cookies (e.g., green and 5) and then display them in the browser output. Besides, a random number in the range of 0-255 (inclusive) will be generated. A button with color specified by this random number will be generated (under the heading The answer ). The button s color can be set as rgb(100, random number, 100) if player has chosen green channel for guessing. You can assume that values in the other two color channels are always set at 100. Save your answer as GuessingA_PartC.php.
Figure Q1_2 Part D The game in GuessingA.php works as follows: A player enters a number into the text field guess. After player clicks the submit button, the value is sent to the server (to the same file) for checking. The server will then send back the result to the player. If the number the player guesses is equal to the random number, the player wins as in Figure Q1_3. Note that a button is also created under the heading Your guess. This newly created button takes the user input in the text field guess as the color value in the c channel while values in the other two channels are set as 100. If the number the player guesses is not equal to the random number, a hint will be given as in Figure Q1_4 and Figure Q1_5. For example, if the number the player guesses is smaller than the random number, a hint is too small is shown as in Figure Q1_4. Besides a button is also created under the heading Your guess. This newly created button has color value specified by the user in the text field guess. This allows the player to compare the color specified by him/her and that from the true answer. The player has maxno chances to guess the number. The number of chances remain will be shown as in Figure Q1_4 and Figure Q1_5. If the player cannot make the correct guess within maxno chances, the player loses and the correct number will be shown as in Figure Q1_6. When the game is finished (i.e., either the player wins or loses), the submit button is disabled and the player cannot make further guess. You may refer to the soft copy of the handout for the color illustration. Save your answer as GuessingA_PartD.php.
Figure Q1_3 Figure Q1_4
Figure Q1_5 Figure Q1_6