Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 06/01/2019, à 10:25

duocore

Fatal: illegal character "''" ($E2) sous freepascal

Bonjour,

J'ai repris le programme en pascal present dans les liens suivant:
http://fr.1001mags.com/parution/svm/num … e-integral
http://fr.1001mags.com/parution/svm/num … e-integral
http://fr.1001mags.com/parution/svm/num … e-integral
http://fr.1001mags.com/parution/svm/num … e-integral

et dont voici le code:

uses crt;
const
longueur=24; hauteur=14;
 xniveau=67; yniveau=2;
xscore=67; yscore=5;
xtemps=67; ytemps=3;
 decx=28; decy=4;
maxblock=50;
block=15;
 tete=2;
bord=176;
type position = record
 x, y: integer;
 end;
var matrice: array[1..longueur,1..hauteur] of char;
 bloc: array[1..50] of position;
nombre: integer;
touche: char;
temps: integer; (* temps imparti *)
xc,yc: integer; (* coordonnes du curseur dans la matrice *)
score,hiscore: integer;
demande: string[30];
i: integer;

(* matrice mise à blanc *)
procedure init_matrice;
 var i,j: integer;
 begin
for i:=1 to longueur do
for j:=1 to hauteur do
 matrice[i,j]:=’ ‘;
 end;

(. initialisation des variables *)
procedure init_var;
begin
nombre:=0;
 randomize;
 end;

(* initialisation des tètes, placement dans la matrice *)
procedure init_cible;
var x,y,i,hv integer;
begin
x:=random(longueur-6)+3;
 y:=random(hauteur-6)+3;
 hv:=random(2);
 if hv=0
then begin
for i:=y-1 to y+1 do
begin
matrice[x,i]:=chr(tete);
 nombre:=nombre+1;
end;
 end
else begin
 for i:=x-1 to x+1 do
begin
matrice[i,y]:=chr(tete):
 nombre:=nombre+1;
 end;
 end;
 end;

 (* prépare une matrice *)
 procedure init;
 begin
init_var;
init matrice;
init_cible;
 end;

(* fonction testant si la ligne est vide *)
function ligne_vide(x,y,xe,ye:integer):boolean;
 var ok: boolean;
 a,b,c,d,i: integer;
 begin ok:=true;
if (x=xe) and (y=ye) then ok:=false;
if x<xe then begin a:=x c:=xe end
else begin a:=xe; c:=x end;
if y<ye then begin b:=y d:=ye end
else begin b:=ye; d:=y end;
if (x=xe)
then begin
for i:=b+1 to d do if matrice[a,i]<>’ ‘then ok:=false;
end
else begin
for i:=a+1 to c do if matrice[i,b]<>’ ‘then ok:=false;
end;
ligne_vide:=ok;
end;

(*procedure affiche matrice*)
procedure afficher_matrice;
var i,j:integer;
begin
for i:=0 to longueur+1 do
begin
gotoxy(i+decx,decy); write(chr(bord));
gotoxy(i+decx,decy+hauteur+1 );write(chr(bord));
end;
for i:=0 to hauteur+1 do
gotoxy(decx,decy+i);write(chr(bord));
gotoxy(decx+longueur+i,decy+i); write(chr(bord));
end;
for i:=1 to longueur do
for j:=1 to hauteur do
gotoxy(i+decx,j+decy);
write(matrice(i,j));
end;
end;

(*procedure liste block*)
procedure transfert_liste_block;
var i,j,k,n:integer;
begin
k:=0;
n:=0;
for i:=1 to longueur do
for j:=1 to hauteur do
begin
if matrice(i,j)=chr(tete) then
begin
k:=k+1;
bloc[k].x:=i; bloc[k].y:=j;
end;
 if matrice[i,j]=chr(block) then
begin
 n:=n+1;
bloc[n].x:=i;bloc[n].y:=j;
 end;
end;
end;

 (* procédure mélangeant la matrice *)
procedure chaos(N:integer);
 vari,x,y,hv,xe,ye,xp,yp: integer;
begin
 i:=0;
repeat
 transfert_liste_bloc;
 i:=random(nombre)+1;
 x:=bloc[i].x;
 y:=bloc[i].y;
 xe:=bloc[i).x; ye:=bloc[i].y;
 hv:=random(2);
if hv=0 then xe:=random(longueur-2)+2 else ye:=random(hauteur- 2)+2;
 if ligne_vide(x,y,xe,ye) then
 begin xp:=x; yp:=y;
 if hv=1
then
begin (* deplacement vertical *)
if ye>y then begin yp:=y; yp:=y-1; end;
if ye<y then begin yp:=y;yp:=y+1; end;
end
else
begin (* deplacement horizontal *)
if xe>x then begin xp:=x; xp:=x-1; end;
if ye<y then begin xp:=x;xp:=x+1; end;
end;
if (xp<=longueur) and (xp>=1) and (yp<=hauteur) and (yp>=1)
then
begin
if matrice[xp,yp]=’ ‘ then
begin
matrice[xe,ye]:=matrice[x,y];
matrice[xp,yp]:=chr(block);
matrice[x,y]:=’ ‘;
nombre:=nombre+1;
end;
end;
end;
until nombre=n
end;

(*procedure gerant le clavier*)
procedure K_haut;
begin
yc:=yc-1; if yc<1 then yc:=1;
end;
procedure K_bas;
begin
yc:=yc+1; if yc>hauteur then yc:=hauteur;
end;
procedure K_gauche;
begin
xc:=xc-1; if xc<1 then xc:=1;
end;
procedure K_droit;
begin
xc:=xc+1; if xc>longueur then yc:=longueur;
end;

(*procedure pousse bloc*)
procedure pousse(xd,yd:integer);
var xb,yb,stop,l,numero:integer;
if matrice[xc,yc]<>’ ‘ then
begin
xb:=xc;yb:=yc;
stop:=0; (*stop =1: collision; stop=2 : sortie*)
repeat
if (xb+xd>longueur)or(xb+xd<1)or(yb+yd>hauteur)or(yb+yd<1) then stop:=2;
if stop=0 then
begin
if matrice[xb+xd,yb+yd]<>’ ‘ then stop:=1;
end;
if stop=0 then
matrice[xb+xd,yb+yd]:=matrice[xb,yb];
matrice[xb,yb]=’ ‘;
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb];
xb:=xb+xd;yb:=yb+yd;
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb]);
delay(125);temps:=temps-1;
end;
until stop<>0;
if stop=2 then
begin
for i:=100 to 800 do sound(i);nosound;
matrice[xc,yc]:=matrice[xb,yb];
matrice[xb,yb]:= ‘ ‘;
gotoxy(decx+xb,decy+yb);write(‘ ‘);
gotoxy(decx+xc,decy+yc);write(matrice[xc,yc]);
xb:=xc;yb:=yc;
end;
end;
tranfert_liste_bloc;(*pour test alignement*)
if stop=1 then begin xc:=xb;yc:=yb; end;
temps:=temps-1;
end;

(*effacementd’un bloc*)
procedureK_espace;
var i,numero:integer;
begin
if (matrice[xc,yc]<>chr(tete)) then
begin
gotoxy(decx+xc,decy+yc);write(‘ ‘);
matrice[xc,yc]:=’ ‘;
end;
end;

(*procedure de lecture du clavier*)
function lecture_clavier:integer;
var code:integer;
begin
code:=0;
if keypressed then
begin
touche:=readkey;
code:=ord(touche);
if code=0 then
begin
touche:=readkey;
code:=100*ord(touche);
end;
end;
lecture_clavier:=code;
end;

(*procedure test alignement tete*)
function alignement:boolean;
var ok:boolean;
x1,y1,x2,y2,x3,y3:integer;
begin
x1:=bloc[1],x;y1:=bloc[1],y;
x2:=bloc[2],x;y2:=bloc[2],y;
x3:=bloc[3],x;y3:=bloc[3],y;
ok:=false;
(*teste alignement horizontal*)
if (y1=y2) and (y2=y3) then
begin
(*cas 1 2 3*)
if (x2=x1+1) and (x3=x2+1) then ok:=true;
(*cas 3 2 1*)
if (x2=x3+1) and (x1=x2+1) then ok:=true;
(*cas 1 3 2*)
if (x3=x1+1)and (x2=x3+1) then ok:=true;
(*cas 2 3 1*)
if (x3=x2+1) and (x1=x3+1) then ok:=true;
 (* cas 2 1 3 *)
if (x1=x2+1) and (x3=x1+3) then ok:=true;
(* cas 3 1 2 *)
if (x1=x3+1) and (x2=x1+1) then ok:=true;
end;
(* teste un alignement vertical *)
if (x1=x2) and (x2=x3) then
begin
(* cas 1 2 3 *)
if (y2=y1+1) and (y3=y2+1) then ok:=true;
(* cas 3 2 1 *)
if (y2=y3+1) and (y1=y2+1) then ok:=true;
(* cas 1 3 2 *)
 if (y3=y1+1) and (y2=y3+1) then ok:=true;
(* cas 2 3 1 *)
if (y3=y2+1) and (y1=y3+1) then ok:=true;
(* cas 2 1 3 *)
 if (y1=y2+1) and (y3=y1+1) then ok:=true;
(* cas 3 1 2 *)
if (y1=y3+1) and (y2=y1+1) then ok:=true;
end;
alignement:=ok;
end;

(* Jouer le niveau actuel *)
procedure jouer_la_matrice(N:integer);
 var code: integer;
 sortie: boolean;
begin
xc:=longueur div 2;
yc:=longueur div 2;
temps:=150 * N;
repeat code:=lecture_clavier;
case code of
7200: K_haut;
7500: K_gauche;
 7700: K_droit;
 8000: K_bas;
 8200: K_espace;
8300: K_espace;
 56: (* K_8 *) pousse (0,-1);
 52 (* K_4 *) pousse (-1,0);
 54: (* K_6 *) pousse (1,0);
50: (* K_2 *) pousse (0,1);
32: K_espace;
 13: temps:=1;
 end;
temps:=temps-l;
gotoxy(xtemps,ytemps); write(temps:5);
gotoxy(xc+decx,yc+decy); delay(100):
sortie: =(alignement) or (temps<1);
until sortie;
end;

(*creation carre jeu*)
procedure creer_matrice(N:integer);
begin
init;
chaos(N+1);
transfert_list_bloc;
end;

(*calcul score*)
procedure calcul_score;
var i:integer;
begin
for i:=temps div 15 downto 0 do
begin
sound(i);
score:=score+1;
temps:=temps-15;
if temps<0 then temps:=0;
gotoxy(xtemps,ytemps):write(temps:5);
gotoxy(xscore,yscore):write(score:5);
delay(10);
end;
nosound;
delay(1000);
end;

(*jouer partie entiere*)
procedure jouer_partie(N:integer);
begin
creer_matrice(N);
afficher_matrice;
jouer_la_matrice(N);
if alignement then calcul_score;
end;
 (* racine gestion partie *)
 procedure racine_partie;
 var niveau: integer;
begin
gotoxy(decx,decy-1); write('Appuyez sur une touche');
touche:=readkey;
gotoxy(decx,decy-1); write('                      ');
niveau:=0;
score:=0;
gotoxy(xscore,yscore);
write(0:5);
 repeat
niveau:=niveau+1;
 if niveau>15 then niveau:=15;
 gotoxy(xniveau,yniveau); write(niveau:5);
 jouer_partie(niveau);
 until not(alignement);
end;
 begin
clrscr;
writeln;
writeln('Très heureux de jouer avec vous !');
 delay(3000);
 clrscr;
gotoxy(1,1); Writeln('P.U.S.H.');
writeln('S.V.M.');
 writeln('Jeu de Réflexion');
writeln;writeln;
 writeln('Alignez les Têtes');
 writeln('dans le temps imparti.');
writeln;
writeln('On peut déplacer les');
 writeln('blocs et les têtes.');
 writeln('On peut détruire les blocs.');
 writeln('Les murs n"arrétent rien !');
writeln;
 writeln('Il faut un alignement');
writeln('horizontal ou vertical.');
 writeln;
 writeln('Face:',chr(tete));
 writeln('Bloc:',chr(block));
writeln('Mur:',chr(bord));
gotoxy(1,hauteur+decy+2); writeln('',chr(24),",chr(25),",chr(27),'',chr(26),'Pour le curseur (pavé numérique)');
writeln('(Shift) +',chr(24),",chr(25),",chr(27),'',chr(26),'Pour les blocs (pavé numérique)');

writeln('(Space) ou (Ins) ou (Del) pour détruire les blocs');
write ('(Enter) si la situation est sans issue');
gotoxy(xscore-7,yscore); write('Score:');
gotoxy(xtemps-7,ytemps); write('Temps:');
 gotoxy(xniveau-7,yniveau); write('Niveau:');
init;afficher_matrice;
 hiscore:=1000;
repeat
 gotoxy(56,8); write('Melleur Score:',hiscore:6);
 gotoxy(56,16); write('----------------------');
racine_partie;
 if score>hiscore then hiscore:=score;
 gotoxy(60,16);
demande:='Autre partie (o/n) ?';
 for 1:=1 to length(demande) do
begin
gotoxy(60+i-1,16); write(demande[i]); delay(100);
 end;
touche:=upcase(readkey);
 until touche,'N';

j'ai essayé de le compiler avec fpc:
fpc jeu.bas -ojeu
et j'ai une erreur de compilation :

 
Free Pascal Compiler version 3.0.4+dfsg-18ubuntu2 [2018/08/29] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling jeu.pas
jeu.pas(32,16) Fatal: illegal character "''" ($E2)
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

merci de votre aide

Hors ligne

#2 Le 06/01/2019, à 11:10

gl38

Re : Fatal: illegal character "''" ($E2) sous freepascal

D'après la page, il me semble que les guillemets autour des caractères ne sont pas bons.
Cordialement,
Guy

Hors ligne

#3 Le 06/01/2019, à 11:12

DRbuntu91

Re : Fatal: illegal character "''" ($E2) sous freepascal

Bonjour
C'est cette ligne qui pose pb.?

 matrice[i,j]:=’ ‘;

Elle me semble OK.....
On dirait que le compilateur a supprimé le blanc a l'intérieur des simple quottes, ou alors il trouve autre chose qui ne le plaît pas....

jeu.pas(32,16) Fatal: illegal character "''" ($E2)

PS1: je ne vais pouvoir aider bcp. mes connaissances de Pascal remontent au "seventies"....
PS2: si t'as pas résolu ton pb. j'essaierai d'installer demain FreePascal sur mon ordi (Ubuntu 1604) pour voir la différence.


Portable CLEVO W55SU1, Intel i5-4200M, RAM=8Go, DD=500Go mSATA, BIOS 4.6.5 AMI, Ubuntu 16.04 LTS a jour
Puis pour bidouiller un vieux portable Dell Precision M4600 avec W10 + DEBIAN-Buster
Utilisateur Ubuntu depuis Janvier 2017

Hors ligne

#4 Le 06/01/2019, à 11:13

pingouinux

Re : Fatal: illegal character "''" ($E2) sous freepascal

Bonjour,
C'est sans doute à cause de la ligne 31 de ton fichier :

 matrice[i,j]:=’ ‘;

On y trouve ces 2 caractères

’ => <U2019>     /xe2/x80/x99 RIGHT SINGLE QUOTATION MARK
‘ => <U2018>     /xe2/x80/x98 LEFT SINGLE QUOTATION MARK

Il faudrait sans doute les remplacer par celui-ci :

' => <U0027>     /x27         APOSTROPHE

Ajouté :
On trouve l'un ou l'autre de ces caractères dans les lignes suivantes (numéro des lignes en tête)

31: matrice[i,j]:=’ ‘;
85:for i:=b+1 to d do if matrice[a,i]<>’ ‘then ok:=false;
88:for i:=a+1 to c do if matrice[i,b]<>’ ‘then ok:=false;
164:if matrice[xp,yp]=’ ‘ then
168:matrice[x,y]:=’ ‘;
197:if matrice[xc,yc]<>’ ‘ then
205:if matrice[xb+xd,yb+yd]<>’ ‘ then stop:=1;
209:matrice[xb,yb]=’ ‘;
220:matrice[xb,yb]:= ‘ ‘;
221:gotoxy(decx+xb,decy+yb);write(‘ ‘);
231:(*effacementd’un bloc*)
237:gotoxy(decx+xc,decy+yc);write(‘ ‘);
238:matrice[xc,yc]:=’ ‘;

Ajouté(2) :
Si c'est bien ça, tu peux corriger ton fichier ainsi :

sed -r "s/’|‘/'/g" ancien_fichier >nouveau_fichier

Dernière modification par pingouinux (Le 06/01/2019, à 11:42)

Hors ligne

#5 Le 06/01/2019, à 14:00

duocore

Re : Fatal: illegal character "''" ($E2) sous freepascal

j'ai corriger le probleme:

uses crt;
const
longueur=24; hauteur=14;
 xniveau=67; yniveau=2;
xscore=67; yscore=5;
xtemps=67; ytemps=3;
 decx=28; decy=4;
maxblock=50;
block=15;
 tete=2;
bord=176;
type position = record
 x, y: integer;
 end;
var matrice: array[1..longueur,1..hauteur] of char;
 bloc: array[1..50] of position;
nombre: integer;
touche: char;
temps: integer; (* temps imparti *)
xc,yc: integer; (* coordonnes du curseur dans la matrice *)
score,hiscore: integer;
demande: string[30];
i: integer;

(* matrice mise à blanc *)
procedure init_matrice;
 var i,j: integer;
 begin
for i:=1 to longueur do
for j:=1 to hauteur do
 matrice[i,j]:=' ';
 end;

(* initialisation des variables *)
procedure init_var;
begin
nombre:=0;
 randomize;
 end;

(* initialisation des tètes, placement dans la matrice *)
procedure init_cible;
var x,y,i,hv :integer;
begin
x:=random(longueur-6)+3;
 y:=random(hauteur-6)+3;
 hv:=random(2);
 if hv=0
then begin
for i:=y-1 to y+1 do
begin
matrice[x,i]:=chr(tete);
 nombre:=nombre+1;
end;
 end
else begin
 for i:=x-1 to x+1 do
begin
matrice[i,y]:=chr(tete);
 nombre:=nombre+1;
 end;
 end;
 end;

 (* prépare une matrice *)
 procedure init;
 begin
init_var;
init_matrice;
init_cible;
 end;

(* fonction testant si la ligne est vide *)
function ligne_vide(x,y,xe,ye:integer):boolean;
 var ok: boolean;
 a,b,c,d,i: integer;
 begin ok:=true;
if (x=xe) and (y=ye) then ok:=false;
if x<xe then begin a:=x; c:=xe end
else begin a:=xe; c:=x end;
if y<ye then begin b:=y; d:=ye end
else begin b:=ye; d:=y end;
if (x=xe)
then begin
for i:=b+1 to d do if matrice[a,i]<>' 'then ok:=false;
end
else begin
for i:=a+1 to c do if matrice[i,b]<>' 'then ok:=false;
end;
ligne_vide:=ok;
end;

(*procedure affiche matrice*)
procedure afficher_matrice;
var i,j:integer;
begin
for i:=0 to longueur+1 do
begin
gotoxy(i+decx,decy); write(chr(bord));
gotoxy(i+decx,decy+hauteur+1);write(chr(bord));
end;
for j:=0 to hauteur+1 do
begin
gotoxy(decx,decy+j);write(chr(bord));
gotoxy(decx+longueur+1,decy+j); write(chr(bord));
end;
for i:=1 to longueur do
for j:=1 to hauteur do
begin
gotoxy(i+decx,j+decy);
write(matrice[i,j]);
end;
end;

(*procedure liste block*)
procedure transfert_liste_bloc;
var i,j,k,n:integer;
begin
k:=0;
n:=0;
for i:=1 to longueur do
for j:=1 to hauteur do
begin
if matrice[i,j]=chr(tete) then
begin
k:=k+1;
bloc[k].x:=i; bloc[k].y:=j;
end;
 if matrice[i,j]=chr(block) then
begin
 n:=n+1;
bloc[n].x:=i;bloc[n].y:=j;
 end;
end;
end;

 (* procédure mélangeant la matrice *)
procedure chaos(N:integer);
 var i,x,y,hv,xe,ye,xp,yp: integer;
begin
 i:=0;
repeat
 transfert_liste_bloc;
 i:=random(nombre)+1;
 x:=bloc[i].x;
 y:=bloc[i].y;
 xe:=bloc[i].x; ye:=bloc[i].y;
 hv:=random(2);
if hv=0 then xe:=random(longueur-2)+2 else ye:=random(hauteur- 2)+2;
 if ligne_vide(x,y,xe,ye) then
 begin xp:=x; yp:=y;
 if hv=1
then
begin (* deplacement vertical *)
if ye>y then begin yp:=y; yp:=y-1; end;
if ye<y then begin yp:=y;yp:=y+1; end;
end
else
begin (* deplacement horizontal *)
if xe>x then begin xp:=x; xp:=x-1; end;
if ye<y then begin xp:=x;xp:=x+1; end;
end;
if (xp<=longueur) and (xp>=1) and (yp<=hauteur) and (yp>=1)
then
begin
if matrice[xp,yp]=' ' then
begin
matrice[xe,ye]:=matrice[x,y];
matrice[xp,yp]:=chr(block);
matrice[x,y]:=' ';
nombre:=nombre+1;
end;
end;
end;
until nombre=n
end;

(*procedure gerant le clavier*)
procedure K_haut;
begin
yc:=yc-1; if yc<1 then yc:=1;
end;
procedure K_bas;
begin
yc:=yc+1; if yc>hauteur then yc:=hauteur;
end;
procedure K_gauche;
begin
xc:=xc-1; if xc<1 then xc:=1;
end;
procedure K_droit;
begin
xc:=xc+1; if xc>longueur then yc:=longueur;
end;

(*procedure pousse bloc*)
procedure pousse(xd,yd:integer);
var xb,yb,stop,i,numero:integer;
begin
if matrice[xc,yc]<>' ' then
begin
xb:=xc;yb:=yc;
stop:=0; (*stop =1: collision; stop=2 : sortie*)
repeat
if (xb+xd>longueur)or(xb+xd<1)or(yb+yd>hauteur)or(yb+yd<1) then stop:=2;
if stop=0 then
begin
if matrice[xb+xd,yb+yd]<>' ' then stop:=1;
end;
if stop=0 then
begin
matrice[xb+xd,yb+yd]:=matrice[xb,yb];
matrice[xb,yb]:=' ';
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb]);
xb:=xb+xd;yb:=yb+yd;
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb]);
delay(125);temps:=temps-1;
end;
until stop<>0;
if stop=2 then
begin
for i:=100 to 800 do sound(i);nosound;
matrice[xc,yc]:=matrice[xb,yb];
matrice[xb,yb]:=' ';
gotoxy(decx+xb,decy+yb);write(' ');
gotoxy(decx+xc,decy+yc);write(matrice[xc,yc]);
xb:=xc;yb:=yc;
end;
end;
transfert_liste_bloc;(*pour test alignement*)
if stop=1 then begin xc:=xb;yc:=yb; end;
temps:=temps-1;
end;

(*effacementd'un bloc*)
procedure K_espace;
var i,numero:integer;
begin
if (matrice[xc,yc]<>chr(tete)) then
begin
gotoxy(decx+xc,decy+yc);write(' ');
matrice[xc,yc]:=' ';
end;
end;

(*procedure de lecture du clavier*)
function lecture_clavier:integer;
var code:integer;
begin
code:=0;
if keypressed then
begin
touche:=readkey;
code:=ord(touche);
if code=0 then
begin
touche:=readkey;
code:=100*ord(touche);
end;
end;
lecture_clavier:=code;
end;

(*procedure test alignement tete*)
function alignement:boolean;
var ok:boolean;
x1,y1,x2,y2,x3,y3:integer;
begin
x1:=bloc[1].x;y1:=bloc[1].y;
x2:=bloc[2].x;y2:=bloc[2].y;
x3:=bloc[3].x;y3:=bloc[3].y;
ok:=false;
(*teste alignement horizontal*)
if (y1=y2) and (y2=y3) then
begin
(*cas 1 2 3*)
if (x2=x1+1) and (x3=x2+1) then ok:=true;
(*cas 3 2 1*)
if (x2=x3+1) and (x1=x2+1) then ok:=true;
(*cas 1 3 2*)
if (x3=x1+1)and (x2=x3+1) then ok:=true;
(*cas 2 3 1*)
if (x3=x2+1) and (x1=x3+1) then ok:=true;
 (* cas 2 1 3 *)
if (x1=x2+1) and (x3=x1+3) then ok:=true;
(* cas 3 1 2 *)
if (x1=x3+1) and (x2=x1+1) then ok:=true;
end;
(* teste un alignement vertical *)
if (x1=x2) and (x2=x3) then
begin
(* cas 1 2 3 *)
if (y2=y1+1) and (y3=y2+1) then ok:=true;
(* cas 3 2 1 *)
if (y2=y3+1) and (y1=y2+1) then ok:=true;
(* cas 1 3 2 *)
 if (y3=y1+1) and (y2=y3+1) then ok:=true;
(* cas 2 3 1 *)
if (y3=y2+1) and (y1=y3+1) then ok:=true;
(* cas 2 1 3 *)
 if (y1=y2+1) and (y3=y1+1) then ok:=true;
(* cas 3 1 2 *)
if (y1=y3+1) and (y2=y1+1) then ok:=true;
end;
alignement:=ok;
end;

(* Jouer le niveau actuel *)
procedure jouer_la_matrice(N:integer);
 var code: integer;
 sortie: boolean;
begin
xc:=longueur div 2;
yc:=longueur div 2;
temps:=150 * N;
repeat code:=lecture_clavier;
case code of
7200: K_haut;
7500: K_gauche;
 7700: K_droit;
 8000: K_bas;
 8200: K_espace;
8300: K_espace;
 56: (* K_8 *) pousse (0,-1);
 52: (* K_4 *) pousse (-1,0);
 54: (* K_6 *) pousse (1,0);
50: (* K_2 *) pousse (0,1);
32: K_espace;
 13: temps:=1;
 end;
temps:=temps-1;
gotoxy(xtemps,ytemps); write(temps:5);
gotoxy(xc+decx,yc+decy); delay(100);
sortie:=(alignement) or (temps<1);
until sortie;
end;

(*creation carre jeu*)
procedure creer_matrice(N:integer);
begin
init;
chaos(N+1);
transfert_liste_bloc;
end;

(*calcul score*)
procedure calcul_score;
var i:integer;
begin
for i:=temps div 15 downto 0 do
begin
sound(i);
score:=score+1;
temps:=temps-15;
if temps<0 then temps:=0;
gotoxy(xtemps,ytemps);write(temps:5);
gotoxy(xscore,yscore);write(score:5);
delay(10);
end;
nosound;
delay(1000);
end;

(*jouer partie entiere*)
procedure jouer_partie(N:integer);
begin
creer_matrice(N);
afficher_matrice;
jouer_la_matrice(N);
if alignement then calcul_score;
end;
 (* racine gestion partie *)
 procedure racine_partie;
 var niveau: integer;
begin
gotoxy(decx,decy-1); write('Appuyez sur une touche');
touche:=readkey;
gotoxy(decx,decy-1); write('                      ');
niveau:=0;
score:=0;
gotoxy(xscore,yscore);
write(0:5);
 repeat
niveau:=niveau+1;
 if niveau>15 then niveau:=15;
 gotoxy(xniveau,yniveau); write(niveau:5);
 jouer_partie(niveau);
 until not(alignement);
end;
 begin
clrscr;
writeln;
writeln('Très heureux de jouer avec vous !');
 delay(3000);
 clrscr;
gotoxy(1,1); Writeln('P.U.S.H.');
writeln('S.V.M.');
 writeln('Jeu de Réflexion');
writeln;writeln;
 writeln('Alignez les Têtes');
 writeln('dans le temps imparti.');
writeln;
writeln('On peut déplacer les');
 writeln('blocs et les têtes.');
 writeln('On peut détruire les blocs.');
 writeln('Les murs n"arrétent rien !');
writeln;
 writeln('Il faut un alignement');
writeln('horizontal ou vertical.');
 writeln;
 writeln('Face:',chr(tete));
 writeln('Bloc:',chr(block));
writeln('Mur:',chr(bord));
gotoxy(1,hauteur+decy+2); writeln('',chr(24),' ',chr(25),' ',chr(27),' ',chr(26),'Pour le curseur (pavé numérique)');
writeln('(Shift) +',chr(24),' ',chr(25),' ',chr(27),' ',chr(26),'Pour les blocs (pavé numérique)');

writeln('(Space) ou (Ins) ou (Del) pour détruire les blocs');
write ('(Enter) si la situation est sans issue');
gotoxy(xscore-7,yscore); write('Score:');
gotoxy(xtemps-7,ytemps); write('Temps:');
 gotoxy(xniveau-7,yniveau); write('Niveau:');
init;afficher_matrice;
 hiscore:=1000;
repeat
 gotoxy(56,8); write('Melleur Score:',hiscore:6);
 gotoxy(56,16); write('----------------------');
racine_partie;
 if score>hiscore then hiscore:=score;
 gotoxy(60,16);
demande:='Autre partie (o/n) ?';
for i:=1 to length(demande) do
begin
gotoxy(60+i-1,16); write(demande[i]); delay(100);
end;
touche:=upcase(readkey);
until touche='N';
end.

mais quand je compile j'ai comme message:

Free Pascal Compiler version 3.0.4+dfsg-18ubuntu2 [2018/08/29] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling jeu.pas
jeu.pas(198,18) Note: Local variable "numero" not used
jeu.pas(237,5) Note: Local variable "i" not used
jeu.pas(237,7) Note: Local variable "numero" not used
Linking jeu
/usr/bin/ld.bfd : avertissement : link.res contient des sections de sortie; avez-vous oublié -T?
437 lines compiled, 0.1 sec
3 note(s) issued

je peux lancer le jeu par ./jeu
mais je ne peux pas bouger le curseur.

Hors ligne

#6 Le 06/01/2019, à 16:23

pingouinux

Re : Fatal: illegal character "''" ($E2) sous freepascal

Je ne pratique pas le langage Pascal, mais voici deux suggestions :
1) Peut-être te retrouves-tu dans une boucle infinie dans laquelle tu ne fais pas de readkey
2) La ligne 161 n'est pas cohérente avec les lignes 155, 156, 160

   154	begin (* deplacement vertical *)
   155	if ye>y then begin yp:=y; yp:=y-1; end;
   156	if ye<y then begin yp:=y;yp:=y+1; end;
   157	end
   158	else
   159	begin (* deplacement horizontal *)
   160	if xe>x then begin xp:=x; xp:=x-1; end;
   161	if ye<y then begin xp:=x;xp:=x+1; end;

Hors ligne

#7 Le 07/01/2019, à 23:40

duocore

Re : Fatal: illegal character "''" ($E2) sous freepascal

pingouinux a écrit :

Je ne pratique pas le langage Pascal, mais voici deux suggestions :
1) Peut-être te retrouves-tu dans une boucle infinie dans laquelle tu ne fais pas de readkey
2) La ligne 161 n'est pas cohérente avec les lignes 155, 156, 160

   154	begin (* deplacement vertical *)
   155	if ye>y then begin yp:=y; yp:=y-1; end;
   156	if ye<y then begin yp:=y;yp:=y+1; end;
   157	end
   158	else
   159	begin (* deplacement horizontal *)
   160	if xe>x then begin xp:=x; xp:=x-1; end;
   161	if ye<y then begin xp:=x;xp:=x+1; end;

j'ai corrigé l'erreur, mais je ne peux toujours pas bouger lecurseur

Merci

Hors ligne

#8 Le 11/01/2019, à 23:26

DRbuntu91

Re : Fatal: illegal character "''" ($E2) sous freepascal

@duocore: j'ai finie par installer FreePascal pour découvrir pleins d'erreurs.
Pour les "flèches" j'ai d'abord écrit un petit programme pour connaître leur valeur:

uses Crt;

{ Program to demonstrate the ReadKey function. }

var ch : char;
var code : integer;
begin
  writeln('Press Left/Right, Esc=Quit');
  repeat
    ch:=ReadKey;
    WriteLn('Char1 ', ch);
    code:=ord(ch);
    WriteLn('Code1 ', code);
    if code = 0 then begin
	ch:=ReadKey;
	WriteLn('Char2 ', ch);
	code:=ord(ch);
	WriteLn('Code2 ', code);
    end
  until ch=#27 {Esc}
end.

Du coup ma procédure jouer_la_matrice est ainsi:

(* Jouer le niveau actuel *)
procedure jouer_la_matrice(N:integer); (* N = niveau *)
var 
 code: integer;
 sortie: boolean;
begin
 xc:=longueur div 2;
 yc:=hauteur div 2;
 temps:=150 * N;
 repeat code:=lecture_clavier;
 (*Fleches:       Up=72, Down = 80, Left = 75, Right = 77 *)
 (*Shift+Fleches: Up=65, Down = 66, Left = 68, Right = 67 *)
 case code of
  7200: K_haut;   (* Touche Up *)
  7500: K_gauche; (* Touche Left *)
  7700: K_droit;  (* Touche Right *)
  8000: K_bas;    (* Touche Down *)
  8200: K_espace;
  8300: K_espace;
  6500:   pousse (0,-1); (* Shift + Up *)
  6800:   pousse (-1,0); (* Shift + Left *)
  6700:   pousse (1,0);  (* Shift + Right *)
  6600:   pousse (0,1);  (* Shift + Down *)
  32: K_espace;
  13: temps:=1; (* Touche CR - Enter *)
 end;
 temps:=temps-1;
 gotoxy(xtemps,ytemps); write(temps:5);
 gotoxy(xc+decx,yc+decy); (* Milieu de carré *)
 delay(100);
 sortie:= (alignement) or (temps<=1);
 until sortie;
end;

Je continue mes test mais  je peux déjà "jouer"!


Portable CLEVO W55SU1, Intel i5-4200M, RAM=8Go, DD=500Go mSATA, BIOS 4.6.5 AMI, Ubuntu 16.04 LTS a jour
Puis pour bidouiller un vieux portable Dell Precision M4600 avec W10 + DEBIAN-Buster
Utilisateur Ubuntu depuis Janvier 2017

Hors ligne

#9 Le 01/02/2019, à 21:39

duocore

Re : Fatal: illegal character "''" ($E2) sous freepascal

@DRbuntu91: j'ai essayé la procédure jouer_la_matrice que tu as modifié en l’intégrant au reste du programme.
Impossible d'y jouer

Hors ligne

#10 Le 01/02/2019, à 21:52

duocore

Re : Fatal: illegal character "''" ($E2) sous freepascal

en compilant voici les erreurs:

fpc jeu
Free Pascal Compiler version 3.0.4+dfsg-18ubuntu2 [2018/08/29] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling jeu.pas
jeu.pas(198,18) Note: Local variable "numero" not used
jeu.pas(237,5) Note: Local variable "i" not used
jeu.pas(237,7) Note: Local variable "numero" not used
Linking jeu
/usr/bin/ld.bfd : avertissement : link.res contient des sections de sortie; avez-vous oublié -T?
441 lines compiled, 0.1 sec
3 note(s) issued

Hors ligne

#11 Le 02/02/2019, à 13:35

DRbuntu91

Re : Fatal: illegal character "''" ($E2) sous freepascal

@duocore: j'imagine que tu es un étudiant, alors je pensais que tu allais chercher un peu toi même pour faire marcher ce programme (par ce que j'ai encore fait d'autres corrections). Sinon je peux donner ma version, mais ce n'est peut-être pas le but....


Portable CLEVO W55SU1, Intel i5-4200M, RAM=8Go, DD=500Go mSATA, BIOS 4.6.5 AMI, Ubuntu 16.04 LTS a jour
Puis pour bidouiller un vieux portable Dell Precision M4600 avec W10 + DEBIAN-Buster
Utilisateur Ubuntu depuis Janvier 2017

Hors ligne

#12 Le 03/02/2019, à 09:04

duocore

Re : Fatal: illegal character "''" ($E2) sous freepascal

Bonjour,

J'ai résolu une partie du programme:
j'ai modifié tete=64,block=42,bord=35
dans la procedure chaos , j'ai rajouté la variable nombre.
dans la procedure pousse, j'ai supprimé numero
dans la procedure K_espace , j'ai supprimé i et numero.

le jeu fonctionne, mais je me retrouve en cours de partie avec les 3 @ alignés a un moment et impossible de passer au niveau suivant.

voici le code modifié:

uses crt;
const
longueur=24; hauteur=14;
 xniveau=67; yniveau=2;
xscore=67; yscore=5;
xtemps=67; ytemps=3;
 decx=28; decy=4;
maxblock=50;
block=42;
 tete=64;
bord=35;
type position = record
 x, y: integer;
 end;
var matrice: array[1..longueur,1..hauteur] of char;
 bloc: array[1..50] of position;
nombre: integer;
touche: char;
temps: integer; (* temps imparti *)
xc,yc: integer; (* coordonnes du curseur dans la matrice *)
score,hiscore: integer;
demande: string[30];
i: integer;

(* matrice mise à blanc *)
procedure init_matrice;
 var i,j: integer;
 begin
for i:=1 to longueur do
for j:=1 to hauteur do
 matrice[i,j]:=' ';
 end;

(* initialisation des variables *)
procedure init_var;
begin
nombre:=0;
 randomize;
 end;

(* initialisation des tètes, placement dans la matrice *)
procedure init_cible;
var x,y,i,hv :integer;
begin
x:=random(longueur-6)+3;
 y:=random(hauteur-6)+3;
 hv:=random(2);
 if hv=0
then begin
for i:=y-1 to y+1 do
begin
matrice[x,i]:=chr(tete);
 nombre:=nombre+1;
end;
 end
else begin
 for i:=x-1 to x+1 do
begin
matrice[i,y]:=chr(tete);
 nombre:=nombre+1;
 end;
 end;
 end;

 (* prépare une matrice *)
 procedure init;
 begin
init_var;
init_matrice;
init_cible;
 end;

(* fonction testant si la ligne est vide *)
function ligne_vide(x,y,xe,ye:integer):boolean;
 var ok: boolean;
 a,b,c,d,i: integer;
 begin ok:=true;
if (x=xe) and (y=ye) then ok:=false;
if x<xe then begin a:=x; c:=xe end
else begin a:=xe; c:=x end;
if y<ye then begin b:=y; d:=ye end
else begin b:=ye; d:=y end;
if (x=xe)
then begin
for i:=b+1 to d do if matrice[a,i]<>' 'then ok:=false;
end
else begin
for i:=a+1 to c do if matrice[i,b]<>' 'then ok:=false;
end;
ligne_vide:=ok;
end;

(*procedure affiche matrice*)
procedure afficher_matrice;
var i,j:integer;
begin
for i:=0 to longueur+1 do
begin
gotoxy(i+decx,decy); write(chr(bord));
gotoxy(i+decx,decy+hauteur+1);write(chr(bord));
end;
for j:=0 to hauteur+1 do
begin
gotoxy(decx,decy+j);write(chr(bord));
gotoxy(decx+longueur+1,decy+j); write(chr(bord));
end;
for i:=1 to longueur do
for j:=1 to hauteur do
begin
gotoxy(i+decx,j+decy);
write(matrice[i,j]);
end;
end;

(*procedure liste block*)
procedure transfert_liste_bloc;
var i,j,k,n:integer;
begin
k:=0;
n:=0;
for i:=1 to longueur do
for j:=1 to hauteur do
begin
if matrice[i,j]=chr(tete) then
begin
k:=k+1;
bloc[k].x:=i; bloc[k].y:=j;
end;
 if matrice[i,j]=chr(block) then
begin
 n:=n+1;
bloc[n].x:=i;bloc[n].y:=j;
 end;
end;
end;

 (* procédure mélangeant la matrice *)
procedure chaos(N:integer);
 var i,x,y,hv,xe,ye,xp,yp,nombre: integer;
begin
 i:=0;
 nombre:=0;
repeat
 transfert_liste_bloc;
 i:=random(nombre)+1;
 x:=bloc[i].x;
 y:=bloc[i].y;
 xe:=bloc[i].x;
 ye:=bloc[i].y;
 hv:=random(2);
if hv=0 then xe:=random(longueur-2)+2 else ye:=random(hauteur- 2)+2;
 if ligne_vide(x,y,xe,ye) then
 begin xp:=x; yp:=y;
 if hv=1
then
begin (* deplacement vertical *)
if ye>y then begin yp:=y; yp:=y-1; end;
if ye<y then begin yp:=y;yp:=y+1; end;
end
else
begin (* deplacement horizontal *)
if xe>x then begin xp:=x; xp:=x-1; end;
if xe<x then begin xp:=x;xp:=x+1; end;
end;
if (xp<=longueur) and (xp>=1) and (yp<=hauteur) and (yp>=1)
then
begin
if matrice[xp,yp]=' ' then
begin
matrice[xe,ye]:=matrice[x,y];
matrice[xp,yp]:=chr(block);
matrice[x,y]:=' ';
nombre:=nombre+1;
end;
end;
end;
until nombre=n
end;

(*procedure gerant le clavier*)
procedure K_haut;
begin
yc:=yc-1; if yc<1 then yc:=1;
end;
procedure K_bas;
begin
yc:=yc+1; if yc>hauteur then yc:=hauteur;
end;
procedure K_gauche;
begin
xc:=xc-1; if xc<1 then xc:=1;
end;
procedure K_droit;
begin
xc:=xc+1; if xc>longueur then yc:=longueur;
end;

(*procedure pousse bloc*)
procedure pousse(xd,yd:integer);
var xb,yb,stop,i:integer;
begin
if matrice[xc,yc]<>' ' then
begin
xb:=xc;yb:=yc;
stop:=0; (*stop =1: collision; stop=2 : sortie*)
repeat
if (xb+xd>longueur)or(xb+xd<1)or(yb+yd>hauteur)or(yb+yd<1) then stop:=2;
if stop=0 then
begin
if matrice[xb+xd,yb+yd]<>' ' then stop:=1;
end;
if stop=0 then
begin
matrice[xb+xd,yb+yd]:=matrice[xb,yb];
matrice[xb,yb]:=' ';
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb]);
xb:=xb+xd;yb:=yb+yd;
gotoxy(decx+xb,decy+yb);write(matrice[xb,yb]);
delay(125);temps:=temps-1;
end;
until stop<>0;
if stop=2 then
begin
for i:=100 to 800 do sound(i);nosound;
matrice[xc,yc]:=matrice[xb,yb];
matrice[xb,yb]:=' ';
gotoxy(decx+xb,decy+yb);write(' ');
gotoxy(decx+xc,decy+yc);write(matrice[xc,yc]);
xb:=xc;yb:=yc;
end;
end;
transfert_liste_bloc;(*pour test alignement*)
if stop=1 then begin xc:=xb;yc:=yb; end;
temps:=temps-1;
end;

(*effacementd'un bloc*)
procedure K_espace;
begin
if (matrice[xc,yc]<>chr(tete)) then
begin
gotoxy(decx+xc,decy+yc);write(' ');
matrice[xc,yc]:=' ';
end;
end;

(*procedure de lecture du clavier*)
function lecture_clavier:integer;
var code:integer;
begin
code:=0;
if keypressed then
begin
touche:=readkey;
code:=ord(touche);
if code=0 then
begin
touche:=readkey;
code:=100*ord(touche);
end;
end;
lecture_clavier:=code;
end;

(*procedure test alignement tete*)
function alignement:boolean;
var ok:boolean;
x1,y1,x2,y2,x3,y3:integer;
begin
x1:=bloc[1].x;y1:=bloc[1].y;
x2:=bloc[2].x;y2:=bloc[2].y;
x3:=bloc[3].x;y3:=bloc[3].y;
ok:=false;
(*teste alignement horizontal*)
if (y1=y2) and (y2=y3) then
begin
(*cas 1 2 3*)
if (x2=x1+1) and (x3=x2+1) then ok:=true;
(*cas 3 2 1*)
if (x2=x3+1) and (x1=x2+1) then ok:=true;
(*cas 1 3 2*)
if (x3=x1+1)and (x2=x3+1) then ok:=true;
(*cas 2 3 1*)
if (x3=x2+1) and (x1=x3+1) then ok:=true;
 (* cas 2 1 3 *)
if (x1=x2+1) and (x3=x1+3) then ok:=true;
(* cas 3 1 2 *)
if (x1=x3+1) and (x2=x1+1) then ok:=true;
end;
(* teste un alignement vertical *)
if (x1=x2) and (x2=x3) then
begin
(* cas 1 2 3 *)
if (y2=y1+1) and (y3=y2+1) then ok:=true;
(* cas 3 2 1 *)
if (y2=y3+1) and (y1=y2+1) then ok:=true;
(* cas 1 3 2 *)
 if (y3=y1+1) and (y2=y3+1) then ok:=true;
(* cas 2 3 1 *)
if (y3=y2+1) and (y1=y3+1) then ok:=true;
(* cas 2 1 3 *)
 if (y1=y2+1) and (y3=y1+1) then ok:=true;
(* cas 3 1 2 *)
if (y1=y3+1) and (y2=y1+1) then ok:=true;
end;
alignement:=ok;
end;

(* Jouer le niveau actuel *)
procedure jouer_la_matrice(N:integer); (* N = niveau *)
var 
 code: integer;
 sortie: boolean;
begin
 xc:=longueur div 2;
 yc:=hauteur div 2;
 temps:=150 * N;
 repeat code:=lecture_clavier;
 (*Fleches:       Up=72, Down = 80, Left = 75, Right = 77 *)
 (*Shift+Fleches: Up=65, Down = 66, Left = 68, Right = 67 *)
 case code of
  7200: K_haut;   (* Touche Up *)
  7500: K_gauche; (* Touche Left *)
  7700: K_droit;  (* Touche Right *)
  8000: K_bas;    (* Touche Down *)
  8200: K_espace;
  8300: K_espace;
  6500:   pousse (0,-1); (* Shift + Up *)
  6800:   pousse (-1,0); (* Shift + Left *)
  6700:   pousse (1,0);  (* Shift + Right *)
  6600:   pousse (0,1);  (* Shift + Down *)
  32: K_espace;
  13: temps:=1; (* Touche CR - Enter *)
 end;
 temps:=temps-1;
 gotoxy(xtemps,ytemps); write(temps:5);
 gotoxy(xc+decx,yc+decy); (* Milieu de carré *)
 delay(100);
 sortie:= (alignement) or (temps<=1);
 until sortie;
end;

(*creation carre jeu*)
procedure creer_matrice(N:integer);
begin
init;
chaos(N+1);
transfert_liste_bloc;
end;

(*calcul score*)
procedure calcul_score;
var i:integer;
begin
for i:=temps div 15 downto 0 do
begin
sound(i);
score:=score+1;
temps:=temps-15;
if temps<0 then temps:=0;
gotoxy(xtemps,ytemps);write(temps:5);
gotoxy(xscore,yscore);write(score:5);
delay(10);
end;
nosound;
delay(1000);
end;

(*jouer partie entiere*)
procedure jouer_partie(N:integer);
begin
creer_matrice(N);
afficher_matrice;
jouer_la_matrice(N);
if alignement then calcul_score;
end;
 
 (* racine gestion partie *)
procedure racine_partie;
var niveau: integer;
begin
gotoxy(decx,decy-1); write('Appuyez sur une touche');
touche:=readkey;
gotoxy(decx,decy-1); write('                      ');
niveau:=0;
score:=0;
gotoxy(xscore,yscore);
write(0:5);
 repeat
niveau:=niveau+1;
 if niveau>15 then niveau:=15;
 gotoxy(xniveau,yniveau); write(niveau:5);
 jouer_partie(niveau);
 until not(alignement);
end;
 begin
clrscr;
writeln;
writeln('Très heureux de jouer avec vous !');
 delay(3000);
 clrscr;
gotoxy(1,1); Writeln('P.U.S.H.');
writeln('S.V.M.');
 writeln('Jeu de Réflexion');
writeln;writeln;
 writeln('Alignez les Têtes');
 writeln('dans le temps imparti.');
writeln;
writeln('On peut déplacer les');
 writeln('blocs et les têtes.');
 writeln('On peut détruire les blocs.');
 writeln('Les murs n"arrétent rien !');
writeln;
 writeln('Il faut un alignement');
writeln('horizontal ou vertical.');
 writeln;
 writeln('Face:',chr(tete));
 writeln('Bloc:',chr(block));
writeln('Mur:',chr(bord));
gotoxy(1,hauteur+decy+2); writeln('',chr(72),' ',chr(75),' ',chr(77),' ',chr(80),' ','Pour le curseur (pavé numérique)');
writeln('(Shift) +',chr(72),' ',chr(75),' ',chr(77),' ',chr(80),' ','Pour les blocs (pavé numérique)');

writeln('(Space) ou (Ins) ou (Del) pour détruire les blocs');
write ('(Enter) si la situation est sans issue');
gotoxy(xscore-7,yscore); write('Score:');
gotoxy(xtemps-7,ytemps); write('Temps:');
 gotoxy(xniveau-7,yniveau); write('Niveau:');
init;afficher_matrice;
 hiscore:=1000;
repeat
 gotoxy(56,8); write('Melleur Score:',hiscore:6);
 gotoxy(56,16); write('----------------------');
racine_partie;
 if score>hiscore then hiscore:=score;
 gotoxy(60,16);
demande:='Autre partie (o/n) ?';
for i:=1 to length(demande) do
begin
gotoxy(60+i-1,16); write(demande[i]); delay(100);
end;
touche:=upcase(readkey);
until touche='N';
end.

Hors ligne

#13 Le 04/02/2019, à 20:02

DRbuntu91

Re : Fatal: illegal character "''" ($E2) sous freepascal

Voici mon code

uses crt;
const
longueur=24; hauteur=14;
xniveau=67; yniveau=2;
xscore=67; yscore=5;
xtemps=67; ytemps=3;
decx=28; decy=4;
maxblock=50;
block=64;
tete=35;
bord=111;
type position = record
 x, y: integer;
end;

var 
matrice: array[1..longueur,1..hauteur] of char;
bloc: array[1..50] of position;
nombre: integer;
touche: char;
temps: integer; (* temps imparti *)
xc,yc: integer; (* coordonnes du curseur dans la matrice *)
score,hiscore: integer;
demande: string[30];
i: integer;

(* matrice mise à blanc *)
procedure init_matrice;
var i,j: integer;
begin
 for i:=1 to longueur do for j:=1 to hauteur do
  matrice[i,j]:=' ';
end;
 
(* initialisation des variables *)
procedure init_var;
begin
 nombre:=0;
 randomize;
end;

(* initialisation des tètes, placement dans la matrice *)
procedure init_cible;
var x,y,i,hv: integer;
begin
 x:=random(longueur-6)+3;
 y:=random(hauteur-6)+3;
 hv:=random(2);
 if hv=0 then begin
   for i:=y-1 to y+1 do begin
     matrice[x,i]:=chr(tete);
     nombre:=nombre+1;
   end;
 end else begin
  for i:=x-1 to x+1 do begin
    matrice[i,y]:=chr(tete);
    nombre:=nombre+1;
  end;
 end;
end;

(* prépare une matrice *)
procedure init;
begin
 init_var;
 init_matrice;
 init_cible;
end;

(* fonction testant si la ligne est vide *)
function ligne_vide(x,y,xe,ye:integer):boolean;
var ok: boolean;
a,b,c,d,i: integer;
begin 
  ok:=true;
  if (x=xe) and (y=ye) then ok:=false;
  if (x<xe) then begin 
    a:=x; c:=xe 
  end else begin 
    a:=xe; c:=x 
  end;
  if (y<ye) then begin 
    b:=y; d:=ye 
  end else begin 
    b:=ye; d:=y 
  end;
  if (x=xe) then begin
   for i:=b+1 to d do if matrice[a,i]<>' 'then ok:=false;
  end else begin
   for i:=a+1 to c do if matrice[i,b]<>' 'then ok:=false;
  end;
 ligne_vide:=ok;
end;

(*procedure affiche matrice*)
procedure afficher_matrice;
var i,j: integer;
begin
 for i:=0 to longueur+1 do begin
   gotoxy(i+decx,decy); write(char(bord));
   gotoxy(i+decx,decy+hauteur+1 ); write(char(bord));
 end;
 for i:=0 to hauteur+1 do begin
   gotoxy(decx,decy+i); write(char(bord));
   gotoxy(decx+longueur+1,decy+i); write(char(bord));
 end;
 for i:=1 to longueur do for j:=1 to hauteur do begin
   gotoxy(i+decx,j+decy);
   write(matrice[i,j]);
 end;
end;

(*procedure liste block*)
procedure transfert_liste_block;
var i,j,k,n:integer;
begin
 k:=0; n:=0;
 for i:=1 to longueur do for j:=1 to hauteur do begin
  if matrice[i,j]=chr(tete) then begin
   k:=k+1;
   bloc[k].x:=i; bloc[k].y:=j;
  end;
  if matrice[i,j]=chr(block) then begin
   n:=n+1;
   bloc[n].x:=i;bloc[n].y:=j;
  end;
 end;
end;

(* procédure mélangeant la matrice *)
procedure chaos(N:integer); (* N = niveau *)
var i,x,y,hv,xe,ye,xp,yp: integer;
begin
 i:=0;
 repeat
  transfert_liste_block;
  i:=random(nombre)+1;
  x:=bloc[i].x;
  y:=bloc[i].y;
  xe:=bloc[i].x; 
  ye:=bloc[i].y;
  hv:=random(2);
  if hv=0 then xe:=random(longueur-2)+2 else ye:=random(hauteur-2)+2;
  if ligne_vide(x,y,xe,ye) then begin 
   xp:=x; yp:=y;
   if hv=1 then begin (* deplacement vertical *)
    if ye>y then begin yp:=y; yp:=y-1; end;
    if ye<y then begin yp:=y; yp:=y+1; end;
   end else begin (* deplacement horizontal *)
    if xe>x then begin xp:=x; xp:=x-1; end;
    if ye<y then begin xp:=x; xp:=x+1; end;
   end;
  end;
  if (xp<=longueur) and (xp>=1) and (yp<=hauteur) and (yp>=1) then begin
   if matrice[xp,yp]=' ' then begin
    matrice[xe,ye]:=matrice[x,y];
    matrice[xp,yp]:=chr(block);
    matrice[x,y]:=' ';
    nombre:=nombre+1;
   end;
  end;
 until nombre > N;
end;

(*procedure gerant le clavier*)
procedure K_haut;
begin
 yc:=yc-1; 
 if yc<1 then yc:=1;
end;

procedure K_bas;
begin
 yc:=yc+1; 
 if yc>hauteur then yc:=hauteur;
end;

procedure K_gauche;
begin
 xc:=xc-1; 
 if xc<1 then xc:=1;
end;

procedure K_droit;
begin
 xc:=xc+1; 
 if xc>longueur then yc:=longueur;
end;

(*procedure pousse bloc*)
procedure pousse(xd,yd:integer);
var xb,yb,stop,i:integer;
begin
if matrice[xc,yc]<>' ' then begin
 xb:=xc; yb:=yc;
 stop:=0; (*stop =1: collision; stop=2 : sortie*)
 repeat
  if (xb+xd>longueur)or(xb+xd<1)or(yb+yd>hauteur)or(yb+yd<1) then stop:=2;
  if stop=0 then begin
    if matrice[xb+xd,yb+yd]<>' ' then stop:=1;
  end;
  if stop=0 then begin
   matrice[xb+xd,yb+yd]:=matrice[xb,yb];
   matrice[xb,yb]:=' ';
   gotoxy(decx+xb,decy+yb); write(matrice[xb,yb]);
   xb:=xb+xd; yb:=yb+yd;
   gotoxy(decx+xb,decy+yb); write(matrice[xb,yb]);
   delay(125); temps:=temps-1;
  end;
 until stop<>0;
 if stop=2 then begin
   for i:=100 to 800 do sound(i); nosound; begin
    matrice[xc,yc]:=matrice[xb,yb];
    matrice[xb,yb]:= ' ';
    gotoxy(decx+xb,decy+yb); write(' ');
    gotoxy(decx+xc,decy+yc); write(matrice[xc,yc]);
    xb:=xc; yb:=yc;
   end;
  end;
 transfert_liste_block;(*pour test alignement*)
 if stop=1 then begin 
  xc:=xb; yc:=yb; 
 end;
 temps:=temps-1;
end;
end;

(*effacement d’un bloc*)
procedure K_espace;
begin
 if (matrice[xc,yc]<>chr(tete)) then begin
  gotoxy(decx+xc,decy+yc); write(' ');
  matrice[xc,yc]:=' ';
 end;
end;

(*procedure de lecture du clavier *)
(*si code = 0 alors il s'agit de Schift+Touche, alors il faut lire une deuxieme fois *)
function lecture_clavier:integer;
var code:integer;
begin
 code:=0;
  touche:=readkey;
  code:=ord(touche);
  if code=0 then begin
   touche:=readkey;
   code:=100*ord(touche); (*Donc la fleche Shift+Up devient 7200  *)
  end;
 lecture_clavier:=code;
end;

(*procedure test alignement tete*)
function alignement:boolean;
var 
 ok:boolean; 
 x1,y1,x2,y2,x3,y3:integer;
begin
 x1:=bloc[1].x; y1:=bloc[1].y;
 x2:=bloc[2].x; y2:=bloc[2].y;
 x3:=bloc[3].x; y3:=bloc[3].y;
 ok:=false;
 (*teste alignement horizontal*)
 if (y1=y2) and (y2=y3) then begin
  (*cas 1 2 3*)
  if (x2=x1+1) and (x3=x2+1) then ok:=true;
  (*cas 3 2 1*)
  if (x2=x3+1) and (x1=x2+1) then ok:=true;
  (*cas 1 3 2*)
  if (x3=x1+1)and (x2=x3+1) then ok:=true;
  (*cas 2 3 1*)
  if (x3=x2+1) and (x1=x3+1) then ok:=true;
  (* cas 2 1 3 *)
  if (x1=x2+1) and (x3=x1+3) then ok:=true;
  (* cas 3 1 2 *)
  if (x1=x3+1) and (x2=x1+1) then ok:=true;
 end;
 (* teste un alignement vertical *)
 if (x1=x2) and (x2=x3) then begin
  (* cas 1 2 3 *)
  if (y2=y1+1) and (y3=y2+1) then ok:=true;
  (* cas 3 2 1 *)
  if (y2=y3+1) and (y1=y2+1) then ok:=true;
  (* cas 1 3 2 *)
  if (y3=y1+1) and (y2=y3+1) then ok:=true;
  (* cas 2 3 1 *)
  if (y3=y2+1) and (y1=y3+1) then ok:=true;
  (* cas 2 1 3 *)
  if (y1=y2+1) and (y3=y1+1) then ok:=true;
  (* cas 3 1 2 *)
  if (y1=y3+1) and (y2=y1+1) then ok:=true;
 end;
alignement:=ok;
end;

(* Jouer le niveau actuel *)
procedure jouer_la_matrice(N:integer); (* N = niveau *)
var 
 code: integer;
 sortie: boolean;
begin
 xc:=longueur div 2;
 yc:=hauteur div 2;
 temps:=150 * N;
 repeat code:=lecture_clavier;
 (*Fleches:       Up=72, Down = 80, Left = 75, Right = 77 *)
 (*Shift+Fleches: Up=65, Down = 66, Left = 68, Right = 67 *)
 case code of
  7200: K_haut;   (* Touche Up *)
  7500: K_gauche; (* Touche Left *)
  7700: K_droit;  (* Touche Right *)
  8000: K_bas;    (* Touche Down *)
  8200: K_espace;
  8300: K_espace;
  6500:   pousse (0,-1); (* Shift + Up *)
  6800:   pousse (-1,0); (* Shift + Left *)
  6700:   pousse (1,0);  (* Shift + Right *)
  6600:   pousse (0,1);  (* Shift + Down *)
  32: K_espace;
  13: temps:=1; (* Touche CR - Enter *)
 end;
 temps:=temps-1;
 gotoxy(xtemps,ytemps); write(temps:5);
 gotoxy(xc+decx,yc+decy); (* Milieu de carré *)
 delay(100);
 sortie:= (alignement) or (temps<=1);
 until sortie;
end;

(*creation carre jeu*)
procedure creer_matrice(N:integer); (* N = niveau *)
begin
 init;
 chaos(N+1);
 transfert_liste_block;
end;

(*calcul score*)
procedure calcul_score;
var i:integer;
begin
 for i:=temps div 15 downto 0 do begin
  sound(i);
  score:=score+1;
  temps:=temps-15;
  if temps<0 then temps:=0;
  gotoxy(xtemps,ytemps); write(temps:5);
  gotoxy(xscore,yscore); write(score:5);
  delay(10);
 end;
 if score>hiscore then begin 
   hiscore:=score; 
   gotoxy(74,8); write(hiscore:6); 
 end;
 nosound;
 delay(1000);
end;

(*jouer partie entiere*)
procedure jouer_partie(N:integer); (* N = niveau *)
begin
 creer_matrice(N); (* init + chaos + transfert_list_block *)
 afficher_matrice;
 jouer_la_matrice(N);
 if alignement then calcul_score;
end;

(* racine gestion partie *)
procedure racine_partie;
var niveau: integer;
begin
 gotoxy(20,1); write('Pour démarrer le jeu appuyez sur une touche');
 touche:=readkey;
 niveau:=0;
 score:=0;
 gotoxy(xscore,yscore); write(0:5);
 repeat
  niveau:=niveau+1;
  if niveau>15 then niveau:=15;
  gotoxy(xniveau,yniveau); write(niveau:5);
  jouer_partie(niveau);
 until not(alignement);
end;

begin
 clrscr;
 writeln;
 writeln('Très heureux de jouer avec vous !');
 delay(300);
 clrscr;
 gotoxy(1,1); Writeln('P.U.S.H.');
 writeln('S.V.M.');
 writeln('Jeu de Réflexion');
 writeln;writeln;
 writeln('Alignez les Têtes');
 writeln('dans le temps imparti.');
 writeln;
 writeln('On peut déplacer les');
 writeln('blocs et les têtes.');
 writeln('On peut détruire les blocs.');
 writeln('Les murs n''arrétent rien !');
 writeln;
 writeln('Il faut un alignement');
 writeln('horizontal ou vertical.');
 writeln;
 writeln('Face:',char(tete));
 writeln('Bloc:',char(block));
 writeln('Mur :',char(bord));
 writeln('Utilisez les fleches pour se déplacer');
 writeln('Utlisez Shift+Fleches pour déplacer un bloc');
 writeln('(Space) ou (Ins) ou (Del) pour effacer un bloc');
 writeln('(Enter) si la situation est sans issue');
 gotoxy(xscore-7,yscore); write('Score:');
 gotoxy(xtemps-7,ytemps); write('Temps:');
 gotoxy(xniveau-7,yniveau); write('Niveau:');
 init;
 afficher_matrice;
 hiscore:=100;
 repeat
  gotoxy(60,8); write('Melleur Score:',hiscore:6);
  gotoxy(60,9); write('---------------------');
  racine_partie;
  if score>hiscore then hiscore:=score;
  gotoxy(60,9); demande:='Autre partie (o/n)  ?';
  for i:=1 to length(demande) do begin
   gotoxy(60+i-1,9); write(demande[i]); delay(100);
  end;
  touche:=upcase(readkey);
 until touche = 'N';
 end.

Portable CLEVO W55SU1, Intel i5-4200M, RAM=8Go, DD=500Go mSATA, BIOS 4.6.5 AMI, Ubuntu 16.04 LTS a jour
Puis pour bidouiller un vieux portable Dell Precision M4600 avec W10 + DEBIAN-Buster
Utilisateur Ubuntu depuis Janvier 2017

Hors ligne

#14 Le 05/02/2019, à 09:53

DRbuntu91

Re : Fatal: illegal character "''" ($E2) sous freepascal

duocore a écrit :

le jeu fonctionne, mais je me retrouve en cours de partie avec les 3 @ alignés a un moment et impossible de passer au niveau suivant.

Après coup je me suis souvenu que parfois il m'arrive la même chose.
Dans ce cas je dois effacer les autres @ autour du bloc de trois et faire bouger une dernière fois une des trois @ pour passer au niveau suivant.
Je n'ai pas essayé d'analyser d’où vient ce bug.


Portable CLEVO W55SU1, Intel i5-4200M, RAM=8Go, DD=500Go mSATA, BIOS 4.6.5 AMI, Ubuntu 16.04 LTS a jour
Puis pour bidouiller un vieux portable Dell Precision M4600 avec W10 + DEBIAN-Buster
Utilisateur Ubuntu depuis Janvier 2017

Hors ligne