(* ===================================================== *)
(*      Apprentissage de la programmation avec OCaml     *)
(*      Catherine Dubois & Valérie Ménissier-Morain      *)
(*                Éditions Hermès Sciences               *)
(*                        Mars 2004                      *)
(* ===================================================== *)
(* Fichier MLSRC/CC/CC_base_modulaire/affichage_jeu.ml   *)
(* ===================================================== *)

open Representation;;
open Graphics;;
open Affichage_base;;

open_graph "";;
set_window_title "Court circuit";;

let espace_pièces = 8;;

let largeur_zone_de_jeu =
  colonnes*taille_pièce+(colonnes-1)*espace_pièces
and hauteur_zone_de_jeu =
  lignes*taille_pièce+(lignes-1)*espace_pièces;;

let espace_horizontal = (size_x()-largeur_zone_de_jeu)/2
and espace_vertical = (size_y()-hauteur_zone_de_jeu)/2;;

let dessiner_zone_de_jeu () =
  let x = ref espace_horizontal
  and y = ref espace_vertical in
  (* où placer le coin en bas à gauche de la zone de jeu *)
   for c = débutc to finc do
     for
 l = débutl to finl do
       begin match
 zone_de_jeu.(c).(l) with
       | Vide -> ()
       | Occupée couleur -> dessiner_pièce (!x, !y) couleur
       end;
       y := !y+taille_pièce+espace_pièces;
    done;
    y := espace_vertical;
    x := !x+taille_pièce+espace_pièces
  done;;

let coordonnées_centre_pièce (c,l) =
  (espace_horizontal+(c-1)*taille_pièce+
   (c-1)*espace_pièces+taille_pièce/2,
   espace_vertical+(l-1)*taille_pièce+
   (l-1)*espace_pièces+taille_pièce/2);;

let dessiner_circuit circuit =
  match List.map coordonnées_centre_pièce circuit with
  | [] -> ()
  | (x,y)::circuit' ->
    set_line_width 3; moveto x y;
    List.iter (function (x,y) -> lineto x y) circuit';
    set_line_width 1;;

let coordonnées_pièce (c,l) =
  (espace_horizontal+(c-1)*taille_pièce+(c-1)*espace_pièces,
   espace_vertical+(l-1)*taille_pièce+(l-1)*espace_pièces);;

let effacer_pièce_sélectionnée (c,l) =
  let (x, y) = coordonnées_pièce (c,l) in
  set_color background;
  fill_rect x y taille_pièce taille_pièce;
  dessiner_sélection (x, y);
  set_color foreground;;

let effacer_circuit circuit =
  set_color background;
  dessiner_circuit circuit;
  set_color foreground;;

let écrire_pas_de_circuit () =
  print_string "pas de circuit entre ces pièces\n";;

Ce document a été traduit de LATEX par HEVEA.