исходный код программы.
код (Показать/Скрыть)
program zmeika;
uses crt;
type
spoint=record
x:integer;
y:integer;
end;
const
maxwidth=15;
var
width:integer;
e:spoint;
snakebody:array[1..maxwidth] of spoint;
i, nx,ny:integer;
v:byte;
gameover:boolean;
key:char;
function checknext(x:integer;y:integer):boolean;
var
isset:boolean;
i:integer;
begin
isset:=true;
for i:=1 to width do
begin
if (x=snakebody[i].x) and (y=snakebody[i].y) then
isset:=false;
end;
if isset then
begin
if (x<=0) or (y<=0) or (x>=80) or (y>=25)then
isset:=false;
end;
checknext:=isset;
end;{ᮧ¤*св Ґ¤г ** Ї®«Ґ}
procedure neweat;
begin
e.x:=random(78)+2;
e.y:=random(23)+2;
while (not checknext(e.x,e.y)) do
begin
e.x:=random(78)+2;
e.y:=random(23)+2;
end;
end;
procedure movesnake (x,y:integer);
var
i:integer;
begin
for i:=1 to width do
begin
snakebody[i]:=snakebody[i+1];
end;
snakebody[width].x:=x;
snakebody[width].y:=y;
if (x=e.x) and (y=e.y) then
begin
width:=width+1;
snakebody[width].x:=x;
snakebody[width].y:=y;
neweat;
end;
end;
{*****main program*****}
begin
textbackground(3);
clrscr;
textcolor(1);
gotoxy(33,10);
write ('*****SNAKE*****');
gotoxy(20,12);
write ('press W to go up');
gotoxy(20,14);
write('press A to go left');
gotoxy(20,16);
write('press D to go right');
gotoxy(20,18);
write('press S to go down');
gotoxy(27,22);
write('*****PRESS ENTER TO START*****');
readln;
clrscr;
gameover:=false;
width:=4;
snakebody[1].x:=1;
snakebody[1].y:=1;
snakebody[2].x:=2;
snakebody[2].y:=1;
snakebody[3].x:=3;
snakebody[3].y:=1;
snakebody[4].x:=4;
snakebody[4].y:=1;
clrscr;
v:=1;
randomize;
neweat;{ᮧ¤*с¬ Ґ¤г}
while (width<maxwidth) do
begin
if (keypressed) then
begin
key:=readkey;
case key of
'w':begin if v=4 then continue; v:=3; end;{up}
's':begin if v=3 then continue; v:=4; end;{down}
'a':begin if v=1 then continue; v:=2; end;{left}
'd':begin if v=2 then continue; v:=1; end;{rigth}
#27:break; {exit}
end;
end;
clrscr;
case v of
1:begin nx:=snakebody[width].x+1;
ny:=snakebody[width].y;end;{rigth}
2:begin nx:=snakebody[width].x-1;
ny:=snakebody[width].y;end;{left}
3:begin nx:=snakebody[width].x;
ny:=snakebody[width].y-1; end;{up}
4:begin nx:=snakebody[width].x;
ny:=snakebody[width].y+1;end;{down}
end;
if (not checknext(nx,ny)) then
begin
gameover:=true;
break;
end;
movesnake(nx,ny);
gotoxy(e.x,e.y);
write('o');
for i:=1 to width-1 do
begin {
gotoxy(snakebody[i].x,snakebody[i].y);
textbackground(2);
textcolor(15);
write('o');
end;
gotoxy (snakebody[width].x,snakebody[i].y);
textcolor(4);
write('o');
gotoxy(80,25);
delay(200)
end;
clrscr;
if (gameover) then
begin
textcolor(4);
gotoxy(30,12);
writeln('*****GAME OVER!*****');
end
else
begin
textcolor(11);
gotoxy(35,12);
writeln('*****YOU WIN!*****') ;
end;
textcolor(15);
gotoxy(25,20);
writeln('*****PRESS ENTER FOR EXIT!*****');
readln;
end.
Не забываем заключать исходный код в соответствующие теги!
Сообщение отредактировано: APAL -