function gameCheck() { if (strlen($_SESSION['word']) == count($_SESSION['guesses'])) { echo "Du vann!"; resetGame(); } elseif ($_SESSION['lifes'] == 0) { echo "Du förlorade!"; resetGame(); } }
if (isset($_POST['guess']) && $position !== false) { $_SESSION['guesses'][$position] = $guess; echo "Du gissade rätt!<br>"; } elseif (isset($_POST['guess'])) { echo "Du gissade fel!<br> {$guess} finns inte i ordet!<br>"; $_SESSION['lifes'] = $_SESSION['lifes'] - 1; } echo "Du har " . $_SESSION['lifes'] . " liv kvar.<br>"; printWord($word, $_SESSION['guesses']); //print_r($_SESSION); if (strlen($word) == count($_SESSION['guesses'])) { echo "Du vann!"; resetGame(); } elseif ($_SESSION['lifes'] == 0) { echo "Du förlorade!"; resetGame(); } } function resetGame() { unset($_SESSION['word']); unset($_SESSION['guesses']); } function printWord($word, $guesses) { $length = strlen($word); for ($i = 0; $i <= $length - 1; $i++) { if (isset($guesses[$i])) { echo $guesses[$i] . " "; } else { echo "_ ";