Bonjour, je fais un jeux d'allumettes je voudrais savoir comment faire pour creer un enregistrement de tableau en ocaml. J'ai déjà fait mon enregistrement d'allumettes.
Bonjour, je fais un jeux d'allumettes je voudrais savoir comment faire pour creer un enregistrement de tableau en ocaml. J'ai déjà fait mon enregistrement d'allumettes.
Bonsoir, nous ne pouvons pas vous aider si vous ne mettez aucune autre information. Il faudrait déjà qu'on puisse voir ce que vous avez déjà fait
Cordialement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
75 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; };; type status = { mouse_x : int; mouse_y : int; button : bool; keypressed : bool; key : char; };; type event = |Button_down | Button_up |Key_pressed | Mouse_motion | Poll ;; #load "graphics.cma" ;; Graphics.open_graph " 800x440";; Graphics.set_window_title "Jeu de Batonnets";; let vertforet = Graphics.rgb 0 128 0;; 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 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 v = Array.make 20 allum;; 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;;
Voici le code que j'ai fait maintenant je veux faire bouger les alllumettes mais je ne sais pas comment faire pour integrer la gestion des évènements. Par exemple faire bouger une allumettes par clic de la souris
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
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 ())Une fois que vous aurez essayé de les manipuler, nous verrons si vous avez encore des questions.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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
[EDIT] J'ai réécrit votre code, ça me faisait trop mal
Code : Sélectionner tout - Visualiser dans une fenêtre à part ocamlc -o monexec graphics.cma monfichier.ml
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager