diff --git a/cgi-bin/uebung08/hangman-guess.php b/cgi-bin/uebung08/hangman-guess.php new file mode 100644 index 0000000..a856237 --- /dev/null +++ b/cgi-bin/uebung08/hangman-guess.php @@ -0,0 +1,12 @@ + diff --git a/cgi-bin/uebung08/hangman.php b/cgi-bin/uebung08/hangman.php index 554a22c..8c116d3 100644 --- a/cgi-bin/uebung08/hangman.php +++ b/cgi-bin/uebung08/hangman.php @@ -1,5 +1,59 @@ Wörter raten +

$mask

+END; + +echo << +END; + //Output all buttons + $alphabet = range('A', 'Z')); + foreach($alphabet as $abc) { +echo <<$abc +END; + + } + +echo << +END; + +//Show errorCount +$errors = $_SESSION['errorCount']; +echo <<$errors / 8

+END; + +//Show the restart link +$state = $_SESSION['state']; +if ($state > 0) { +echo <<Neues Spiel starten +END; +} + +if ($errors > 8) { +$guessword = $_SESSION['toGuess']; +echo <<Das richtige Wort wäre $guessword gewesen!

+END; +} + +//HOW MUCH IS THE FISH +echo << +END; + ?> diff --git a/cgi-bin/uebung08/hangman_lib.php b/cgi-bin/uebung08/hangman_lib.php index 14ebcef..31e41fc 100644 --- a/cgi-bin/uebung08/hangman_lib.php +++ b/cgi-bin/uebung08/hangman_lib.php @@ -49,4 +49,46 @@ function initGame() $_SESSION['errorCount'] = 0; $_SESSION['state'] = 0; } + +//Aufgabe 3 +function guessLetter($letter) { + //convert to uppercase letter + $letter = strtoupper($letter); + + //stop here if the letter is in guessedLetters + if (in_array($letter, $_SESSION['guessedLetters'])) { + return; + } + + //Append the guessed letter + $_SESSION['guessedLetters'][] = $letter; + + //Add the letter to the mask + $guessword = str_split($_SESSION['toGuess']); + $newMask = $_SESSION['mask']; + $wordcontainsletter = false; + for ($i = 0; $i < count($guessword); $i++) { + if ($guessword[$i] == $letter) { + $newMask[$i] = $letter; + $wordcontainsletter = true; + } + } + $_SESSION['mask'] = $newMask; + + //if the guessword doesn't contain the letter increment errorCount + if (!$wordcontainsletter) { + $_SESSION['errorCount'] += 1; + } + + //refresh the state + if ($_SESSION['errorCount'] > 8) { + $_SESSION['state'] = 2; + } else if (!in_array("_", $_SESSION['mask'])) { + $_SESSION['state'] = 1; + } + + + +} + ?> diff --git a/cgi-bin/uebung08/img/fish-0.svg b/cgi-bin/uebung08/img/fish-0.svg new file mode 100644 index 0000000..08bcc64 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-0.svg @@ -0,0 +1,227 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-1.svg b/cgi-bin/uebung08/img/fish-1.svg new file mode 100644 index 0000000..a56dcbc --- /dev/null +++ b/cgi-bin/uebung08/img/fish-1.svg @@ -0,0 +1,237 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-2.svg b/cgi-bin/uebung08/img/fish-2.svg new file mode 100644 index 0000000..cc73dae --- /dev/null +++ b/cgi-bin/uebung08/img/fish-2.svg @@ -0,0 +1,227 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-3.svg b/cgi-bin/uebung08/img/fish-3.svg new file mode 100644 index 0000000..e4f7b51 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-3.svg @@ -0,0 +1,227 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-4.svg b/cgi-bin/uebung08/img/fish-4.svg new file mode 100644 index 0000000..9da84cf --- /dev/null +++ b/cgi-bin/uebung08/img/fish-4.svg @@ -0,0 +1,227 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-5.svg b/cgi-bin/uebung08/img/fish-5.svg new file mode 100644 index 0000000..0750149 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-5.svg @@ -0,0 +1,226 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-6.svg b/cgi-bin/uebung08/img/fish-6.svg new file mode 100644 index 0000000..f349792 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-6.svg @@ -0,0 +1,230 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-7.svg b/cgi-bin/uebung08/img/fish-7.svg new file mode 100644 index 0000000..db50564 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-7.svg @@ -0,0 +1,241 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-8.svg b/cgi-bin/uebung08/img/fish-8.svg new file mode 100644 index 0000000..c727781 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-8.svg @@ -0,0 +1,237 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cgi-bin/uebung08/img/fish-9.svg b/cgi-bin/uebung08/img/fish-9.svg new file mode 100644 index 0000000..8d9d055 --- /dev/null +++ b/cgi-bin/uebung08/img/fish-9.svg @@ -0,0 +1,378 @@ + + + + + + + + Thought Balloon + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +