回 帖 发 新 帖 刷新版面

主题:[原创]各位大虾,帮我修改一下

program L_snack_011;
        uses crt;
        type
            d=array [1..20,1..50] of char;
            e=array [1..250] of integer;
        var
           a:d;
           b,c:e;
           mark,l1,l2,l3,l4,l5,r1,r2,i,j,f,k,l,m,n:integer;
           cc,ch:char;
        procedure print(a:d;
                        i,j:integer);
                  begin
                       clrscr;
                       for i:=1 to 20 do
                           begin
                                for j:=1 to 50 do
                                    write(a[i,j]);
                                writeln;
                           end;
                  end;
         procedure print1(a:d;
                        i,j:integer);
                  begin
                       for i:=2 to 19 do
                           begin
                                gotoxy(2,i);
                                for j:=2 to 43 do
                                   write(a[i,j]);
                           end;
                  end;
         begin
               for i:=2 to 19 do
                   begin
                        a[i,1]:='I';
                        a[i,44]:='I';
                        a[i,50]:='I';
                   end;
               for j:=1 to 50 do
                   begin
                        a[1,j]:='=';
                        a[20,j]:='=';
                   end;
               for i:=45 to 49 do
                   a[10,i]:='=';
               l:=0;
               f:=5;
               for j:=6 downto 2 do
                   begin
                        l:=l+1;
                        b[l]:=2;
                        c[l]:=j;
                        a[b[l],c[l]]:='*';
                   end;
               randomize;
               repeat
                     r1:=random(41)+2;
                     r2:=random(17)+2;
                     for i:=1 to f do
                         if (r1=c[i]) and (r2=b[i]) then
                            begin
                                 cc:='c';
                                 break;
                            end
                                                    else cc:='s';
               until cc='s';
               a[r2,r1]:='$';
               print(a,i,j);
               a[b[1],c[1]]:=' ';
               repeat
               until keypressed;
               while (a[b[1],c[1]]<>'=') and (a[b[1],c[1]]<>'I') and (a[b[1],c[1]]<>'*')
do
                     begin
                          for i:=1 to f do
                              a[b[i],c[i]]:='*';
                          m:=b[1]-b[2];
                          n:=c[1]-c[2];
                          print1(a,i,j);
                          mark:=(f-5)*100;
                          gotoxy(45,7);
                          write('分数':4);
                          gotoxy(45,9);
                          write(mark:4);
                          a[b[f],c[f]]:=' ';
                          b[f+1]:=b[f];
                          c[f+1]:=c[f];
                          for i:=f downto 2 do
                              begin
                                   b[i]:=b[i-1];
                                   c[i]:=c[i-1];
                              end;
                          delay(200);
                          if keypressed then
                             ch:=readkey;
                          case ord(ch) of
                              $48:b[1]:=b[1]-1;
                              $50:b[1]:=b[1]+1;
                              $4b:c[1]:=c[1]-1;
                              $4d:c[1]:=c[1]+1;
                          else
                              begin
                                   if m<>0 then if m>0 then b[1]:=b[1]+1
                                                       else b[1]:=b[1]-1
                                           else if n>0 then c[1]:=c[1]+1
                                                       else c[1]:=c[1]-1;
                              end;
                          end;
                          if (b[1]=b[3]) and (c[1]=c[3]) then
                            begin
                                 b[1]:=b[2];
                                 c[1]:=c[2];
                                 if m<>0 then if m>0 then b[1]:=b[1]+1
                                                     else b[1]:=b[1]-1
                                         else if n>0 then c[1]:=c[1]+1
                                                     else c[1]:=c[1]-1;
                            end;
                          if a[b[1],c[1]]='$' then
                            begin
                                 Sound(220);        { Beep }
                                 Delay(200);        { For 200 ms }
                                 NoSound;           { Relief! }
                                 f:=f+1;
                                 repeat
                                 r1:=random(41)+2;
                                 r2:=random(17)+2;
                                 for i:=1 to f do
                                 if (r1=c[i]) and (r2=b[i]) then
                                    begin
                                         cc:='c';
                                         break;
                                    end
                                                            else cc:='s';
                                 until cc='s';
                                 a[r2,r1]:='$';
                            end;
                    end;
                    for i:=1 to 3 do
                        begin
                             Sound(440);        { Beep }
                             Delay(300);        { For 200 ms }
                             NoSound;           { Relief! }
                             Sound(190);        { Beep }
                             Delay(300);        { For 200 ms }
                             NoSound;           { Relief! }
                        end;
        end.






请帮我增加以下几点:
1.有生命值
2.可随意设置宽度和大小
3.可随意设置蛇的长度

回复列表 (共2个回复)

沙发

本人好久没有编过游戏了

板凳

[quote]本人好久没有编过游戏了[/quote]
Me too!
很可惜,帮不了LZ的忙了………………
不过我认为只需用到第三点:“可随意设置蛇的长度”
我以前编写贪吃蛇时开一个足够大的一维数组 of 坐标,记录蛇的身体的第N部分的纵横坐标,移动时将蛇头向前移动一格,其余的均向前(赋为上一格曾经的位置),然后输出到屏幕。

我来回复

您尚未登录,请登录后再回复。点此登录或注册