pascal游戏吧 关注:1,980贴子:4,974
  • 17回复贴,共1

额写的贪吃蛇v1.0

只看楼主收藏回复

program example;
{$M 9999,0,0}
uses dos,crt,windows;
const pic:array[1..25] of string=(
' ',
' ',
' ******************** *************** ',
' * ** ** ',
' * ** ** ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * * ',
' * * ** * ',
' * * ** * ',
' * ** ** ',
' * ** ** ** *** ** ',
' ********************* ** *************** ***** ** ',
' ');
type shijian=array[1..4] of word;
zuobiao=record x,y:longint; end;
var ch:char;
point,x,y,i,j,len,head,tail,col,line,point2,speed,score:longint;
f:text;
s:string;
b,a:array[1..100,1..100] of boolean;
she:array[1..1000000,1..2] of longint; //longint =====>>>> byte;^^^^^>><<<<<<<<<<>>>>>>>>>>
t1,t2:shijian;
apple,p_mark:zuobiao;
function turnstr(x:longint):string;
begin
str(x,turnstr);
while length(turnstr)<4 do turnstr:='0'+turnstr;
end; procedure printpic;
var i:longint;
begin
clrscr;
for i:=1 to 25 do writeln(pic[i]);



IP属地:安徽1楼2012-04-22 14:59回复
    writeln('press any key to start...');
    end; procedure printshi(a:shijian);
    begin
    for i:=1 to 4 do write(a[i],' '); writeln;
    end; procedure press;
    var times:longint;
    begin
    while not keypressed do begin inc(times); if times>9999999999 then times:=0; end;
    ch:=readkey;
    end; procedure clrscrn;
    begin
    clrscr; x:=0; y:=1;
    end; procedure writes(ch:char);
    begin
    inc(x);
    gotoxy(x,y);
    write(ch);
    end; function turnint(a:shijian):longint;
    begin
    turnint:=a[4]+a[3]*100+a[2]*100*60+a[1]*100*60*60;
    end;
    function turnshi(x:longint):shijian;
    var a:shijian;
    begin
    a[1]:=x div 100 div 60 div 60; x:=x-a[1]*100*60*60;
    a[2]:=x div 100 div 60; x:=x-a[2]*100*60;
    a[3]:=x div 100; x:=x-a[3]*100;
    a[4]:=x mod 100; exit(a);
    end; function jia(a:shijian; time:longint):shijian;
    begin exit(turnshi(turnint(a)+time)); end; operator >(a,b:shijian)c:boolean;
    begin
    if turnint(a)>turnint(b) then c:=true else c:=false;
    end;
    procedure gettimes(var a:shijian);
    begin gettime(a[1],a[2],a[3],a[4]); end;
    procedure gover;
    var c,d:shijian;
    k,i,j:longint;
    begin
    clrscr;
    for k:=1 to 5 do begin
    gettimes(c);
    while true do begin
    gettimes(d);
    if d>jia(c,50) then begin
    clrscr;
    while true do begin
    gettimes(c);
    if c>jia(d,50) then begin
    gotoxy(50,1); write('Your Score:');
    p_mark.x:=61;
    p_mark.y:=1;
    gotoxy(p_mark.x,p_mark.y); write(turnstr(score)); for i:=1 to col do begin
    for j:=1 to line do begin
    gotoxy(i,j);
    if not b[i,j] then write('*' ) else
    if a[i,j] then write(chr(1));
    end;
    end;
    break;
    end;
    end;
    break;
    end;
    end;
    end;
    while keypressed do press;
    press; clrscr;
    writeln; writeln;
    for i:=1 to 25 do writeln(pic[i]);
    writeln('game over!!!');
    write('Your final score: '); writeln(score);
    writeln('press any key to exit...');
    press;
    halt;
    end; procedure getapple;
    begin
    randomize;
    repeat
    apple.x:=random(col-2)+1;
    apple.y:=random(line-2)+1;
    until b[apple.x,apple.y];
    gotoxy(apple.x,apple.y); write(chr(1));
    a[apple.x,apple.y]:=true;
    end; procedure zhuanwan;
    begin
    while keypressed do begin ch:=readkey;
    case ch of
    'w': point2:=8;
    's': point2:=2;
    'a': point2:=4;
    'd': point2:=6;
    end;
    end;
    case ch of
    'w':if point<>2 then point:=point2;
    's':if point<>8 then point:=point2;
    'a':if point<>6 then point:=point2;
    'd':if point<>4 then point:=point2;
    end;
    end; procedure init;
    begin
    clrscr;
    repeat
    


    IP属地:安徽2楼2012-04-22 14:59
    回复
      writeln('please enter the speed... (1<=speed<=100) 推荐:100');
      readln(s);
      val(s,speed,x);
      if not ((speed>=1) and (speed<=100)) then writeln('Wrong entering!!! Again:');
      until (speed>=1) and (speed<=100);
      speed:=101-speed;
      clrscr; repeat
      writeln('please enter the cols... (10<=cols<=40 推荐:40)');
      readln(s);
      val(s,col,x);
      if not ((col>=10) and (col<=40)) then writeln('Wrong entering!!! Again:');
      until (col>=10) and (col<=40);
      clrscr; repeat
      writeln('please enter the lines... (10<=line<=25 推荐:25)');
      readln(s);
      val(s,line,x);
      if not ((line>=10) and (line<=25)) then writeln('Wrong entering!!! Again:');
      until (line>=10) and (line<=25);
      //speed:=0; col:=40; line:=25;
      end; begin
      assign(f,'d:\b.bat'); rewrite(f);
      writeln(f,'@echo off');
      writeln(f,'mode con cols=70 lines=45');
      close(f);
      {assign(output,'b.bat'); rewrite(output);
      writeln(f,'@echo off');
      writeln(f,'mode con cols=70 lines=45');
      close(output);}
      exec('b.bat',''); assign(f,'d:\a.bat'); rewrite(f);
      writeln(f,'@echo off');
      writeln(f,'chcp 936');
      close(f);
      exec('a.bat',''); WinExec('cmd /c "del /Q d:\a.bat"', SW_NORMAL);
      WinExec('cmd /c "del /Q d:\b.bat"', SW_NORMAL);
      printpic;
      press; ch:='k';
      init;
      clrscr;
      gotoxy(50,1); write('Your Score:');
      p_mark.x:=61;
      p_mark.y:=1;
      score:=0;
      gotoxy(p_mark.x,p_mark.y); write('0000'); //col:=40; line:=25; //40 行 30 列
      gotoxy(1,1);
      for i:=1 to col do write('*');
      gotoxy(1,line);
      for i:=1 to col do write('*');
      for i:=1 to line do
      begin
      gotoxy(1,i); write('*');
      gotoxy(col,i); write('*');
      end; fillchar(b,sizeof(b),1);
      for i:=1 to col do begin b[i,1]:=false; b[i,line]:=false; end;
      for i:=1 to line do begin b[1,i]:=false; b[col,i]:=false; end;
      getapple;
      len:=4;
      she[1,1]:=2; she[1,2]:=2;
      she[2,1]:=3; she[2,2]:=2;
      she[3,1]:=4; she[3,2]:=2;
      she[4,1]:=5; she[4,2]:=2;
      head:=4; tail:=1;
      for i:=tail to head do b[she[i,1],she[i,2]]:=false;
      point:=6;
      for i:=tail to head do begin gotoxy(she[i,1],she[i,2]); write('>') end;
      repeat
      gettime(t1[1],t1[2],t1[3],t1[4]);
      while true do
      begin
      gettime(t2[1],t2[2],t2[3],t2[4]);
      if t2>jia(t1,speed) then begin inc(head);
      zhuanwan;
      if point=6 then begin she[head,1]:=she[head-1,1]+1; she[head,2]:=she[head-1,2]; end;
      if point=2 then begin she[head,1]:=she[head-1,1]; she[head,2]:=she[head-1,2]+1; end;
      if point=8 then begin she[head,1]:=she[head-1,1]; she[head,2]:=she[head-1,2]-1; end;
      if point=4 then begin she[head,1]:=she[head-1,1]-1; she[head,2]:=she[head-1,2]; end;
      if not b[she[head,1],she[head,2]] then gover;
      gotoxy(she[head,1],she[head,2]);
      //write('*');
      if point=2 then write(chr(31)) else if point=8 then write(chr(30)) else if point=4 then write('<') else write('>');
      b[she[head,1],she[head,2]]:=false; if not a[she[head,1],she[head,2]] then begin
      gotoxy(she[tail,1],she[tail,2]);
      write(' ');
      b[she[tail,1],she[tail,2]]:=true;
      inc(tail);
      end
      else begin
      inc(score);
      gotoxy(p_mark.x,p_mark.y);
      write(turnstr(score));
      a[she[head,1],she[head,2]]:=false;
      getapple;
      end;
      break;
      end;
      end;
      until false;
      end.


      IP属地:安徽3楼2012-04-22 14:59
      回复
        还不错。。。


        IP属地:河北5楼2012-05-02 14:25
        回复
          好啊啊!


          IP属地:中国台湾6楼2012-06-03 17:59
          回复
            IP属地:安徽7楼2012-08-27 14:19
            回复
              怎么拐弯啊?


              IP属地:日本9楼2012-12-29 13:48
              收起回复
                。。。


                IP属地:河北10楼2013-01-05 14:27
                回复


                  IP属地:中国台湾来自Android客户端11楼2013-06-15 19:37
                  回复
                    其实
                    我也写了一个
                    弱弱的问一句
                    求交流…………
                    exe文件:http://www.kuaipan.cn/file/id_54337027126077223.htm?source=1
                    源代码:http://www.kuaipan.cn/file/id_54337027126077200.htm?source=1


                    IP属地:江苏12楼2013-11-14 00:12
                    收起回复
                      @@%¥##¥##@@@@……*¥%¥%¥#@¥@%#……¥&…………&……%#@#@@@


                      13楼2014-04-20 17:45
                      回复