Files
intecsync/cgi-bin/uebung08/hangman.php
2019-06-30 23:02:48 +02:00

60 lines
1.0 KiB
PHP

<?php
session_name(get_current_user() . "hangman");
session_start();
if (!isset($_SESSION['toGuess'])) {
header("Location: hangman-init.php");
}
$mask = implode(" ", $_SESSION['mask']);
echo <<<END
<h1>Wörter raten</h1>
<p>$mask</p>
END;
echo <<<END
<form action="hangman-guess.php" method="post">
END;
//Output all buttons
$alphabet = range('A', 'Z');
foreach($alphabet as $abc) {
echo <<<END
<button name="letter" type="submit" value="$abc">$abc</button>
END;
}
echo <<<END
</form>
END;
//Show errorCount
$errors = $_SESSION['errorCount'];
echo <<<END
<p>$errors / 8</p>
END;
//Show the restart link
$state = $_SESSION['state'];
if ($state > 0) {
echo <<<END
<a href="hangman-init.php">Neues Spiel starten</a>
END;
}
if ($errors > 8 || 1 == 1) {
$guessword = $_SESSION['toGuess'];
echo <<<END
<p>Das richtige Wort wäre $guessword gewesen!</p>
END;
}
//HOW MUCH IS THE FISH
echo <<<END
<img src="img/fish-$errors.svg">
END;
?>