Sei sulla pagina 1di 4

program gamesnake;

uses crt;
label
habis, lanjut;
const
max_panjang = 100;
batas_x = 80;
batas_y = 24;
speed = 200;
type
tempat = record
x, y : integer;
end;
var
ekor : array[1..max_panjang] of tempat;
ujung, makanan : tempat;
tkn, u : char;
i,pjg,skor,skorr,spd,topskor : integer;
mati : boolean;

procedure atur_posisi;
begin
textbackground(red);
TEXTCOLOR(cyan);
ujung.x := ekor[pjg].x;
ujung.y := ekor[pjg].y;
for i:=pjg downto 2 do begin
ekor[i].x := ekor[i-1].x;
ekor[i].y := ekor[i-1].y;
end;
gotoxy(ekor[2].x, ekor[2].y); write('C');
gotoxy(ekor[3].x, ekor[3].y); write('0');
gotoxy(ekor[pjg-1].x, ekor[pjg-1].y); write('0');
gotoxy(ujung.x, ujung.y); write(' ');
for i:=3 to pjg do if((ekor[2].x=ekor[i].x) and (ekor[2].y=ekor[i].y)) then
mati:=true;
delay(speed-spd);
end;

procedure makan;
var beda : boolean;
begin
clrscr;
TEXTCOLOR(yellow);
inc(skor,5);
gotoxy(10,25); write('Skor = ',skor);
inc(skorr,5);
topskor:=skorr;
gotoxy(30,25); write('Top Skor = ',topskor); textbackground(blue);

for i:=1 to 80 do begin


gotoxy(i,1); write(' ');
gotoxy(i,24); write(' ');
end;
for i:=2 to 23 do begin
gotoxy(1,i); write(' ');
gotoxy(80,i); write(' ');
spd:=speed-150;
if skor=10 then
spd:=speed-125;
if skor=15 then
spd:=speed-100;
if skor=20 then
spd:=speed-75;
if skor=25 then
spd:=speed-50;
if skor=30 then
spd:=speed-35;
if skor=35 then
spd:=speed-25;
if skor=40 then
spd:=speed-20;
if skor=45 then
spd:=speed-15;
if skor=50 then
spd:=speed-10;
end;
repeat
beda := true;
makanan.x := random(batas_x-2)+2;
makanan.y := random(batas_y-2)+2;
for i:=1 to pjg do
if((makanan.x=ekor[i].x) and (makanan.y=ekor[i].y)) then beda:=false;
until beda;
textbackground(red);
TEXTCOLOR(yellow);
gotoxy(makanan.x, makanan.y); write('o');
inc(pjg);
inc(spd,2);
end;

procedure bergerak(c : char);


begin
if c = 'd' then begin
repeat
if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
ekor[1].x := ekor[1].x+1;
atur_posisi;
if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or
(ekor[1].y = 1) then mati := true;
until keypressed or mati;
if mati then exit;
tkn:=readkey;
if tkn = 'a' then tkn:='d';
end
else if c = 's' then begin
repeat
if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
ekor[1].y := ekor[1].y+1;
atur_posisi;
if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or
(ekor[1].y = 1) then mati := true;
until keypressed or mati;
if mati then exit;
tkn:=readkey;
if tkn = 'w' then tkn:='s';
end
else if c = 'w' then begin
repeat
if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
ekor[1].y := ekor[1].y-1;
atur_posisi;
if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or
(ekor[1].y = 1) then mati := true;
until keypressed or mati;
if mati then exit;
tkn:=readkey;
if tkn = 's' then tkn:='w';
end
else if c = 'a' then begin
repeat
if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
ekor[1].x := ekor[1].x-1;
atur_posisi;
if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or
(ekor[1].y = 1) then mati := true;
until keypressed or mati;
if mati then exit;
tkn:=readkey;
if tkn = 'd' then tkn:='a';
end;
end;
begin
repeat
textbackground(red);
tkn:='d';
mati := false;
randomize;
pjg := 7; spd := 0; skor:=0;
makanan.x := random(batas_x-2)+2;
makanan.y := random(batas_y-2)+2;
ekor[1].x := 40; //respown
ekor[1].y := 10;
for i:=2 to pjg do begin
ekor[i].x := ekor[i-1].x;
ekor[i].y := 10;
end;

lanjut:
clrscr;
TEXTCOLOR(yellow);
inc(skor,0);
gotoxy(10,25); write('Skor = ',skor);
inc(skorr,0);
topskor:=skorr;
gotoxy(30,25); write('Top Skor = ',topskor);
textbackground(blue);
for i:=1 to 80 do begin
gotoxy(i,1); write(' ');
gotoxy(i,24); write(' ');
end;
for i:=2 to 23 do begin
gotoxy(1,i); write(' ');
gotoxy(80,i); write(' ');
end;
for i:=1 to pjg do begin
gotoxy(ekor[i].x, ekor[i].y);
TEXTCOLOR(cyan);
write('0');
end;
textbackground(red);
TEXTCOLOR(yellow);
gotoxy(makanan.x, makanan.y); write('o');
repeat
if((tkn='w') or (tkn='a') or (tkn='s') or (tkn='d')) then bergerak(tkn)
else begin
repeat
TEXTCOLOR(white);
gotoxy(20,11); write(' ..Paused Game..');
repeat
gotoxy(20,13); write('..Press w, a, s or d to Play again..'); delay(200);
gotoxy(20,13); write(' '); delay(200);
until keypressed;
tkn:=readkey;
until((tkn='w') or (tkn='a') or (tkn='s') or (tkn='d')); goto lanjut;
end;
if mati then goto habis;
until (tkn = #7) or mati;
habis:
TEXTCOLOR(white);
gotoxy(30,10); write(' GAME OVER ');
gotoxy(24,11); write(' Your Top Skor : ',topskor);delay(200);
gotoxy(30,12); write(' Try Again Y/N : ');
readln(u);
until u='N';
end.

Potrebbero piacerti anche