示例#1
0
function buildSubMenu($items)
{
    if ($items) {
        echo "<p><ul class='submenu'>";
        foreach ($items as $k => $v) {
            echo "<li><a href='#" . $k . "'>" . $v . "</a></li>";
        }
        echo "</ul></p><hr style='clear:both;'>";
    }
    successMsg();
}
示例#2
0
 /**
  * Purpose: guess a letter in this word
  * Preconditions: a game has started
  * Postconditions: the game data is updated
  **/
 function guessLetter($letter)
 {
     if ($this->isOver()) {
         return;
     }
     if (!is_string($letter) || strlen($letter) != 1 || !$this->isLetter($letter)) {
         return errorMsg("Oops! Please enter a letter.");
     }
     //check if they've already guessed the letter
     if (in_array($letter, $this->letters)) {
         return errorMsg("Oops! You've already guessed this letter.");
     }
     //only allow lowercase letters
     $letter = strtolower($letter);
     //if the word contains this letter
     if (!(strpos($this->wordList[$this->wordIndex], $letter) === false)) {
         //increase their score based on how many guesses they've used so far
         if ($this->health > 100 / ceil($this->guesses / 5)) {
             $this->setScore(5);
         } else {
             if ($this->health > 100 / ceil($this->guesses / 4)) {
                 $this->setScore(4);
             } else {
                 if ($this->health > 100 / ceil($this->guesses / 3)) {
                     $this->setScore(3);
                 } else {
                     if ($this->health > 100 / ceil($this->guesses / 2)) {
                         $this->setScore(2);
                     } else {
                         $this->setScore(1);
                     }
                 }
             }
         }
         //add the letter to the letters array
         array_push($this->letters, $letter);
         //if they've found all the letters in this word
         if (implode(array_intersect($this->wordLetters, $this->letters), "") == str_replace($this->punctuation, "", strtolower($this->wordList[$this->wordIndex]))) {
             $this->won = true;
         } else {
             return successMsg("Good guess, that's correct!");
         }
     } else {
         //reduce their health
         $this->setHealth(ceil(100 / $this->guesses) * -1);
         //add the letter to the letters array
         array_push($this->letters, $letter);
         if ($this->isOver()) {
             return;
         } else {
             return errorMsg("There are no letter {$letter}'s in this word.");
         }
     }
 }