49 lines
1.0 KiB
PHP
49 lines
1.0 KiB
PHP
<?php
|
|
|
|
// startet die Session und initialisiert das tasks-Array
|
|
function startHangmanSession()
|
|
{
|
|
// Setze einen eindeutigen Session-Name: zdvlogin mit suffix todo
|
|
// get_current_user() liefert den Benutzernamen
|
|
session_name(get_current_user() . "hangman");
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['state'])) {
|
|
resetTasks();
|
|
}
|
|
}
|
|
|
|
// Löscht alle Session Daten
|
|
function resetTasks()
|
|
{
|
|
$_SESSION['state'] = [];
|
|
}
|
|
|
|
//Bringt ein Wort in das richtige Format
|
|
function transformWord($word) {
|
|
$word = strtoupper($word);
|
|
$word = str_replace("Ä", "AE", $word);
|
|
$word = str_replace("Ö", "OE", $word);
|
|
$word = str_replace("Ü", "UE", $word);
|
|
$word = str_replace("ß", "SS", $word);
|
|
|
|
return $word;
|
|
}
|
|
|
|
//Maskiert ein Wort mit _
|
|
function maskWord($word) {
|
|
$arr = array();
|
|
for ($i = 0; $i < strlen($word); $i++) {
|
|
$arr[] = "_";
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
function getAllWords() {
|
|
$str = file_get_contents("words-array.php");
|
|
return explode(", ", $str);
|
|
}
|
|
|
|
|
|
?>
|