Là j'ai terminé la 1ere version fonctionnelle sur Hector (en B3X, soit HRX ou MX)
Ce qui est ballot c'est qu'a la vue de la rapidité du jeu, j'aurais dû le programmer en Forth... Ce sera pour la prochaine fois !
Le code source :
Code : Tout sélectionner
10 '''''''''''''''''''''''''''
11 '''''''''2048 '''''''''''''
12 '''''''''''''''''''''''''''
13 ''''Cassis 25 09 2016'''''
14 ''''Lozorno 10 10 2016'''''
15 '''''''''''''''''''''''''''
16 ''''' YO_FR ''''''''''''''
17 '''''''''''''''''''''''''''
20 dim PL(4,4):dim UNDO(4,4)
21 dim XSOL(16)
22 dim YSOL(16)
23 dim DJ(4)
24 NBU=3:DEPL=1
30 gosub 3000: 'init grille
35 GAGNE=0
40 gosub 4000: ' Dessin grille
50 gosub 5000: ' Dessin tuiles
60 if DEPL <> 0 then gosub 1000: ' Ajout 1 tuile
70 DIR= joy(0)
75 if DIR =1 or DIR =2 or DIR =4 or DIR =8 then gosub 8100
80 if DIR =1 then goto 2000 :'Gauche
85 if DIR =2 then goto 2200 :'Droite
90 if DIR =4 then goto 2400 :'Haut
100 if DIR =8 then goto 2600 :'Bas
120 if fire(0)=1 and NBU > 0 then gosub 8000:gosub 1000:DEPL=0:NBU=NBU-1:goto 40
160 goto 70 : ' Attente position correcte
200 ' Retour des deplacements-ne pas renumeroter
210 DIR= joy(0)
220 if DIR <> 0 then goto 200
230 scale 1,1
240 if GAGNE=1 then output "*** GAGNE,BRAVO ***",7,24
250 if DEPL= 0 then output "Pas de mouvements !",7,24
260 if DEPL<>0 and GAGNE <> 1 then output " ",7,24
270 if GAGNE=1 then GAGNE=2
280 goto 50 :' on reboucle !
1000 '''''''''''''
1001 'Ajout une case
1002 '''''''''''''
1010 'Avant on verifie que l'on a pas perdu !
1020 if ISOL=0 then goto 1500: ' Perdu !
1030 I= int( rnd(0,ISOL))
1040 X=XSOL(I):Y=YSOL(I)
1050 VEL=2
1060 PL(X,Y)=2:UNDO(X,Y)=0
1065 OLD=1
1070 pen 3: gosub 5500: 'Et on l'affiche
1072 XX=XSOL(I):YY=YSOL(I)
1075 PL(XX,YY)=2:UNDO(XX,YY)=0
1080 return
1500 '''''''''''''
1501 ' PERDU
1502 '''''''''''''
1510 output "PERDU !!!",2,1
1520 for I=10 to 400 step 5
1530 tone I,3
1540 next I
1550 for I=400 to 10 step -5
1560 tone I,3
1570 next I
1580 end
2000 ' Deplacement vers la gauche
2010 DEPL=0
2020 for Y =1 to 4
2030 for J=1 to 3 :'Tassage
2040 for X = 2 to 4 step 1
2050 ' Case gauche vide
2060 if PL(X-1,Y)=0 and PL(X,Y) <> 0 then PL(X-1,Y)=PL(X,Y):PL(X,Y)=0:DEPL=1
2070 next X
2080 next J
2090 if PL(1,Y)= PL(2,Y) and PL(2,Y) <> 0 then PL(1,Y)= 2*PL(2,Y):PL(2,Y)=0:DEPL=1
2100 if PL(2,Y)= PL(3,Y) and PL(3,Y) <> 0 then PL(2,Y)= 2*PL(3,Y):PL(3,Y)=0:DEPL=1
2110 if PL(3,Y)= PL(4,Y) and PL(4,Y) <> 0 then PL(3,Y)= 2*PL(4,Y):PL(4,Y)=0:DEPL=1
2120 for J=1 to 3 :'Tassage
2130 for X = 2 to 4 step 1
2140 ' Case gauche vide
2150 if PL(X-1,Y)=0 and PL(X,Y) <> 0 then PL(X-1,Y)=PL(X,Y):PL(X,Y)=0:DEPL=1
2160 next X
2170 next J
2180 next Y
2190 goto 200 :'Reboucle
2200 ' Deplacement vers la droite
2210 DEPL=0
2220 for Y =1 to 4
2230 for J=1 to 3 :'Tassage
2240 for X = 3 to 1 step -1
2250 ' Case ` gauche vide
2260 if PL(X+1,Y)=0 and PL(X,Y) <> 0 then PL(X+1,Y)=PL(X,Y):PL(X,Y)=0:DEPL=1
2270 next X
2280 next J
2290 if PL(3,Y)= PL(4,Y) and PL(4,Y) <> 0 then PL(4,Y)= 2*PL(3,Y):PL(3,Y)=0:DEPL=1
2300 if PL(2,Y)= PL(3,Y) and PL(3,Y) <> 0 then PL(3,Y)= 2*PL(2,Y):PL(2,Y)=0:DEPL=1
2310 if PL(1,Y)= PL(2,Y) and PL(2,Y) <> 0 then PL(2,Y)= 2*PL(2,Y):PL(1,Y)=0:DEPL=1
2320 for J=1 to 3 :'Tassage
2330 for X = 3 to 1 step -1
2340 ' Case DROITE vide
2350 if PL(X+1,Y)=0 and PL(X,Y) <> 0 then PL(X+1,Y)=PL(X,Y):PL(X,Y)=0:DEPL=1
2360 next X
2370 next J
2380 next Y
2390 goto 200 :'Reboucle
2400 ' Deplacement vers le haut
2410 DEPL=0
2420 for X =1 to 4
2430 for J=1 to 3 :'Tassage
2440 for Y = 2 to 4 step 1
2450 ' Case en haut vide
2460 if PL(X,Y-1)=0 and PL(X,Y) <> 0 then PL(X,Y-1)=PL(X,Y):PL(X,Y)=0:DEPL=1
2470 next Y
2480 next J
2490 if PL(X,1)= PL(X,2) and PL(X,2) <> 0 then PL(X,1)= 2*PL(X,2):PL(X,2)=0:DEPL=1
2500 if PL(X,2)= PL(X,3) and PL(X,3) <> 0 then PL(X,2)= 2*PL(X,3):PL(X,3)=0:DEPL=1
2510 if PL(X,3)= PL(X,4) and PL(X,4) <> 0 then PL(X,3)= 2*PL(X,4):PL(X,4)=0:DEPL=1
2520 for J=1 to 3 :'Tassage
2530 for Y = 2 to 4 step 1
2540 ' Case ` gauche vide
2550 if PL(X,Y-1)=0 and PL(X,Y) <> 0 then PL(X,Y-1)=PL(X,Y):PL(X,Y)=0:DEPL=1
2560 next Y
2570 next J
2580 next X
2590 goto 200 :'Reboucle
2600 ' Deplacement vers le bas
2610 DEPL=0
2620 for X =1 to 4
2630 for J=1 to 3 :'Tassage
2640 for Y = 3 to 1 step -1
2650 ' Case gauche vide
2660 if PL(X,Y+1)=0 and PL(X,Y) <> 0 then PL(X,Y+1)=PL(X,Y):PL(X,Y)=0:DEPL=1
2670 next Y
2680 next J
2690 if PL(X,3)= PL(X,4) and PL(X,4) <> 0 then PL(X,4)= 2*PL(X,3):PL(X,3)=0:DEPL=1
2700 if PL(X,2)= PL(X,3) and PL(X,3) <> 0 then PL(X,3)= 2*PL(X,2):PL(X,2)=0:DEPL=1
2710 if PL(X,1)= PL(X,2) and PL(X,2) <> 0 then PL(X,2)= 2*PL(X,2):PL(X,1)=0:DEPL=1
2720 for J=1 to 3 :'Tassage
2730 for Y = 3 to 1 step -1
2740 ' Case BAS vide
2750 if PL(X,Y+1)=0 and PL(X,Y) <> 0 then PL(X,Y+1)=PL(X,Y):PL(X,Y)=0:DEPL=1
2760 next Y
2770 next J
2780 next X
2790 goto 200 :'Reboucle
3000 '''''''''''''
3001 'Init Tableau
3002 '''''''''''''
3010 VEL=1
3020 for X = 1 to 4
3030 for Y = 1 to 4
3040 PL(X,Y)=0
3050 UNDO(X,Y)=0
3060 next Y
3070 next X
3199 return
4000 '''''''''''''
4001 'DESSIN
4002 '''''''''''''
4010 wipe:special:ink 3
4020 for LI=0 to 160 step 40
4030 line 50,50+LI,160+50,50+LI
4040 line 50+LI,50,50+LI,160+50
4050 next LI
4060 scale2,2:pen1
4070 output "2",0,1
4080 output "0",0,2
4090 output "4",0,3
4100 output "8",0,4:pen 2
4105 scale 1,1
4110 output "YO",1,11
4120 output "FR",2,12
4130 standard
4140 output "Cassis,29/9/2016",70,12
4150 standard
4160 output "HELPER :", 50,220
4170 output NBU, 100,220
4900 return
5000 '''''''''''
5001 ''Affichage
5002 '''''''''''
5010 ISOL=0 :' Index solutions tuile
5020 for X = 1 to 4
5030 for Y = 1 to 4
5040 VEL = PL(X,Y):OLD=UNDO(X,Y)
5050 if VEL =0 then XSOL(ISOL)=X: YSOL(ISOL)=Y: ISOL=ISOL+1
5060 standard:ink 0
5080 special
5090 pen 2 : gosub 5500
5110 next Y
5120 next X
5199 'Redraw de la derniere case documentee
5200 X=XX
5210 Y=YY
5220 pen 2:VEL = PL(X,Y):OLD=0
5230 if xx > 0 and yy > 0 then GOSUB 5500
5400 return
5500 'Mise en place dans la grille
5510 if OLD=VEL and UND = 0 then return:'SORTIE SI RIEN NE CHANGE
5520 special:scale 1,1:ink 0
5530 box X*40 +24,234-Y*40, 48+X*40,218-Y*40
5540 ink 1
5550 if VEL=0 then return
5560 if VEL<4 then goto 6000
5565 if VEL<65 then goto 6060
5570 if VEL=128 then goto 6128
5580 if VEL=256 then goto 6256
5590 if VEL=512 then goto 6512
5600 if VEL=1024 then goto 7024
5610 if VEL=2048 then goto 7048
5630 if VEL=4096 then goto 7200
5640 if VEL=8192 then goto 7300
5650 if VEL=16384 then goto 7400
5700 output "ERR",2+X*5,-1+Y*5
5710 PL(X,Y)=2
5720 return
6000 'Negatif => redraw du dernier
6010 PL(X,Y)=ABS(PL(X,Y))
6020 VEL = PL(X,Y)
6060 output VEL,2+X*5,Y*5-1
6070 return
6128 output "1",3+X*5,-1+Y*5
6150 output "28",3+X*5,Y*5
6160 return
6256 output "2",3+X*5,-1+Y*5
6260 output "56",3+X*5,Y*5
6270 return
6512 output "5",3+X*5,-1+Y*5
6520 output "12",3+X*5,Y*5
6530 return
7024 output "10",3+X*5,-1+Y*5
7030 output "24",3+X*5,Y*5
7040 return
7048 output "20",3+X*5,-1+Y*5
7050 output "48",3+X*5,Y*5
7060 GAGNE=GAGNE+1
7070 return
7200 output "40",3+X*5,-1+Y*5
7210 output "96",3+X*5,Y*5
7220 return
7300 output "81",3+X*5,-1+Y*5
7310 output "92",3+X*5,Y*5
7320 return
7400 output "16",3+X*5,-1+Y*5
7410 output "384",3+X*5,Y*5
7420 return
8000 ' UNDO
8010 for X=1 to 4
8020 for Y=1 to 4
8030 PL(X,Y)=ABS(UNDO(X,Y))
8040 next Y
8050 next X
8060 UND=1
8070 return
8100 ' SAUVE POUR UNDO
8110 for X=1 to 4
8120 for Y=1 to 4
8125 PL(X,Y)=ABS(PL(X,Y))
8130 UNDO(X,Y)=PL(X,Y)
8140 next Y
8150 next X
8160 UND=0
8170 return
Sinon, ici le fichier pour le charger depuis HectorDuino (réel ou dans VBHector) le chargement se faisant alors en sélectionnant HectorDuino (option 4) puis un "LOAD 2048 4200" suivi d'un reset, option 9 pour B3X et un "RUN".
JJ