uses crt;
{
управление w
a d
s
}
const
Wm = 30;
Hm = 20;
Maxlen = 100;
snch = '*';
edach = '%';
bigedach = 'W';
stena = '#';
maxtlifeb = 40;
var
Matrix:array [1..Hm]of string= (
'#### #####' ,
'# #' ,
'# #' ,
'# #' ,
' ',
' ' ,
' ' ,
' ' ,
' ' ,
' ######### ' ,
' ' ,
' ######### ' ,
' ' ,
' ' ,
' ' ,
' ' ,
'# #' ,
'# #' ,
'# #' ,
'#### ####'
);
dir:integer=0;
count:integer = 4;
tick:integer = 0;
lifeda:boolean = false;
tlifedab:integer = 10;
lifedab:boolean = false;
GameOver:boolean;
score:integer = 0;
randbe:integer;
snake:array [0..Maxlen] of record x,y:integer;end;
procedure onkeyboard();
begin
if (keypressed)then
begin
case readkey of
'a': if (dir <> 2)then dir := 0;
'w': if (dir <> 3)then dir := 1;
'd': if(dir <> 0)then dir := 2;
's': if (dir <> 1)then dir := 3;
end;
end;
end;
procedure snakep();
var i:integer;
begin
for i := count downto 1 do snake[i] := snake[i - 1];
case (dir) of
0:begin
if (snake[0].x = 1)then snake[0].x := Wm;
snake[0].x:=snake[0].x-1;
end;
1:begin
if (snake[0].y = 1)then snake[0].y := Hm;
snake[0].y:=snake[0].y-1;
end;
2: begin
if (snake[0].x = Wm)then snake[0].x := 1;
snake[0].x:=snake[0].x+1;
end;
3:begin
if (snake[0].y = Hm)then snake[0].y := 1;
snake[0].y:=snake[0].y+1;
end;
end;
if (Matrix[snake[0].y][snake[0].x] = stena)then
begin
GameOver := true;
end;
if (Matrix[snake[0].y][snake[0].x] = snch)then
begin
GameOver := true;
end;
if (Matrix[snake[0].y][snake[0].x] = edach)then
begin
lifeda := false;
inc(count);
inc(score);
end;
if (Matrix[snake[0].y][snake[0].x] = bigedach)then
begin
tlifedab := 0;
lifedab := false;
inc(count);
inc(score, 4);
end;
Matrix[snake[0].y][snake[0].x]:=snch;
Matrix[snake[count].y][snake[count].x] := ' ';
end;
procedure drawmatrix();
var x,y:integer;
begin
for y := 1 to Hm do
begin
for x := 1 to Wm do
begin
if (Matrix[y][x] <> '$')then
begin
gotoxy(x,y);
write( Matrix[y][x]);
if(Matrix[y][x]=' ')then Matrix[y][x] := '$';
end;
end;
end;
end;
procedure randcord(var x:integer;var y:integer);
begin
repeat
x := random(wm div 2);
y := random(hm div 2);
until not ((Matrix[y][x] = snch) or (Matrix[y][x] = stena));
end;
var x,x1, y,y1:integer;
procedure edap();
begin
if (not lifeda) then
begin
randcord(x,y);
lifeda := true;
Matrix[y][x] := edach;
end;
if (1<=tlifedab) then begin
dec(tlifedab);
if(0 = tlifedab)then begin
Matrix[y1][x1] := ' ';
tlifedab := 0;
lifedab := false;
end;
end;
if (( tlifedab>0)
and((tick mod randbe + 1) = randbe))then
begin
randbe := random(10)+ random(30)+100 + maxtlifeb;
tlifedab := maxtlifeb;
lifedab := true;
randcord(x1, y1);
Matrix[y1][x1] := bigedach;
end;
gotoxy(x,y+1);
end;
begin
randbe:= random(20) + random(20)+10+maxtlifeb;
GameOver := false;
snake[0].x := (Wm) div 2;
snake[0].y := (Hm) div 2+5;
writeln( score);
snakep();
drawmatrix();
readkey;
while(not GameOver) do
begin
onkeyboard();
snakep();
edap();
drawmatrix();
inc(tick);
delay(150);
end;
clrscr;
writeln( 'GAMEOVER!!!');
writeln( 'score: ',score);
end.