Program snake; { By Oligoatria 12/05 }
uses crt;
{ definizione type e variabili per il salvataggio dell'highscore }
type
rec = record
nome: string;
punti: integer;
lunghezza: integer;
end;
var
high: array[1..10] of rec;
i2: integer;
recsi: boolean;
{ salvataggio su file }
save: file of rec;
const
Cdelay=80;
var
x,y: integer;
{ movimento snake }
v: array[1..100] of integer;
Vdelay: integer;
(*su,destra: boolean;*)
x1,y1: array[1..100] of integer;
tmp,i,j,lun: integer;
com: char;
mov: array[1..100] of integer; (* 1 = sinistra -- 2 = destra -- 3 = su -- 4 = giu *)
(* se si vuole fare un tipo di movimento che segue la visuale
dello snake basta fare un mov a scalare in senso antiorario *)
{ punti e bonus }
x2,y2,x3,y3,count: integer;
vite,punti:integer;
com2: char;
imm: char;
Procedure grafica; (* da pong, sempre by GDL3BAB *)
begin
clrscr;
textcolor(red);
gotoxy(1,1);
for i:=1 to 70 do
write('Ä');
gotoxy(1,40);
for i:=1 to 70 do
write('Ä');
for y:=1 to 40 do
begin
gotoxy(1,y);
write('³');
end;
for y:=1 to 40 do
begin
gotoxy(70,y);
write('³');
end;
gotoxy(1,40);
write('À');
gotoxy(70,1);
write('¿');
gotoxy(70,40);
write('Ù');
gotoxy(1,1);
write('Ú');
end;
Procedure comsnake;
begin
if keypressed then
begin
com:=readkey;
(* Snake non pu• tornare indietro a 180ø *)
if (mov[1]=1) and (com='6') then
sound(150)
else
if (mov[1]=2) and (com='4') then
sound(150)
else
if (mov[1]=3) and (com='5') then
sound(150)
else
if (mov[1]=4) and (com='8') then
sound(150)
else
begin
if (com='p') then
repeat until keypressed;
case com of
'4': mov[1]:=1;
'6': mov[1]:=2;
'8': mov[1]:=3;
'5': mov[1]:=4;
end;
end;
end;
end;
Procedure movsnake;
begin
case mov[i] of
1: x1[i]:=x1[i]-1;
2: x1[i]:=x1[i]+1;
3: y1[i]:=y1[i]-1;
4: y1[i]:=y1[i]+1;
end;
(* RALLENTA AI BORDI *)
if (x1[1]<4) or (x1[1]>67) or (y1[1]<4) or (y1[1]>37) then
Vdelay:=Cdelay + 50;
end;
Procedure writesnake;
begin
for i:=1 to lun do
begin
gotoxy(x1[i],y1[i]);
write(' ');
end;
comsnake;
for i:=1 to lun do
movsnake;
for i:=1 to lun do
begin
textcolor(yellow);
gotoxy(x1[i],y1[i]);
write('é');
end;
end;
Procedure copiamov;
begin
for tmp:=lun-1 downto 1 do
mov[tmp+1]:=mov[tmp];
end;
Procedure writebonus;
begin
textcolor(green);
gotoxy(x2,y2);
write('è');
gotoxy(70,50);
textcolor(0);
write(' ');
end;
Procedure contattobonus;
begin
if (x1[1]=x2) and (y1[1]=y2) then
begin
punti:=punti+10;
x2:=random(68)+2;
y2:=random(38)+2;
lun:=lun+1;
i:=lun-1;
case mov[i] of
1: begin
x1[lun]:=x1[i]+1;
y1[lun]:=y1[i];
end;
2: begin
x1[lun]:=x1[i]-1;
y1[lun]:=y1[i];
end;
3: begin
x1[lun]:=x1[i];
y1[lun]:=y1[i]+1;
end;
4: begin
x1[lun]:=x1[i];
y1[lun]:=y1[i]-1;
end;
end;
sound(300);
end;
if (x1[1]=x3) and (y1[1]=y3) then
begin
count:=100;
punti:=punti+50;
sound(400);
end;
end;
Procedure punti_;
begin
gotoxy(2,48);
textcolor(white);
writeln('Punti = ',punti);
write('Lunghezza = ',lun);
end;
Procedure contatti_morte;
begin
for i:=1 to lun do
for j:=1 to lun do
if (x1[i]=x1[j]) and (y1[i]=y1[j]) then
if i<>j then
begin
vite:=vite-1;
sound(500);
end;
for i:=1 to lun do
begin
if (x1[i]<2) or (x1[i]>69) or (y1[i]<2) or (y1[i]>39) then
begin
vite:=vite-1;
sound(500);
end;
end;
end;
Procedure bonus2_;
begin
count:=count+1;
textcolor(yellow);
if (count>50) and (count<100) then
begin
gotoxy(x3,y3);
case imm of (* IDEA GRAFICA BY BERGAMIN MARCO *)
'/': imm:='|';
'|': imm:='\';
'\': imm:='Ä';
'Ä': imm:='/';
end;
write(imm);
gotoxy(70,50);
textcolor(0);
write(' ');
end
else
if count=50 then
begin
x3:=random(68)+2;
y3:=random(38)+2;
end
else
if count=100 then
begin
gotoxy(x3,y3);
write(' ');
x3:=50;
y3:=50;
end;
if count=400 then
count:=0;
(* aumento velocit… *)
if ((lun mod 10)=0) then
begin
Vdelay:=Vdelay-40;
x2:=x1[1];
y2:=y1[1];
end;
end;
Procedure scrivi_record;
begin
clrscr;
RESET(SAVE);
FOR I:=1 TO 10 DO
READ(SAVE,HIGH[I]);
gotoxy(1,1);
write('NOME');
gotoxy(20,1);
write('PUNTEGGIO');
gotoxy(40,1);
write('LUNGHEZZA');
for i:=1 to 10 do
begin
gotoxy(1,i+2);
write(high[i].nome);
gotoxy(20,i+2);
write(high[i].punti);
gotoxy(40,i+2);
write(high[i].lunghezza);
end;
readln;
CLOSE(SAVE);
end;
Procedure trova_record;
begin
RESET(SAVE);
clrscr;
recsi:=false;
i:=1;
while (recsi=false) and (i<=10) do
begin
if punti>high[i].punti then
begin
for i2:=10 downto (i+1) do
begin
high[i2].punti:=high[i2-1].punti;
high[i2].nome:=high[i2-1].nome;
high[i2].lunghezza:=high[i2-1].lunghezza;
end;
high[i].punti:=punti;
high[i].lunghezza:=lun;
writeln('Scrivi il tuo nome');
readln(high[i].nome);
recsi:=true;
for i:=1 to 10 do
WRITE(SAVE,HIGH[I]);
scrivi_record;
end;
i:=i+1;
end;
end;
begin
imm:='/';
count:=0;
textcolor(white);
repeat
ASSIGN(SAVE, 'SAVE.TXT');
clrscr;
writeln('[1] = Gioca');
writeln('[2] = High Score');
writeln('[3] = Esci');
com2:=readkey;
if com2='1' then
begin
clrscr;
randomize;
grafica;
(* INIZIALIZZAZIONE SNAKE E COORDINATE PUNTI E BONUS *)
vite:=1;
punti:=0;
x2:=random(68)+2;
y2:=random(38)+2;
x3:=random(68)+2;
y3:=random(38)+2;
lun:=5;
for i:=1 to lun do
begin
mov[i]:=2;
x1[i]:=38-i;
y1[i]:=20;
end;
while (com<>'\') and (vite>0) do
begin
Vdelay:=Cdelay;
copiamov;
writesnake;
writebonus;
bonus2_;
contattobonus;
punti_;
contatti_morte;
delay(Vdelay);
nosound;
end;
trova_record;
end
else
if com2='õ' then
begin
readln(punti);
readln(lun);
trova_record;
end
else
if com2='2' then
begin
scrivi_record;
end;
until com2='3';
end.