Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / examples / grazyna.xmp / dominate.log
1 program dominate;\r
2 \r
3 Unit elem:class;\r
4 var couleur:integer,x:integer,y:integer;\r
5 end elem;\r
6 \r
7 Unit init_tab:procedure;\r
8 var i,j,valx,valy:integer;\r
9 begin\r
10 (* INITIALISATION DES COULEURS *)\r
11 for i:=-1 to 10\r
12 do\r
13      for j:=-1 to 10\r
14      do\r
15           tab(i,j):=new elem;\r
16           verif(i,j):=new elem;\r
17           tab(i,j).couleur:=0;\r
18           verif(i,j).couleur:=0;\r
19           \r
20      od;\r
21 od;\r
22 for i:=-2 to 11\r
23 do\r
24      for j:=-2 to 11\r
25      do\r
26           simul(i,j):=new elem;\r
27           simul(i,j).couleur:=0;\r
28      od;\r
29 od;\r
30 tab(1,1).couleur:=1;\r
31 tab(8,8).couleur:=1;\r
32 tab(8,1).couleur:=2;\r
33 tab(1,8).couleur:=2;\r
34 verif(1,1).couleur:=1;\r
35 verif(8,8).couleur:=1;\r
36 verif(8,1).couleur:=2;\r
37 verif(1,8).couleur:=2;\r
38 (* INITIALISATION DES POSITIONS *)\r
39 valx:= 120;\r
40 valy:= 50;\r
41 for i:=-1 to 10\r
42 do\r
43      tab(-1,i).x:=0;\r
44      tab(i,-1).x:=0;\r
45      tab(-1,i).x:=0;\r
46      tab(i,-1).x:=0;\r
47 od;\r
48 for i:=-1 to 10\r
49 do\r
50      tab(10,i).x:=0;\r
51      tab(i,10).x:=0;\r
52      tab(10,i).x:=0;\r
53      tab(i,10).x:=0;\r
54 od;\r
55 \r
56 for i:=1 to 8\r
57 do\r
58      for j:=1 to 8\r
59      do\r
60           tab(i,j).x := valx;\r
61           tab(i,j).y := valy;\r
62           valx:=valx+50;\r
63      od;\r
64      valx:=120;\r
65      valy:=valy+50;\r
66 od;     \r
67 end init_tab;\r
68 \r
69 Unit aff_tab:procedure;\r
70 var i,j:integer;\r
71 begin\r
72 for i:=1 to 8\r
73 do\r
74      for j:=1 to 8\r
75      do\r
76           write(tab(i,j).couleur);\r
77      od;\r
78      writeln;\r
79 od;\r
80 end aff_tab;\r
81 \r
82 Unit aff_simul:procedure;\r
83 var i,j:integer;\r
84 begin\r
85 for i:=1 to 8\r
86 do\r
87      for j:=1 to 8\r
88      do\r
89           write(simul(i,j).couleur);\r
90      od;\r
91      writeln;\r
92 od;\r
93 end aff_simul;\r
94 \r
95 Unit aff_verif:procedure;\r
96 var i,j:integer;\r
97 begin\r
98 for i:=1 to 8\r
99 do\r
100      for j:=1 to 8\r
101      do\r
102           write(verif(i,j).couleur);\r
103      od;\r
104      writeln;\r
105 od;\r
106 end aff_verif;\r
107 \r
108 \r
109 Unit creatab:procedure;\r
110 var i:integer;\r
111 begin\r
112 array tab dim(-1:10);\r
113         for i:=-1 to 10\r
114         do\r
115         array tab(i) dim(-1:10);\r
116         od;\r
117 array verif dim(-1:10);\r
118         for i:=-1 to 10\r
119         do\r
120         array verif(i) dim(-1:10);\r
121         od;\r
122 array simul dim(-2:11);\r
123         for i:=-2 to 11\r
124         do\r
125         array simul(i) dim(-2:11);\r
126         od;\r
127 \r
128 end creatab;\r
129 \r
130 unit recopie : procedure;\r
131 var i,j:integer;\r
132 begin\r
133 for i:=-1 to 10\r
134 do\r
135      for j:=-1 to 10\r
136      do\r
137      simul(i,j).couleur:=tab(i,j).couleur;\r
138      od;\r
139 od;\r
140 end recopie;\r
141 \r
142 unit ecran : procedure;\r
143 begin\r
144  pref IIUWGRAPH block\r
145  \r
146  unit sortie:procedure;\r
147   begin\r
148      call groff;\r
149  end sortie;\r
150  \r
151  var i:integer,rep:char ;\r
152  begin\r
153  pref MOUSE block\r
154   \r
155      unit presentation:procedure;\r
156      begin\r
157      call bouton(110,150,530,330);\r
158      call outstring(230,220,"     PROJET nø2 DE LI1     ",15,7);\r
159      call outstring(230,240,"DOMINATE : jeu de strategie",15,7);\r
160      call outstring(0,0,"ANTON JEAN-FRANCOIS",15,0);\r
161      call outstring(0,20,"LAVIGNOTTE SEBASTIEN",15,0);\r
162      call outstring(0,40,"Licence Informatique - Groupe II",15,0);\r
163      call outstring(0,60,"Annee universitaire 1994/1995",15,0);\r
164      call outstring(200,450,"Appuyer sur le bouton GAUCHE de votre souris...",15,0);\r
165  \r
166      (* Attente de l'appui de la souris *)\r
167      while (Num_Mouse <> 1)\r
168      do\r
169         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
170      od;\r
171  \r
172      call cls;\r
173      call cadre;\r
174      call menu0;\r
175      end presentation;\r
176      \r
177      unit finir : procedure;\r
178      var i,j:integer,modifie :boolean;\r
179      begin\r
180      modifie:=false;\r
181      if num_joueur=1 then num_joueur:=2;\r
182      else num_joueur:=1;\r
183      \r
184      fi;\r
185      for i:=1 to 8\r
186      do\r
187           for j:=1 to 8\r
188           do\r
189           if tab(i,j).couleur=0 \r
190           then \r
191                tab(i,j).couleur:=num_joueur;\r
192                modifie:=true;\r
193           fi;\r
194           if modifie\r
195           then\r
196                call affic;\r
197                call compte;\r
198           modifie:=false;\r
199           fi;\r
200           od;\r
201      od;\r
202         call compte;\r
203         call affic;\r
204           call finjeu;\r
205      \r
206      end finir;\r
207 \r
208      unit finjeu : procedure;\r
209      begin\r
210      call bouton(214,200,428,320);\r
211      if ( nombre1 > nombre2 ) then\r
212      call outstring(250,230,"VAINQUEUR : JOUEUR 1",15,7);\r
213      else\r
214      call outstring(250,230,"VAINQUEUR : JOUEUR 2",15,7);\r
215      fi;\r
216      call bouton(270,270,380,300);\r
217      call outstring(280,280,"cliquez ici",15,7);   \r
218      while (Num_Mouse<>3)\r
219      do\r
220         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
221         if num_mouse = 1 then\r
222            if (x_s>=270 and x_s<=380) and (y_s>=270 and y_s<=300)\r
223               then  call cls;\r
224                     call cadre;\r
225                     call menu0;\r
226            fi;\r
227         fi;\r
228      od;\r
229      end finjeu;\r
230 \r
231      unit tirage : procedure;\r
232      var x:real,i,premier:integer;\r
233      begin\r
234      premier:=0;\r
235      call bouton(214,200,428,320);\r
236      call outstring(265,230,"Tirage au sort",15,7);\r
237      x:=random;\r
238      if (x>=0 and x<0.5) then premier:=1;fi;\r
239      if (x>=0.5 and x<1) then premier:=2;fi;\r
240      for i:=1 to 1000\r
241      do\r
242           call outstring(321,285,"³",15,7);\r
243           call outstring(321,285,"\",15,7);\r
244           call outstring(321,285," ",15,7);\r
245           call outstring(321,285,"Ä",15,7);\r
246           call outstring(321,285,"/",15,7);\r
247           call outstring(321,285," ",15,7);\r
248      od;\r
249      if (premier=1) then\r
250      call outstring(220,285,"Le JOUEUR 1 va commencer",15,7);\r
251      num_joueur:=1;\r
252      else call outstring(220,285,"Le JOUEUR 2 va commencer",15,7);\r
253      num_joueur:=2;\r
254      fi;\r
255      call bouton(250,250,360,280);\r
256      call outstring(260,260,"cliquez ici",15,7);   \r
257      while (Num_Mouse<>3)\r
258      do\r
259         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
260         if num_mouse = 1 then\r
261            if (x_s>=250 and x_s<=360) and (y_s>=240 and y_s<=270)\r
262               then  call cls;\r
263                     call cadre;\r
264                     if num_joueur=1 then\r
265                          case type1\r
266                          when 1 : call tourjeu;\r
267                          when 2 : call expansion;\r
268                          when 3 : call destruction;\r
269                          esac;\r
270                     else\r
271                          case type2\r
272                          when 1 : call tourjeu;\r
273                          when 2 : call expansion;\r
274                          when 3 : call destruction;\r
275                          esac;\r
276                     fi;\r
277            fi;\r
278         fi;\r
279      od;\r
280      end tirage;\r
281         \r
282      unit info1 : procedure;\r
283      begin\r
284      call patern(10,100,20,110,4,1);\r
285      call outstring(30,100,"JOUEUR 1",4,0);\r
286      call patern(100,100,110,110,4,1);\r
287      call outstring(10,150,"POINTS : ",4,0);\r
288      call track(80,150,nombre1,0,4); \r
289      end info1;\r
290 \r
291      unit info2 : procedure;\r
292      begin\r
293      call patern(530,100,540,110,9,1);\r
294      call outstring(550,100,"JOUEUR 2",9,0);\r
295      call patern(620,100,630,110,9,1);\r
296      call outstring(530,150,"POINTS : ",9,0);\r
297      call track(600,150,nombre2,0,9);\r
298      end info2;\r
299      \r
300      unit erreur : procedure;\r
301      begin\r
302      call patern(0,460,640,479,10,1);\r
303      call outstring(260,465,"COUP IMPOSSIBLE A REALISER",15,10);\r
304         call cls;\r
305         call cadre;\r
306         call tourjeu;\r
307      end erreur;\r
308      \r
309      unit choix : procedure;\r
310      begin\r
311      call bouton(189,175,453,345);\r
312      call point(321,177);\r
313      call draw(321,343);\r
314      call outstring(223,185,"JOUEUR 1",0,7);\r
315      call outstring(200,210,"humain",0,7);\r
316      call patern(305,210,315,225,15,1);\r
317      call outstring(200,240,"expansion",0,7);\r
318      call patern(305,240,315,255,15,1);\r
319      call outstring(200,270,"destruction",0,7);\r
320      call patern(305,270,315,285,15,1);\r
321      call outstring(355,185,"JOUEUR 2",0,7);\r
322      call outstring(332,210,"humain",0,7);\r
323      call patern(437,210,447,225,15,1);\r
324      call outstring(332,240,"expansion",0,7);\r
325      call patern(437,240,447,255,15,1);\r
326      call outstring(332,270,"destruction",0,7);\r
327      call patern(437,270,447,285,15,1);\r
328      call bouton(306,300,336,320);\r
329      call outstring(315,305,"OK",15,7);\r
330      case type1\r
331      when 1 : call outstring(306,211,"X",0,15);\r
332      when 2 : call outstring(306,241,"X",0,15);\r
333      when 3 : call outstring(306,271,"X",0,15);\r
334      esac;\r
335      case type2\r
336      when 1 : call outstring(438,211,"X",0,15);\r
337      when 2 : call outstring(438,241,"X",0,15);\r
338      when 3 : call outstring(438,271,"X",0,15);\r
339      esac;\r
340      while (Num_mouse <> 3)\r
341      do\r
342      Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
343         if num_mouse = 1 then\r
344            if (x_s>=306 and x_s<=336) and (y_s>=300 and y_s<=320)\r
345               then  call cls;\r
346                     call cadre;\r
347                     call tirage;\r
348            fi;\r
349           if (x_s>=305 and x_s<=315) and (y_s>=210 and y_s<=220)\r
350               then  call patern(305,210,315,225,15,1);\r
351                     call patern(305,240,315,255,15,1);\r
352                     call patern(305,270,315,285,15,1);\r
353                     call outstring(306,211,"X",0,15);\r
354                     type1:=1;\r
355            fi;\r
356           if (x_s>=305 and x_s<=315) and (y_s>=240 and y_s<=250)\r
357               then  call patern(305,210,315,225,15,1);\r
358                     call patern(305,240,315,255,15,1);\r
359                     call patern(305,270,315,285,15,1);\r
360                     call outstring(306,241,"X",0,15);\r
361                     type1:=2;\r
362            fi;\r
363           if (x_s>=305 and x_s<=315) and (y_s>=270 and y_s<=280)\r
364               then  call patern(305,210,315,225,15,1);\r
365                     call patern(305,240,315,255,15,1);\r
366                     call patern(305,270,315,285,15,1);\r
367                     call outstring(306,271,"X",0,15);\r
368                     type1:=3;\r
369            fi;\r
370           if (x_s>=437 and x_s<=447) and (y_s>=210 and y_s<=220)\r
371               then  call patern(437,210,447,225,15,1);\r
372                     call patern(437,240,447,255,15,1);\r
373                     call patern(437,270,447,285,15,1);\r
374                     call outstring(438,211,"X",0,15);\r
375                     type2:=1;\r
376            fi;\r
377           if (x_s>=437 and x_s<=447) and (y_s>=240 and y_s<=250)\r
378               then  call patern(437,210,447,225,15,1);\r
379                     call patern(437,240,447,255,15,1);\r
380                     call patern(437,270,447,285,15,1);\r
381                     call outstring(438,241,"X",0,15);\r
382                     type2:=2;\r
383            fi;\r
384           if (x_s>=437 and x_s<=447) and (y_s>=270 and y_s<=280)\r
385               then  call patern(437,210,447,225,15,1);\r
386                     call patern(437,240,447,255,15,1);\r
387                     call patern(437,270,447,285,15,1);\r
388                     call outstring(438,271,"X",0,15);\r
389                     type2:=3;\r
390            fi;\r
391 \r
392         fi;\r
393      od; \r
394      \r
395      end choix;\r
396      \r
397      unit aide : procedure;\r
398      begin\r
399 call bouton(10,50,632,460);\r
400 call outstring(304,80,"AIDE",15,7);\r
401 call point(300,95);\r
402 call draw(336,95);\r
403 call outstring(20,110,"CONTROLE ET REGLE DU JEU",15,7);\r
404 call outstring(20,125,"Bienvenue sur DOMINATE. Ce jeu est bas\82 sur les r\8agles du",0,7); \r
405 call outstring(20,140,"tr\8as vieux et tr\8as c\82l\8abre 'GO'. C'est donc un jeu de",0,7); \r
406 call outstring(20,155,"strat\82gie de plateau o\97 le but est de recouvrir un",0,7);\r
407 call outstring(20,170,"maximum d'espaces avec la couleur de votre joueur.",0,7);\r
408 call outstring(20,185,"MOUVEMENT DURANT LE JEU",15,7);\r
409 call outstring(20,200,"Quand c'est votre tour de jouer, choisissez simplement la",0,7);\r
410 call outstring(20,215,"pi\8ace \85 bouger en cliquant dessus \85 l'aide du bouton",0,7);\r
411 call outstring(20,230,"gauche de la souris. Durant le jeu, il est possible de",0,7);\r
412 call outstring(20,245,"bouger sur une case voisine dans n'importe quelle",0,7); \r
413 call outstring(20,260,"direction ou sauter horizontalement et verticalement par",0,7);\r
414 call outstring(20,275,"dessus un obstacle. Si vous sautez, l'espace par dessus",0,7);\r
415 call outstring(20,290,"lequel vous bougez garde son \82tat initial, malgr\82 que la",0,7);\r
416 call outstring(20,305,"case de destination change de couleur.",0,7);\r
417 call outstring(20,320,"Apr\82s votre mouvement toutes les pi\8aces adversaires ",0,7);\r
418 call outstring(20,335,"voisines \85 la case de destination deviennent de votre",0,7); \r
419 call outstring(20,350,"couleur.",0,7);\r
420 call outstring(20,365,"GAGNER UNE PARTIE",15,7);\r
421 call outstring(20,380,"Lorsque toutes les cases du plateau sont utilis\82es, ou si",0,7);\r
422 call outstring(20,395,"un des deux joueurs ne peut plus bouger, l'ordinateur",0,7);\r
423 call outstring(20,410,"remplit les cases libres, en correspondance avec les",0,7);\r
424 call outstring(20,425,"mouvements de chaque joueur, le joueur qui poss\8ade alors",0,7);\r
425 call outstring(20,440," le plus de cases du plateau est le vainqueur.",0,7); \r
426 call bouton(490,390,600,420);\r
427      call outstring(500,400,"cliquez ici",15,7);   \r
428      while (Num_Mouse<>3)\r
429      do\r
430         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
431         if num_mouse = 1 then\r
432            if (x_s>=490 and x_s<=600) and (y_s>=390 and y_s<=420)\r
433               then  call cls;\r
434                     call cadre;\r
435                     call menu0; \r
436            fi;\r
437         fi;\r
438      od;\r
439      end aide;\r
440 \r
441      unit cadre : procedure;\r
442      var i,j:integer;\r
443      begin\r
444      if num_joueur=1 then call patern(25,95,95,115,15,0);\r
445      else call patern(545,95,615,115,15,0);\r
446      fi;        \r
447      call bouton(5,5,640,30);\r
448      call outstring(20,13,"QUITTER",15,7);\r
449      call outstring(125,13,"JEU",15,7);\r
450      call outstring(200,13,"AIDE",15,7);\r
451      call info1;\r
452      call info2;\r
453      for i:=1 to 8\r
454      do\r
455           for j:=1 to 8\r
456           do\r
457                call patern(tab(i,j).x,tab(i,j).y,tab(i,j).x+50,tab(i,j).y+50,15,0);\r
458                           \r
459           od;\r
460      od;\r
461         for i:=1 to 8\r
462      do\r
463           for j:=1 to 8\r
464           do\r
465                case tab(i,j).couleur\r
466                when 0 : ;\r
467                when 1 : call patern(tab(i,j).x+1,tab(i,j).y+1,tab(i,j).x+49,tab(i,j).y+49,4,1);\r
468                when 2 : call patern(tab(i,j).x+1,tab(i,j).y+1,tab(i,j).x+49,tab(i,j).y+49,9,1);\r
469                when 3 : call patern(tab(i,j).x,tab(i,j).y,tab(i,j).x+50,tab(i,j).y+50,2,0);\r
470                when 4 : call patern(tab(i,j).x,tab(i,j).y,tab(i,j).x+50,tab(i,j).y+50,14,0);\r
471                esac; \r
472                \r
473                \r
474           od;\r
475      od;\r
476      end cadre;\r
477 \r
478      unit affic : procedure;\r
479      var i,j:integer;\r
480      begin\r
481      if num_joueur=1 then call patern(25,95,95,115,15,0);\r
482                           call patern(545,95,615,115,0,0);              \r
483      else call patern(545,95,615,115,15,0);\r
484           call patern(25,95,95,115,0,0);\r
485      fi;        \r
486      call patern(79,149,95,172,0,1);    \r
487      call track(80,150,nombre1,0,4);\r
488      call patern(599,149,615,172,0,1);\r
489      call track(600,150,nombre2,0,9);\r
490      for i:=1 to 8\r
491      do\r
492           for j:=1 to 8\r
493           do\r
494                case tab(i,j).couleur\r
495                when 0 : call patern(tab(i,j).x+1,tab(i,j).y+1,tab(i,j).x+49,tab(i,j).y+49,0,1);\r
496                when 1 : call patern(tab(i,j).x+1,tab(i,j).y+1,tab(i,j).x+49,tab(i,j).y+49,4,1);\r
497                when 2 : call patern(tab(i,j).x+1,tab(i,j).y+1,tab(i,j).x+49,tab(i,j).y+49,9,1);\r
498                when 3 : call patern(tab(i,j).x,tab(i,j).y,tab(i,j).x+50,tab(i,j).y+50,2,0);\r
499                when 4 : call patern(tab(i,j).x,tab(i,j).y,tab(i,j).x+50,tab(i,j).y+50,14,0);\r
500                esac; \r
501                \r
502                \r
503           od;\r
504      od;\r
505      end affic;\r
506      unit vraiquit : procedure;\r
507      begin\r
508      call bouton(214,200,428,320);\r
509      call outstring(290,230,"QUITTER ?",15,7);\r
510      call bouton(250,300,300,280);\r
511      call outstring(260,285,"OUI",15,7);\r
512      call bouton(342,300,392,280);\r
513      call outstring(352,285,"NON",15,7);\r
514      while (Num_Mouse<>3)\r
515      do\r
516         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
517         if num_mouse = 1 then\r
518            if (x_s>=250 and x_s<=300) and (y_s>=280 and y_s<=300)\r
519               then call groff;\r
520                     call endrun;\r
521            fi;\r
522         if (x_s>=342 and x_s<=392) and (y_s>=280 and y_s<=300)\r
523               then  call cls;\r
524                     call cadre;\r
525                     call menu0; \r
526         fi;\r
527            \r
528         fi;\r
529       od;\r
530      end vraiquit;\r
531 \r
532      unit noujeu : procedure;\r
533      begin\r
534      call bouton(214,200,428,320);\r
535      call outstring(270,230,"NOUVEAU JEU ?",15,7);\r
536      call bouton(250,300,300,280);\r
537      call outstring(260,285,"OUI",15,7);\r
538      call bouton(342,300,392,280);\r
539      call outstring(352,285,"NON",15,7);\r
540      while (Num_Mouse<>3)\r
541      do\r
542         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
543         if num_mouse = 1 then\r
544            if (x_s>=250 and x_s<=300) and (y_s>=280 and y_s<=300)\r
545               then call init_tab;\r
546                    call compte;\r
547                     call cls;\r
548                     call cadre;\r
549                     call choix;\r
550            fi;\r
551         if (x_s>=342 and x_s<=392) and (y_s>=280 and y_s<=300)\r
552               then  call cls;\r
553                         call cadre;\r
554                     call menu0;\r
555         fi;\r
556            \r
557         fi;\r
558       od;\r
559      end noujeu;\r
560 \r
561      unit menu0 : procedure;\r
562      var i:integer;\r
563      (*\r
564       * Affichage et gestion du premier\r
565       * menu utilisateur du programme.\r
566       *)\r
567      begin\r
568  \r
569      while (Num_Mouse<>3)\r
570      do\r
571         Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse) ;\r
572         if num_mouse = 1 then\r
573            if (x_s>=20 and x_s<=80) and (y_s>=5 and y_s<=30)\r
574               then call vraiquit;\r
575            fi;\r
576         if (x_s>=125 and x_s<=155) and (y_s>=5 and y_s<=30)\r
577               then  call noujeu;\r
578                            \r
579            fi;\r
580         if (x_s>=200 and x_s<=240) and (y_s>=5 and y_s<=30)\r
581               then call aide;        \r
582            fi;\r
583         \r
584         if (x_s>=120 and x_s<=520) and (y_s>=50 and y_s<=450)\r
585                 then\r
586                     if num_joueur=1 then\r
587                          case type1\r
588                          when 1 : call tourjeu;\r
589                          when 2 : call expansion;\r
590                          when 3 : call destruction;\r
591                          esac;\r
592                     else\r
593                          case type2\r
594                          when 1 : call tourjeu;\r
595                          when 2 : call expansion;\r
596                          when 3 : call destruction;\r
597                          esac;\r
598                     fi;\r
599         fi;\r
600         fi;\r
601       od;\r
602      \r
603      end menu0;\r
604      \r
605 \r
606     unit tourjeu : procedure;\r
607      var inter:integer;\r
608      begin\r
609      inter:=0;\r
610      fini:=false;\r
611      trouve:=false;\r
612         termine:=false;\r
613                 call remis0(tab);\r
614                 call remis0(verif);    \r
615                 call cadre;\r
616 possible:=false;\r
617 call verifjeu;\r
618 if (possible) then      \r
619                 while (not fini)\r
620                 do \r
621                   \r
622                   while (not trouve)\r
623                   do            \r
624                     Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse);\r
625                     if (num_mouse = 1) then\r
626                     if y_s <30 then call menu0;fi;\r
627                     call reccase1(x_s,y_s);\r
628                     fi;\r
629                   od;             \r
630                if (tab(coury,courx).couleur = num_joueur)\r
631                then\r
632                     call remis0(tab);\r
633                     call remis0(verif); \r
634                     call affpos;\r
635                     call affic;\r
636                 else call tourjeu;\r
637                fi; \r
638                                 \r
639                 while (not termine)\r
640                         do\r
641                     Mouse:=getpress(x_s,y_s,Keyb1,Keyb2,Flag,Num_Mouse);\r
642                     if (num_mouse = 1) then\r
643                     if y_s <30 then call menu0;fi;\r
644                     call reccase2(x_s,y_s);\r
645                     fi;\r
646                         od;\r
647                         if ( (indx=courx) and (indy=coury))\r
648                                 then call tourjeu;\r
649                         else\r
650                          \r
651                         if ((tab(indy,indx).couleur <>3) and (tab(indy,indx).couleur <>4)) \r
652                         then\r
653                                 call tourjeu;\r
654                         else\r
655                 \r
656                                 case tab(indy,indx).couleur \r
657                                 when 3 :tab(indy,indx).couleur:=num_joueur;\r
658                                 verif(indy,indx).couleur:=num_joueur;\r
659                                 fini:=true;\r
660                                 termine:=true;\r
661                                 call remis0(tab);\r
662                                 call remis0(verif);\r
663                                 call consequence;\r
664                                 call affic;\r
665                          \r
666                     \r
667                                 when 4 : tab(coury,courx).couleur:=0;\r
668                                 tab(indy,indx).couleur:=num_joueur;\r
669                                 verif(coury,courx).couleur:=0;\r
670                                 verif(indy,indx).couleur:=num_joueur;\r
671                                 fini:=true;\r
672                                 termine:=true;\r
673                                 call remis0(tab);\r
674                                 call remis0(verif);\r
675                                 call consequence;\r
676                                 call affic;\r
677                                 esac;               \r
678                fi;fi;\r
679                od;\r
680                call compte;     \r
681                if (fini) then\r
682                     if num_joueur=1 then num_joueur:=2;\r
683                        else \r
684                               num_joueur:=1;\r
685                                 \r
686                        fi;\r
687                 trouve:=false;\r
688                 termine:=false;\r
689                 call affic;\r
690                 if num_joueur=1 then\r
691                         courx:=1;coury:=1;\r
692                          case type1\r
693                          when 1 : call tourjeu;\r
694                          when 2 : call expansion;\r
695                          when 3 : call destruction;\r
696                          esac;\r
697                     else\r
698                          case type2\r
699                          when 1 : call tourjeu;\r
700                          when 2 : call expansion;\r
701                          when 3 : call destruction;\r
702                          esac;\r
703                     fi;\r
704                                                 \r
705                fi;     \r
706 else\r
707 call finir;\r
708 fi; \r
709     end tourjeu;\r
710 \r
711      unit expansion : procedure;\r
712      var i,j,a,b:integer,ok:boolean;\r
713      \r
714      begin\r
715      call verifjeu;\r
716      ok:=false;\r
717      if (possible)\r
718      then\r
719           for i:=1 to 8\r
720           do\r
721                for j:=1 to 8\r
722                do\r
723                     if tab(i,j).couleur=num_joueur\r
724                     then\r
725                          indy:=i;indx:=j;\r
726                          courx:=j;coury:=i;\r
727                          call affpos;\r
728                     fi;\r
729                od;\r
730           od;\r
731      for a:=1 to 8\r
732      do\r
733           for b:=1 to 8\r
734           do\r
735                if (tab(a,b).couleur = 3) then\r
736                 if (not ok) then\r
737                          tab(a,b).couleur:=num_joueur;\r
738                          verif(a,b).couleur:=num_joueur;\r
739                          ok:=true;\r
740                          call remis0(tab);\r
741                          call remis0(verif);\r
742                          indx:=b;indy:=a;\r
743                          call consequence;\r
744                          call affic;\r
745                          fi;\r
746               fi;\r
747           od;\r
748      od;\r
749                                  \r
750      for a:=1 to 8\r
751      do\r
752           for b:=1 to 8\r
753           do\r
754                case tab(a,b).couleur                         \r
755               when 4 : if (not ok) then\r
756                          tab(coury,courx).couleur:=0;\r
757                         tab(a,b).couleur:=num_joueur;\r
758                         verif(coury,courx).couleur:=0;\r
759                         verif(a,b).couleur:=num_joueur;\r
760                         ok:=true;\r
761                         call remis0(tab);\r
762                         call remis0(verif);\r
763                          indx:=b;indy:=a;\r
764                         call consequence;\r
765                         call affic;\r
766                          fi;\r
767                         esac;       \r
768          od;\r
769     od;\r
770                     \r
771           if (ok)\r
772           then\r
773           if num_joueur=1 then num_joueur:=2;\r
774                        else \r
775                               num_joueur:=1;\r
776                        fi;\r
777                 call compte;\r
778                 call affic;\r
779                 if num_joueur=1 then\r
780                          case type1\r
781                          when 1 : call tourjeu;\r
782                          when 2 : call expansion;\r
783                          when 3 : call destruction;\r
784                          esac;\r
785                     else\r
786                          case type2\r
787                          when 1 : call tourjeu;\r
788                          when 2 : call expansion;\r
789                          when 3 : call destruction;\r
790                          esac;     \r
791                 fi;\r
792           fi; \r
793      else\r
794           call finir;\r
795      fi;        \r
796              \r
797      end expansion;\r
798 \r
799      unit destruction : procedure;\r
800      var i,j,a,b,premx,premy,derx,dery,actuel : integer,teremi:boolean;\r
801      begin\r
802      call verifjeu;\r
803      if possible\r
804      then\r
805      call recopie;\r
806      teremi := false;\r
807      if num_joueur=1 then actuel:=nombre1;\r
808      else actuel:=nombre2;\r
809      fi;\r
810      for i:=1 to 8\r
811      do\r
812           for j:=1 to 8\r
813           do   call remis0(tab);\r
814                call recopie;\r
815                if tab(i,j).couleur=num_joueur\r
816                then\r
817                     indx:=j;indy:=i;\r
818                     call affpos;\r
819                     if (pos <> 0 )\r
820                     then\r
821                     for a:=i-2 to i+2\r
822                     do\r
823                          for b:=j-2 to j+2\r
824                          do\r
825                               if (a>=1 and a<=8) and (b>=1 and b<=8)\r
826                               then\r
827                               case tab(a,b).couleur \r
828                               when 3 : simul(a,b).couleur:=num_joueur;\r
829                                         ix:=b;iy:=a;\r
830                                         call cons;\r
831                                         call simcom;\r
832                                         if ( nomb > actuel )\r
833                                         then\r
834                                              premx:=j;premy:=i;\r
835                                              derx:=b;dery:=a;\r
836                                              actuel:=nomb;   \r
837                                         fi;\r
838                               when 4 : simul(a,b).couleur:=num_joueur;\r
839                                         simul(i,j).couleur:=0;\r
840                                         ix:=b;iy:=a;\r
841                                         call cons;\r
842                                         call simcom;\r
843                                         if ( nomb > actuel )\r
844                                         then\r
845                                              premx:=j;premy:=i;\r
846                                              derx:=b;dery:=a;\r
847                                              actuel:=nomb;   \r
848                                         fi;\r
849                               esac;\r
850                               call recopie;\r
851                               fi;\r
852                          od;\r
853                     od;\r
854                     fi;\r
855                fi;  \r
856           od;\r
857      call remis0(tab);\r
858      od;\r
859 \r
860      if (tab(premy,premx).couleur = num_joueur) then\r
861           indx:=premx;indy:=premy;\r
862           call affpos;\r
863           case tab(dery,derx).couleur\r
864                when 3 :  tab(dery,derx).couleur:=num_joueur;\r
865                          verif(dery,derx).couleur:=num_joueur;\r
866                          teremi:=true;\r
867                          call remis0(tab);\r
868                          call remis0(verif);\r
869                          indx:=derx;indy:=dery;\r
870                          call consequence;\r
871                          call affic;\r
872                when 4 : tab(premy,premx).couleur:=0;\r
873                         tab(dery,derx).couleur:=num_joueur;\r
874                         verif(premy,premx).couleur:=0;\r
875                         verif(dery,derx).couleur:=num_joueur;\r
876                         teremi:=true;\r
877                         call remis0(tab);\r
878                         call remis0(verif);\r
879                         indx:=derx;indy:=dery;\r
880                         call consequence;\r
881                         call affic;\r
882                         esac;            \r
883      fi;\r
884 \r
885      if (teremi)\r
886           then\r
887           if num_joueur=1 then num_joueur:=2;\r
888                        else \r
889                               num_joueur:=1;\r
890                        fi;\r
891                 call compte;\r
892                 call affic;\r
893                 if num_joueur=1 then\r
894                          case type1\r
895                          when 1 : call tourjeu;\r
896                          when 2 : call expansion;\r
897                          when 3 : call destruction;\r
898                          esac;\r
899                     else\r
900                          case type2\r
901                          when 1 : call tourjeu;\r
902                          when 2 : call expansion;\r
903                          when 3 : call destruction;\r
904                          esac;     \r
905                 fi;\r
906           fi;\r
907      else call finir;\r
908      fi; \r
909      call recopie;\r
910      call remis0(tab);\r
911      call remis0(verif);\r
912      end destruction;\r
913 \r
914      unit compte : procedure;\r
915      var\r
916      i,j,jou1,jou2:integer;\r
917      begin\r
918      jou1:=0;\r
919      jou2:=0;\r
920      for i:=1 to 8 \r
921      do\r
922      for j:=1 to 8\r
923           do \r
924           if tab(i,j).couleur=1 then jou1:=jou1+1;fi;\r
925           if tab(i,j).couleur=2 then jou2:=jou2+1;fi;\r
926           \r
927           od;\r
928      od;\r
929      nombre1:=jou1;\r
930      nombre2:=jou2;\r
931      end compte;\r
932 \r
933      unit simcom : procedure;\r
934      var\r
935      i,j,jou1,jou2:integer;\r
936      begin\r
937      jou1:=0;\r
938      jou2:=0;\r
939      for i:=1 to 8 \r
940      do\r
941           for j:=1 to 8\r
942           do \r
943                if simul(i,j).couleur=1 then jou1:=jou1+1;fi;\r
944                if simul(i,j).couleur=2 then jou2:=jou2+1;fi;\r
945           od;\r
946      od;\r
947      if num_joueur=1\r
948      then\r
949           nomb:=jou1;\r
950      else\r
951           nomb:=jou2;\r
952      fi;\r
953      end simcom;\r
954 \r
955      unit consequence : procedure;\r
956      begin\r
957      if tab(indy-1,indx-1).couleur<>0 then \r
958      tab(indy-1,indx-1).couleur:=num_joueur;\r
959      verif(indy-1,indx-1).couleur:=num_joueur;fi;\r
960      if tab(indy-1,indx).couleur<>0 then\r
961      tab(indy-1,indx).couleur:=num_joueur;\r
962      verif(indy-1,indx).couleur:=num_joueur;fi;\r
963      if tab(indy-1,indx+1).couleur<>0 then \r
964      tab(indy-1,indx+1).couleur:=num_joueur;\r
965      verif(indy-1,indx+1).couleur:=num_joueur;fi;\r
966      if tab(indy,indx-1).couleur<>0 then \r
967      tab(indy,indx-1).couleur:=num_joueur;\r
968      verif(indy,indx-1).couleur:=num_joueur;fi;\r
969      if tab(indy,indx+1).couleur<>0 then \r
970      tab(indy,indx+1).couleur:=num_joueur;\r
971      verif(indy,indx+1).couleur:=num_joueur;fi;\r
972      if tab(indy+1,indx-1).couleur<>0 then \r
973      tab(indy+1,indx-1).couleur:=num_joueur;\r
974      verif(indy+1,indx-1).couleur:=num_joueur;fi;\r
975      if tab(indy+1,indx).couleur<>0 then \r
976      tab(indy+1,indx).couleur:=num_joueur;\r
977      verif(indy+1,indx).couleur:=num_joueur;fi;\r
978      if tab(indy+1,indx+1).couleur<>0 then \r
979      tab(indy+1,indx+1).couleur:=num_joueur;\r
980      verif(indy+1,indx+1).couleur:=num_joueur;fi;\r
981      \r
982      end consequence;\r
983 \r
984 unit cons : procedure;\r
985      begin\r
986      call remis0(simul);\r
987      if simul(iy-1,ix-1).couleur<>0 then \r
988      simul(iy-1,ix-1).couleur:=num_joueur;\r
989      fi;\r
990      if simul(iy-1,ix).couleur<>0 then\r
991      simul(iy-1,ix).couleur:=num_joueur;\r
992      fi;\r
993      if simul(iy-1,ix+1).couleur<>0 then \r
994      simul(iy-1,ix+1).couleur:=num_joueur;\r
995      fi;\r
996      if simul(iy,ix-1).couleur<>0 then \r
997      simul(iy,ix-1).couleur:=num_joueur;\r
998      fi;\r
999      if simul(iy,ix+1).couleur<>0 then \r
1000      simul(iy,ix+1).couleur:=num_joueur;\r
1001      fi;\r
1002      if simul(iy+1,ix-1).couleur<>0 then \r
1003      simul(iy+1,ix-1).couleur:=num_joueur;\r
1004      fi;\r
1005      if simul(iy+1,ix).couleur<>0 then \r
1006      simul(iy+1,ix).couleur:=num_joueur;\r
1007      fi;\r
1008      if simul(iy+1,ix+1).couleur<>0 then \r
1009      simul(iy+1,ix+1).couleur:=num_joueur;\r
1010      fi;\r
1011      \r
1012      end cons;\r
1013 \r
1014 \r
1015      unit affpos : procedure;\r
1016      var i,j : integer;\r
1017      begin\r
1018      j:=indx;i:=indy;\r
1019      pos:=0;    \r
1020      if (tab(i,j).couleur=num_joueur) then \r
1021         if tab(i-1,j-1).couleur=0 then tab(i-1,j-1).couleur:=3;pos:=pos+1;fi;\r
1022         if tab(i-1,j).couleur=0 then tab(i-1,j).couleur:=3;pos:=pos+1;fi;\r
1023         if tab(i-1,j+1).couleur=0 then tab(i-1,j+1).couleur:=3;pos:=pos+1;fi;\r
1024         if tab(i,j-1).couleur=0 then tab(i,j-1).couleur:=3;pos:=pos+1;fi;\r
1025         if tab(i,j+1).couleur=0 then tab(i,j+1).couleur:=3;pos:=pos+1;fi;\r
1026         if tab(i+1,j-1).couleur=0 then tab(i+1,j-1).couleur:=3;pos:=pos+1;fi;\r
1027         if tab(i+1,j).couleur=0 then tab(i+1,j).couleur:=3;pos:=pos+1;fi;\r
1028         if tab(i+1,j+1).couleur=0 then tab(i+1,j+1).couleur:=3;pos:=pos+1;fi;\r
1029         if tab(i+2,j).couleur=0 then tab(i+2,j).couleur:=4;pos:=pos+1;fi;\r
1030         if tab(i-2,j).couleur=0 then tab(i-2,j).couleur:=4;pos:=pos+1;fi;\r
1031         if tab(i,j+2).couleur=0 then tab(i,j+2).couleur:=4;pos:=pos+1;fi;\r
1032         if tab(i,j-2).couleur=0 then tab(i,j-2).couleur:=4;pos:=pos+1;fi;\r
1033      fi;\r
1034         \r
1035        \r
1036      end affpos;\r
1037      \r
1038      \r
1039 \r
1040      unit reccase1 : procedure(x_s,y_s:integer);\r
1041      var px,py :integer;\r
1042      begin\r
1043      px:=120;py:=50;courx:=1;coury:=1;\r
1044      trouve:=false;\r
1045      (* recherche de x *)\r
1046         if ((x_s<120) or (y_s>520)) then call erreur;\r
1047         else\r
1048           while (not trouve) \r
1049           do\r
1050                if ((x_s>=px) and (x_s<px+50))\r
1051                then\r
1052                    trouve:= true;\r
1053                else\r
1054                     px:=px+50;\r
1055                     courx:=courx+1;\r
1056                fi; \r
1057           od;     \r
1058         fi;\r
1059      (* recherche de y *)\r
1060      trouve:=false;\r
1061      if ((y_s<50) or (y_s>450)) then call erreur;\r
1062      else\r
1063           while (not trouve)\r
1064           do\r
1065                if ((y_s>=py) and (y_s<py+50))\r
1066                then\r
1067                         trouve:= true;\r
1068                else\r
1069                     py:=py+50;\r
1070                     coury:=coury+1;\r
1071                fi; \r
1072           od;     \r
1073      fi;\r
1074       \r
1075      end reccase1;\r
1076 \r
1077 unit reccase2 : procedure(x_s,y_s:integer);\r
1078      var px,py :integer;\r
1079      begin\r
1080      px:=120;py:=50;indx:=1;indy:=1;\r
1081      termine:=false;\r
1082      (* recherche de x *)\r
1083      if ((x_s<120) or (x_s>520)) then call erreur;\r
1084      else\r
1085           while (not termine) \r
1086           do\r
1087                if ((x_s>=px) and (x_s<px+50))\r
1088                then\r
1089                    termine:= true;\r
1090                else\r
1091                     px:=px+50;\r
1092                     indx:=indx+1;\r
1093                fi; \r
1094           od;     \r
1095      fi;\r
1096      (* recherche de y *)\r
1097      termine:=false;\r
1098      if ((y_s<50) or (y_s>450)) then call erreur;\r
1099      else\r
1100           while (not termine)\r
1101           do\r
1102                if ((y_s>=py) and (y_s<py+50))\r
1103                then\r
1104                         termine:= true;\r
1105                else\r
1106                     py:=py+50;\r
1107                     indy:=indy+1;\r
1108                fi; \r
1109           od;     \r
1110      fi;\r
1111       \r
1112      end reccase2;\r
1113 \r
1114      unit verifjeu : procedure;\r
1115      var a,b : integer;\r
1116      begin\r
1117      possible:=false;\r
1118      call remis0(verif);\r
1119      for a:=1 to 8\r
1120      do\r
1121           for b:=1 to 8\r
1122           do\r
1123                if (verif(a,b).couleur=num_joueur) then\r
1124                 if verif(a-1,b-1).couleur=0 then verif(a-1,b-1).couleur:=3;fi;\r
1125                 if verif(a-1,b).couleur=0 then verif(a-1,b).couleur:=3;fi;\r
1126                 if verif(a-1,b+1).couleur=0 then verif(a-1,b+1).couleur:=3;fi;\r
1127                 if verif(a,b-1).couleur=0 then verif(a,b-1).couleur:=3;fi;\r
1128                 if verif(a,b+1).couleur=0 then verif(a,b+1).couleur:=3;fi;\r
1129                 if verif(a+1,b-1).couleur=0 then verif(a+1,b-1).couleur:=3;fi;\r
1130                 if verif(a+1,b).couleur=0 then verif(a+1,b).couleur:=3;fi;\r
1131                 if verif(a+1,b+1).couleur=0 then verif(a+1,b+1).couleur:=3;fi;\r
1132                 if verif(a+2,b).couleur=0 then verif(a+2,b).couleur:=4;fi;\r
1133                 if verif(a-2,b).couleur=0 then verif(a-2,b).couleur:=4;fi;\r
1134                 if verif(a,b+2).couleur=0 then verif(a,b+2).couleur:=4;fi;\r
1135                 if verif(a,b-2).couleur=0 then verif(a,b-2).couleur:=4;fi;\r
1136                fi;\r
1137           od;\r
1138      od;\r
1139      possible:=false;\r
1140      for a:=1 to 8\r
1141           do\r
1142                for b:=1 to 8\r
1143                do\r
1144                 case verif(a,b).couleur\r
1145                 when 3 : possible:=true;\r
1146                 when 4 : possible:=true;\r
1147                 esac;\r
1148                od;\r
1149           od;\r
1150           call remis0(verif); \r
1151      if num_joueur=1 and nombre1=0 then possible:=false;fi;\r
1152      if num_joueur=2 and nombre2=0 then possible:=false;fi;            \r
1153      end verifjeu;\r
1154  \r
1155      unit remis0 : procedure(rem : arrayof arrayof elem);\r
1156      var i,j : integer;\r
1157      begin\r
1158      for i:=-1 to 10\r
1159      do\r
1160           for j:=-1 to 10\r
1161           do\r
1162                if ((rem(i,j).couleur=3) or (rem(i,j).couleur=4))\r
1163                then\r
1164                     rem(i,j).couleur:=0;     \r
1165                fi;\r
1166           od;\r
1167      od;\r
1168      end remis0;\r
1169 \r
1170      unit Bouton:procedure(xa,ya,xb,yb:integer);\r
1171      (*\r
1172       * Affiche un cadre \85 la WINDOWS.\r
1173       *)\r
1174      begin\r
1175          (* BLANC = 15 *)\r
1176          call patern(xa  ,ya  ,xb  ,yb  ,8 ,1 );\r
1177          call patern(xa+3,ya+3,xb-2,yb-2,0 ,1);\r
1178          call patern(xa+4,ya+4,xb-1,yb-1,15,1);\r
1179          call patern(xa+4,ya+4,xb-3,yb-3,7 ,1);\r
1180  \r
1181      end;\r
1182  \r
1183  \r
1184      (* Variable du programme Principal *)\r
1185      var\r
1186          Mouse     : boolean ,\r
1187          x_pos     ,\r
1188          y_pos     ,\r
1189          X_s       ,\r
1190          Y_s       ,\r
1191          Keyb1     ,\r
1192          Keyb2     ,\r
1193          Flag      ,\r
1194          Num_Mouse :integer;\r
1195          \r
1196      begin (* Begin du block : \82cran *)\r
1197      call gron(0);\r
1198      call init(1,0);\r
1199      call showcursor;\r
1200      call presentation;\r
1201      end;\r
1202 end;\r
1203 end ecran;\r
1204 \r
1205 \r
1206 \r
1207 \r
1208 Var\r
1209         tab : arrayof arrayof elem,\r
1210         simul : arrayof arrayof elem,\r
1211         verif : arrayof arrayof elem,  \r
1212         nombre1,nombre2,num_joueur,indx,indy,courx,\r
1213         type1,type2,coury,nomb,ix,iy,pos:integer,\r
1214         termine,possible,trouve,fini : boolean;\r
1215 \r
1216 Begin\r
1217         nombre1:=2;\r
1218         nombre2:=2;\r
1219         type1:=1;\r
1220         type2:=1;\r
1221         num_joueur:=1;  \r
1222         call creatab;\r
1223         call init_tab;\r
1224         call ecran;\r
1225 end dominate;\r
1226  \r