1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| type tete = {
mutable cx : int;
mutable cy : int;
mutable rayon : int;
mutable teteCol : Graphics.color
}
type tige = {
mutable tx : int;
mutable ty : int;
mutable tLargeur : int;
mutable tHauteur : int;
mutable tigeCol : Graphics.color
}
type allumette = {
mutable haut : tete;
mutable bas : tige;
mutable choisi : bool
}
type joueur = Humain | Ordinateur
type jeux ={
allumettes : allumette array;
nbAlluTotal : int;
nbAlluRestant : int;
nbMaxARetirer : int ;
mutable joueur1 : joueur;
mutable joueur2 : joueur;
tourJoueur : bool;
}
let vertforet = Graphics.rgb 0 128 0
let allum=
{bas = {tx = 20; ty = 200; tLargeur = 2; tHauteur = 40;
tigeCol = Graphics.white};
haut = {cx = 21; cy = 240; rayon = 4; teteCol = Graphics.red};
choisi = true}
let dessiner allu =
Graphics.set_color allu.bas.tigeCol;
Graphics.fill_rect allu.bas.tx allu.bas.ty
allu.bas.tLargeur allu.bas.tHauteur;
Graphics.set_color allu.haut.teteCol;
Graphics.fill_circle allu.haut.cx allu.haut.cy allu.haut.rayon
let () =
Graphics.open_graph " 800x440";
Graphics.set_window_title "Jeu de Batonnets";
Graphics.set_color vertforet;
Graphics.fill_rect 0 70 800 300;
Graphics.set_color Graphics.red;
Graphics.draw_rect 0 69 801 301;
Graphics.moveto 0 69; Graphics.lineto 0 0; Graphics.lineto 801 0;
Graphics.lineto 801 69; Graphics.moveto 0 301; Graphics.lineto 0 440;
Graphics.lineto 801 440; Graphics.lineto 801 301;Graphics.moveto 25 40;
Graphics.draw_string "Batons";Graphics.moveto 20 20;
Graphics.draw_string "restants :";Graphics.moveto 110 50;
Graphics.draw_string "Maximum de";Graphics.moveto 105 40;
Graphics.draw_string "batons que vous:";
let v = Array.make 20 allum in
for i = 1 to Array.length v - 1 do
v.(i) <- {bas={tx=20 + i*(760/20); ty=200; tLargeur=2;
tHauteur=40; tigeCol=Graphics.white};
haut ={cx=(21 + 1) + i*(760/20);cy=240; rayon=4;
teteCol=Graphics.red};
choisi=true};
done;
for i=0 to 19 do
dessiner v.(i);
done;
ignore (Graphics.read_key ()) |
Premièrement, vous n'avez pas besoin de redéfinir les types event et status étant donné qu'ils sont dans Graphics. De plus, je vous invite à regarder les fonctions
1 2 3 4 5 6 7 8
| val wait_next_event : event list -> status
Wait until one of the events specified in the given event list occurs, and return the status of the mouse and keyboard at that time. If Poll is given in the event list, return immediately with the current status. If the mouse cursor is outside of the graphics window, the mouse_x and mouse_y fields of the event are outside the range 0..size_x()-1, 0..size_y()-1. Keypresses are queued, and dequeued one by one when the Key_pressed event is specified.
val loop_at_exit : event list -> (status -> unit) -> unit
Loop before exiting the program, the list given as argument is the list of handlers and the events on which these handlers are called. To exit cleanly the loop, the handler should raise Exit. Any other exception will be propagated outside of the loop.
Since 4.01 |
Une fois que vous aurez essayé de les manipuler, nous verrons si vous avez encore des questions. 
Cordialement.
P.S. Il semble que vous fassiez tout cela dans le toplevel (donc l'interpréteur ocaml). Il faudrait penser à créer un fichier .ml et à le compiler. La directive de compilation est
ocamlc -o monexec graphics.cma monfichier.ml
[EDIT] J'ai réécrit votre code, ça me faisait trop mal
Partager