Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted by dim' ( 14 years ago )
Uses crt;
Const snake='*'; eat='';
MaxLen=200;
InitLen=1;
Type posit = record
x : Integer;
y : Integer;
end;
Var A : Array[1..MaxLen] of posit;
col : Integer;
Crazy : Boolean;
N, fx, fy : Integer;
score : Integer;
time : Integer;
Procedure NewFood;
begin
Score:=Score+10;
If Time > 1 then Time:=Time-1;
fx:=Random(78)+2;
fy:=Random(48)+2;
GotoXY(fx, fy); TextColor(14); Write(eat);
If N<MaxLen then N:=N+1;
end;
Procedure debug(x,y : Integer);
begin
GotoXY(1,1); TextColor(15);
Write('snake : ', x:4, y:4,' food : ', fx:4, fy:4,' score : ',score:4,' speed :', (101-time) : 4, '%');
end;
Procedure draw(x,y:Integer; col : Integer);
var i : Integer;
begin
GotoXY(A[1].x,A[1].y); TextColor(0); Write(snake);
For i := 1 to N-1 do begin A[i].x:=A[i+1].x; A[i].y:=A[i+1].y; end;
A[N].x:=x; A[N].y:=y;
If Crazy then TextColor(Random(15)+1)
else TextColor(col);
GotoXY(x,y); Write(snake); Delay(time);
end;
Procedure goo;
var Key, cur : char;
x, y : Integer;
begin
GotoXY(1,50);
Write('"1..9,0" - colour change, "`" - crazy colour mod, "-" and "=" snake long');
CursorOff;
Randomize;
NewFood;
time:=50;
Score:=0;
Crazy := True;
N:=InitLen;
col:=15;
x:=21;
y:=21;
Repeat
If KeyPressed then
begin
Key := Readkey;
If ord(Key) = 0 then Cur := ReadKey
else Case Key of
'1' : begin col:=1; Crazy:=False; end;
'2' : begin col:=2; Crazy:=False; end;
'3' : begin col:=3; Crazy:=False; end;
'4' : begin col:=4; Crazy:=False; end;
'5' : begin col:=5; Crazy:=False; end;
'6' : begin col:=6; Crazy:=False; end;
'7' : begin col:=7; Crazy:=False; end;
'8' : begin col:=8; Crazy:=False; end;
'9' : begin col:=9; Crazy:=False; end;
'0' : begin col:=10; Crazy:=False; end;
'-' : If N > 2 then N:=N-1;
'=' : If N < MaxLen-1 then N:=N+1;
'`' : Crazy:=True;
end;
end;
Case ord(Cur) of
72 : begin y:=y-1; If y=1 then y:=49; end;
75 : begin x:=x-1; If x=1 then x:=79; end;
77 : begin x:=x+1; If x=80 then x:=2; end;
80 : begin y:=y+1; If y=50 then y:=2; end;
end;
Debug(x,y);
If (fx=x)and(fy=y) then NewFood;
draw(x,y,col);
Until Key = #27;
end;
Begin
Clrscr;
goo;
CursorOn;
End.
Revise this Paste