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

贪吃蛇graph版

只看楼主收藏回复

开始界面鼠标操作


贪吃蛇.zip
大小:49.68KB下载:44次转存:0次
文件已失效
IP属地:浙江来自贴吧神器1楼2013-03-03 17:59回复
    新版:
    uses graph,wincrt,winmouse;
    var gd,gm:smallint;i,j,tx,ty,wx,wy:longint;a:array[1..14,1..20]of record d,x,y:longint;end;f:char;
    procedure print;
    var x1,x2,y1,y2:longint;
    begin
    setcolor(blue);
    x1:=1;y1:=1;x2:=getmaxy;y2:=getmaxx;
    repeat
    rectangle(y1,x1,y2,x2);
    inc(x1);inc(y1);dec(x2);dec(y2);
    rectangle(y1,x1,y2,x2);
    inc(x1);inc(y1);dec(x2);dec(y2);
    delay(1);
    until (x1>x2)or(y1>y2);
    setcolor(yellow);
    for i:=1 to 14 do
    for j:=1 to 20 do
    case a[i,j].d of
    -1:
    begin
    setfillstyle(1,yellow);
    bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);
    end;
    1,2,3:begin setfillstyle(1,red);bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);end;
    -10:begin settextstyle(6,horizdir,6);outtextxy((j-1)*50+1,(i-1)*50+1,#1);end;
    end;
    end;
    procedure run(ch:char);
    var x,y:longint;
    begin
    f:=ch;
    case ch of
    'u':begin a[tx,ty].d:=2;a[tx,ty].x:=tx-1;a[tx,ty].y:=ty;tx:=tx-1;end;
    'd':begin a[tx,ty].d:=2;a[tx,ty].x:=tx+1;a[tx,ty].y:=ty;tx:=tx+1;end;
    'r':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty+1;ty:=ty+1;end;
    'l':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty-1;ty:=ty-1;end;
    end;
    if a[tx,ty].d=-10 then begin a[tx,ty].d:=1;setfillstyle(1,red);bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);end
    else
    begin
    a[tx,ty].d:=1;a[wx,wy].d:=0;
    x:=a[wx,wy].x;y:=a[wx,wy].y;
    setfillstyle(1,blue);
    bar((wy-1)*50+1,(wx-1)*50+1,wy*50,wx*50);
    wx:=x;wy:=y;
    setfillstyle(1,red);
    bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);
    end;
    end;
    procedure failure;
    begin
    setcolor(yellow);
    settextstyle(10,horizdir,10);
    outtextxy(100,100,'YOU FAIL');
    readkey;halt;
    end;
    procedure play;
    var i,x,y:longint;ch:char;
    begin
    print;
    repeat
    ch:=' ';
    delay(1000);
    if keypressed then begin ch:=readkey;if ch=#0 then ch:=readkey;end;
    if(tx=2)and(ch in ['w',#72])then failure;
    if(tx=13)and(ch in ['s',#80])then failure;
    if(ty=2)and(ch in [#75,'a'])then failure;
    if(ty=19)and(ch in [#77,'d'])then failure;
    if ch=' ' then
    case f of
    'u':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
    'd':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
    'l':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
    'r':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
    end;
    case ch of
    #72,'w':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
    #80,'s':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
    #75,'a':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
    #77,'d':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
    end;
    x:=random(14)+1;y:=random(20)+1;
    if a[x,y].d=0 then begin a[x,y].d:=-10;settextstyle(6,horizdir,6);outtextxy((y-1)*50+1,(x-1)*50+1,#1);end;
    I


    IP属地:浙江来自贴吧神器2楼2013-03-10 16:21
    回复
      until false;
      end;
      procedure help;
      var x1,y1,x2,y2,but:longint;
      begin
      setcolor(yellow);
      x1:=1;y1:=1;x2:=getmaxy;y2:=getmaxx;
      repeat
      rectangle(y1,x1,y2,x2);
      inc(x1);inc(y1);dec(x2);dec(y2);
      rectangle(y1,x1,y2,x2);
      inc(x1);inc(y1);dec(x2);dec(y2);
      delay(1);
      until (x1>x2)or(y1>y2);
      setcolor(blue);settextstyle(3,horizdir,2);
      outtextxy(230,100,'Use the up and down about key control movement.');
      outtextxy(200,250,'strike the wall or the snake body is the end of the game.');
      repeat
      getmousestate(y1,x1,but);
      until(keypressed)or(but=1);
      end;
      procedure picture(s:string);
      var i,j:longint;ch:char;
      begin
      assign(input,s);reset(input);
      i:=1;j:=1;
      while not eof do
      begin
      while not eoln do
      begin
      read(ch);
      case ch of
      'r':putpixel(i+300,j+50,red);
      'b':putpixel(i+300,j+50,blue);
      'y':putpixel(i+300,j+50,yellow);
      'g':putpixel(i+300,j+50,green);
      end;
      inc(i);
      end;
      readln;
      i:=1;
      inc(j);
      end;
      close(input);
      end;
      procedure ha;
      var x1,y1,x2,y2,but:longint;
      begin
      setcolor(brown);
      x1:=1;y1:=1;x2:=getmaxy;y2:=getmaxx;
      repeat
      rectangle(y1,x1,y2,x2);
      inc(x1);inc(y1);dec(x2);dec(y2);
      rectangle(y1,x1,y2,x2);
      inc(x1);inc(y1);dec(x2);dec(y2);
      delay(1);
      until (x1>x2)or(y1>y2);
      picture('2');
      i:=0;
      repeat
      getmousestate(y1,x1,but);
      delay(1);
      inc(i);
      until(keypressed)or(but=1)or(i=100);
      end;
      procedure main;
      var x,y,but,i:longint;
      begin
      setbkcolor(green);
      cleardevice;
      setcolor(red);
      picture('1');
      settextstyle(7,horizdir,6);
      outtextxy(450,300,'PLAY');
      outtextxy(450,370,'HELP');
      outtextxy(450,440,'EXIT');
      setfillstyle(1,green);
      repeat
      getmousestate(y,x,but);
      if (y>=450)and(y<=650)then
      begin
      if (x>=300)and(x<=350)and(i<>1) then
      begin bar(400,300,449,500);bar(650,300,700,500);outtextxy(400,300,#16);outtextxy(650,300,#17);write(#7);i:=1;end else
      if (x>=370)and(x<=420)and(i<>2)then
      begin bar(400,300,449,500);bar(650,300,700,500);outtextxy(400,370,#16);outtextxy(650,370,#17);write(#7);i:=2;end else
      if (x>=440)and(x<=490)and(i<>3) then
      begin bar(400,300,449,500);bar(650,300,700,500);outtextxy(400,440,#16);outtextxy(650,440,#17);write(#7);i:=3;end else
      if ((x<300)or((x>350)and(x<370))or((x>420)and(x<440))or(x>490))and(i<>0) then
      begin i:=0;bar(400,300,449,500);bar(650,300,700,500);end;
      end
      else
      begin i:=0;bar(400,300,449,500);bar(650,300,700,500);end;
      until (but=1)and(i<>0);
      if i=1 then play;
      if i=2 then begin help;main;end;
      if i=3 then ha;
      end;
      procedure init;
      begin
      gd:=detect;
      initgraph(gd,gm,'');
      for i:=2 to 13 do
      for j:=2 to 19 do
      a[i,j].d:=0;
      for i:=1 to 20 do
      begin
      a[1,i].d:=-1;a[14,i].d:=-1;
      end;
      for i:=2 to 13 do
      begin
      a[i,1].d:=-1;a[i,20].d:=-1;
      end;
      randomize;
      for i:=1 to random(10) do
      a[random(12)+2,random(18)+2].d:=-10;
      a[2,2].d:=3;a[2,3].d:=2;a[2,4].d:=1;
      a[2,2].x:=2;a[2,2].y:=3;a[2,3].x:=2;a[2,3].y:=4;
      tx:=2;ty:=4;wx:=2;wy:=2;f:='r';
      end;
      begin
      init;
      main;
      end.


      IP属地:浙江来自贴吧神器3楼2013-03-10 16:21
      回复
        啊,其他文件放不下!
        还是用图片吧……


        IP属地:浙江来自贴吧神器4楼2013-03-10 16:26
        回复