CS2623: Server-Side Programming (SSP) 04

Objectives:

Reference

Overview

You are going to create a word guessing game called Frosty. You will select a word and a hint that helps the player, but doesn't help them so much they guess their word too quickly. Think of the hint as more of a category to chose from. Each time, the user will guess a character that might be in the secret word. They get unlimited right answers, but guessing a character that is not in the secret word is bad. For each wrong answer, the world will slowly go into another ice apocalypse symbolized by a giant snowman called Frosty. To be clear, frosty is bad....we do not want to see Frosty. With each wrong guess, Frosty will slowly form.

Specifics:

  1. PHP Page: Create a new HTML page named "SSP04.php" in your root directory.
    1. Create a new HTML form
      1. Textbox: There will be one text box for the user to enter the letter. The name must be "frosty_letter_guess".
      2. Submit button: There will be one submit button for the form
      3. Method: Post
      4. Action: Just reload your ssp04.php page.
    2. Session: Start a new session
    3. Initialize the following sessions if they are not already set
      1. secretWord: Come up with a secret word that is at least seven characters long.
      2. secretWord_hint: Identify a hint for your secret word.
      3. secretWord_array: Set using the str_split function on secretWord session.
      4. secretWord_len: Set using the the strlen function on the secretWord session.
      5. guess_secretWord: Set using the str_repeat. You want the value to be underscores that are the same length as secretWord session.
      6. guess_count: Set equal to zero.
      7. guess_count_wrong: Set equal to zero.
      8. guess_tracked: Set equal to zero.
      9. guess_image: Set equal to zero.
      10. guess_letter: Set equal blank "" for now.
      11. game_lastGuess: Set equal to the current date and time.
      12. game_started: Set equal to the current date and time.
      1. Variables: Using the table "SSP04 Session and Variables" in the reference section. Intialize the variables using the appropriate session if the session is set.
  2. PHP Functions Page:
    1. functions_ssp04.php: Create a new PHP page in your functions folder called "functions_ssp04.php".
    2. ssp04.php: Add code to "ssp04.php" that loads "functions_ssp04.php" once.
    3. frosty_guessing: Create a function entitled "frosty_guessing".
      1. Paramaters:
        1. $secretWord
        2. $secretWord_hint
        3. $guess_secretWord
        4. $guess_letter
        5. $guess_tracked
        6. $guess_count
        7. $guess_count_wrong
        8. $game_started
        9. $game_lastGuess
        10. $secretWord_len
        11. $secretWord_array
        12. $guess_image
    4. $guess_found: Create a variable entitled "$guess_found" which will be used to indicate the guessed word was found. Intialize it to "N"
    5. $game_lastGuess: Create a variable entitled "$game_lastGuess" which will be used to indicate the last time a player made a guess. Set it equal to the current time and date.
    6. Conditional logic: Create an if statement that will handle three diferent conditions.
      1. If: Test if the guessed word (e.g. $guess_letter) has alread been guessed using the strpos() string function and $guess_tracked variable. If the word has been guesssed, increment the counter for the number of wrong guesses (e.g. $guess_count_wrong) by one. Also, increment the guess image number ($guess_image) by one.
      2. Else if: Test if the guessed word (e.g. $guess_letter) is the last one to win the game. If it does, display a congradulations message and special image. You can chose your own image for this.
      3. Else if: Test if the guessed word (e.g. $guess_letter) is not in the secret word. If it is...
        1. $guess_tracked: Append the the guessed word (e.g. $guess_letter) to the string you're using to track all the guesses (e.g. $guess_tracked).
        2. $guess_count_wrong: Increment the counter tracking the number of wrong guesses (e.g. $guess_count_wrong) by one.
        3. $guess_image: Increment the guess image number variable (e.g. $guess_image)by one.
      4. Else: This will handle if conditions where the guessed character is in the secret word.
        1. For Loop: Create a for loop with the following settings: initialize counter to zero, and increment the counter by 1 while keeping it under the length of the secret word (e.g. $secretWord_len).
          1. if: While iterating through the array with the for loop counter, create an if statement that tests if the guessed word (e.g. $guess_letter). Check the reference section above for information about iterating through an array with a loop. If there is a match than set $guess_found = "Y". Also, do the following...
            1. if: If the for loop counter is equal to zero. Update the guessed secret word status (e.g. $guess_secretWord). You will do this by concatenating the guessed letter (e.g. $guess_letter) with the existing $guess_secretWord using the string substr() function. I highly suggest pulling out a piece of paper and writing down the letter. I will give you a hint and tell you the position is 1. For the number of characters, I want you to try and figure this out.
            2. else: This will handle if the letter matches anything after the first character. Here you will be doing two substr() functions with the $guess_letter (i.e. substr($guess_secretWord,,).$guess_lettersubstr($guess_secretWord,,)). The first substr position is 0, and the second is the loop counter + 1. Again, I will leave it to you to find out the number of characters.
    7. $guess_count: Increment the variable $guess_count by 1.
    8. Sessions: Update the sessions. Set each one equal to value of its variable.
  3. frosty_round: Create a function that will display the game output.
    1. Paramaters:
      1. $game_started
      2. $game_lastGuess
      3. $secretWord_len
      4. $secretWord_hint
      5. $guess_count
      6. $guess_count_wrong
      7. $guess_tracked
      8. $guess_image
      9. $guess_secretWord
    2. Date Information: Display when the game was started and the last time the player played
    3. Current Progress: Display the secret word and some information about the game. This should include:
      1. "Secret word hint" using the $secretWord_hint variable
      2. "Secret Word Length" using the $secretWord_len variable
      3. "Guess Count" using the $guess_count variable
      4. "Guess Count (Wrong Answers)" using the $guess_count_wrong variable
      5. "Guess Count (Right Answers)" using the $guess_secretWord variable. Use the strlen() and str_replace() to derive this number. You will be replacing the underscores with an empty string (e.g. "").
      6. "Guessed letters" using the $secretWord_hint variable
      7. "Frosty is currently at" display the current frosty pictue using the $guess_image variable to reference the appropriate frosty image dynamically.
    4. Call: Add a line to the end of the frosty_guessing() function to call the frosty_round() function.

Common Requirements for All Web Pages:

  1. Your code must adhere to HTML5 standards. W3C HTML5 Example: https://www.w3schools.com/html/html5_intro.asp
  2. All your pages must pass W3C validators
  3. The web pages must display correctly in all of the following: FireFox, Chrome, Internet Explorer.
  4. The links between the existing pages with the Pacific Trails Resort website cannot be broken.
  5. All HTML and CSS code must be well documented, properly indented, and easy to read.
    http://css-tricks.com/examples/CleanCode/Beautiful-HTML.png
    http://coding.smashingmagazine.com/2008/05/02/improving-code-readability-with-css-styleguides/