xtljyar xtljyar
关注数: 0 粉丝数: 16 发帖数: 758 关注贴吧数: 5
Greedy Snake Bug {Greedy Snake Source}program GReedySNAKE;uses Crt;const up=0; right=1; down=2; left=3; usual=0; bonus=1; shorten=2;type point=record x,y:integer;end;type tfood=record fpoint:point; ftype:byte; case byte of usual:(); bonus: (btime:word; bscore:byte); shorten: (stime:word; slength:byte);end;var cur,bin:point; food:tfood; track:array[1..200]of point; ch:char; dir:byte; hit:boolean; int,length,score:integer;function pzero(p:point):boolean;var bool:boolean;beginif (p.x=0) and (p.y=0) thenbool:=trueelsebool:=false;pzero:=bool;end;procedure pwrite(p:point;ch:char);beginif not pzero(p) thenbegin gotoxy(p.x,p.y); write(ch);end;end;function psame(p,p2:point):boolean;var bool:boolean;begin if (p.x=p2.x) and (p.y=p2.y) then bool:=trueelsebool:=false;psame:=bool;end;procedure pset(var p:point;x2,y2:integer);beginp.x:=x2;p.y:=y2;end;procedure newfood(var sfood:tfood);var int2:integer; okay:boolean;beginwith sfood dobegin pwrite(fpoint,' '); ftype:=random(9); if (ftype=3) or (ftype=4) then ftype:=1; if ftype=5 then ftype:=2; if ftype>5 then ftype:=0; case ftype of usual:; bonus: begin btime:=(random(3)+4)*20; {20=1000/50} bscore:=8-(btime div 20); end; shorten: begin if 3>length then ftype:=usual else begin stime:=(random(3)+4)*20; slength:=random(2)+1; end; end; end; repeat okay:=true; pset(fpoint,random(78)+2,random(46)+2); for int:=1 to length do okay:=okay and (not psame(fpoint,track[int])); okay:=okay and (not psame(fpoint,cur)) and (not psame(fpoint,bin)); until okay; case ftype of usual: begin textcolor(lightmagenta); pwrite(fpoint,#3); textcolor(yellow); end; bonus: begin textbackground(red); pwrite(fpoint,'B'); textbackground(black); end; shorten: begin textbackground(green); pwrite(fpoint,'S'); textbackground(black); end; end;end;end;procedure newtrack;var int:integer;beginpwrite(bin,' ');for int:=1 to length dopwrite(track[int],#219);textcolor(lightred);pwrite(cur,#2);textcolor(yellow);gotoxy(cur.x,cur.y);end;beginrandomize;checkbreak:=false;textbackground(black);textcolor(yellow);clrscr;writeln('Greedy snake');writeln('Use the ',#27#24#25#26,' keys to control the snake.');writeln('Pressing one of those keys continually can make the snake go faster.');textcolor(lightmagenta);write(#3);textcolor(yellow);writeln(' Ordinary food, score+10 if eaten.');textbackground(red);write('B');textbackground(black);writeln(' Bonus food, score+40 or 60 or 80 if eaten. Be quick and eat!');writeln('If eaten, the length of the snake will enormously increase.');writeln('So try to eat this food:');textbackground(green);write('S');textbackground(black);writeln(' The food to shorten the length of the snake. Also be quick!');
首页 1 2 下一页