(** {C Le jeu du {i same game}.} *) (** {1 Initialisation.} *) (** Initialise aléatoirement le tableau de jeu. *) let init_gb () = failwith "A FAIRE" (** {1 Fin de partie.} *) (** Vaut [true] si la partie est terminée: il ne reste plus aucune sélection possible. *) let end_game() = failwith "A FAIRE" (** {1 Sélections.} *) (** Marque la sélection déterminée par la pièce en [(icol, ilig)]. *) let mark_sel (icol, ilig) = failwith "A FAIRE" (** Vaut [true] si la pièce en [(icol, ilig)] n'est pas isolée. *) let valid_sel icol ilig = failwith "A FAIRE" (** {1 Suppression et compactage.} *) (** Supprime les pièces marquées de la colonne [col] et compacte les pièces restantes. *) let collapse_down col = failwith "A FAIRE" (** Supprime les pièces marquées du tableau et compacte les colonnes restantes. *) let collapse () = failwith "A FAIRE" (** {1 Déroulement du jeu.} *) (** Variable globale: mémorise la dernière action effectuée (voir fonction {! Jeu.game_act}). *) let last_act = ref Glob.Null (** Effectue une action de jeu selon l'évènement souris enregistré ({!Gui.click}) et la dernière action effectuée ({!Jeu.last_act}). *) let game_act () = let act = Gui.click() in match act with Glob.Null -> last_act := act | Glob.Quit -> failwith "quit" | Glob.Next -> ( (match !last_act with Glob.Sel _ -> (collapse(); Gui.redraw_gb Glob.gb) | _ -> ()); last_act := act ) | Glob.Sel (icol, ilig) -> ( if (valid_sel icol ilig) then ( (match !last_act with Glob.Sel (icol', ilig') -> mark_sel (icol', ilig') | _ -> ()); mark_sel (icol, ilig); Gui.redraw_gb Glob.gb; last_act := act ) ) (** Boucle de jeu. *) let rec game_loop() = if end_game() then ( match Gui.click() with Glob.Next -> ( init_gb(); Gui.draw_gb Glob.gb; Gui.draw_next_bt(); game_loop() ) | Glob.Quit -> ( Format.printf"\n End of game@."; Graphics.close_graph() ) | _ -> game_loop() ) else ( game_act(); game_loop() ) (** Lancement du jeu. *) let main () = try ( Graphics.open_graph (Printf.sprintf" %dx%d" Gui.gw_width Gui.gw_height); Gui.draw_next_bt(); Gui.draw_quit_bt(); init_gb(); Gui.draw_gb Glob.gb; last_act := Glob.Null; game_loop() ) with Failure "quit" -> Graphics.close_graph() (**/**) ;; main()