孤独的幻影 孤独的幻影
关注数: 0 粉丝数: 3 发帖数: 34 关注贴吧数: 0
小游戏-贪吃蛇 uses crt;varcj:array[1..22,1..9] of -1..300;cd,js1,js2,x,y,active:integer;js,active2,speed:integer;procedure show;beginclrscr;gotoxy(1,1);write('**********************');gotoxy(1,11);write('**********************');gotoxy(1,2);for js2:=1 to 9 do for js1:=1 to 22 do begin if cj[js1,js2]=0 then write(' '); if cj[js1,js2]<0 then write('o'); if cj[js1,js2]>0 then write(chr(219)); end;gotoxy(x,y+1);write('o');gotoxy(6,12);write(speed,' ',speed*(cd-3));end;procedure bean;varwpx,wpy:integer;beginrepeatwpx:=random(22)+1;wpy:=random(9)+1;until (cj[wpx,wpy]=0) and ((wpx<>x) or (wpy<>y));cj[wpx,wpy]:=-1;end;function canmove:boolean;beginif (x<1) or (x>22) or (y<1) or (y>9) or (cj[x,y]>0) then canmove:=falseelse canmove:=trueend;beginrandomize;textbackground(black);clrscr;window(30,7,51,18);textbackground(white);textcolor(black);clrscr;gotoxy(1,6);write('press enter to start');readln;clrscr;gotoxy(3,5);write('speed(1-30):');repeat readln(speed);until (speed>=1) and (speed<=30);for js2:=1 to 9 do for js1:=1 to 21 do cj[js1,js2]:=0;cd:=3;x:=2;y:=5;cj[2,4]:=3;cj[2,3]:=2;cj[2,2]:=1;active:=2;js:=10;bean;repeat show; delay(700-speed*10); active2:=active; repeat active:=active2; if keypressed then case upcase(readkey) of #0:case readkey of #75:if active<>4 then active:=3; #77:if active<>3 then active:=4; #80:if active<>1 then active:=2; #72:if active<>2 then active:=1; end; #27:exit; end; until not(keypressed); cj[x,y]:=cd+1; case active of 1:y:=y-1; 2:y:=y+1; 3:x:=x-1; 4:x:=x+1; end; if cj[x,y]=-1 then begin cd:=cd+1; bean; end; for js2:=1 to 9 do for js1:=1 to 22 do if cj[js1,js2]>0then cj[js1,js2]:=cj[js1,js2]-1; if (cd=js) and (speed<650) then begin speed:=speed+5; js:=js+10; end;until not(canmove);gotoxy(7,6);write('Game over');readln;end.{本人目前初中,所学不多。。所以可能写的有些不好的地方请见谅。。}
1 下一页