array(array(string)) // ... return $mat; } function afficher_labyrinthe($lig, $col, $mat) { // int int array(array(string)) -> none debut_table('laby'); for($i=0; $i < count($mat); $i++) { // ligne debut_table_ligne(); for($j=0; $j < count($mat[$i]); $j++) { // colonne if($lig == $i and $col == $j) { afficher_table_donnee('O'); } else { afficher_table_donnee($mat[$i][$j]); } } fin_table_ligne(); } fin_table('laby'); // faire un style avec une largeur de case } function afficher_bouton($nom, $texte) { debut_formulaire($nom, 'labyrinthe.php'); fin_formulaire($nom, $texte); } function afficher_boutons() { debut_table('dirs'); debut_table_ligne(); debut_table_donnee(); afficher_bouton('haut', '^'); fin_table_donnee(); // ... fin_table_ligne(); fin_table('dirs'); afficher_bouton('recommencer', 'Recommencer'); } // A FAIRE : devrait renvoyer 'OK' ou un message d'erreur si mouvement impossible // (plus habituel mais moins intuitif : renverrait false si ok, et un message d'erreur sinon) function bouger($dir) { // string -> none $lig = $_SESSION['lig']; $col = $_SESSION['col']; $mat = $_SESSION['matrice']; if($dir == 'haut') { $lig--; } else if($dir == 'bas') { $lig++; } else if($dir == 'gauche') { $col--; } else if($dir == 'droite') { $col++; } if($mat[$lig][$col] == '') { $_SESSION['lig'] = $lig; $_SESSION['col'] = $col; } else if($mat[$lig][$col] == '*') { printline('Vous avez gagné !'); } else { printline('Mouvement impossible'); } } function initialiser() { session_unset(); $_SESSION['lig'] = 1; $_SESSION['col'] = 1; $_SESSION['matrice'] = creer_matrice(5, 10); } function main($id_bouton) { $mat1 = array( array('a', 'b', 'c', 'd'), array('1', '2', '3', '4'), array('w', 'x', 'y', 'z') ); // afficher_labyrinthe(-1, -1, $mat1); if(!array_key_exists('lig', $_SESSION)) { initialiser(); } if($id_bouton == 'recommencer') { initialiser(); } bouger($id_bouton); afficher_labyrinthe($_SESSION['lig'], $_SESSION['col'], $_SESSION['matrice']); afficher_boutons(); } ?>