i信息学奥赛

加入QQ群:1025629106,或关注微信公众号:i信息学奥赛,获取更多学习资源。

导航

大逃亡

Posted on 2016-12-12 14:05  shnoip  阅读(281)  评论(0编辑  收藏  举报

感谢格致杭业晟同学提供
uses crt;
var
  i,j:byte;
  k:integer;
  c:char;
  t:array[1..25,1..80] of boolean;
procedure w;
begin
  i:=i-1;
  if i=0 then i:=25;
end;
procedure a;
begin
  j:=j-1;
  if j=0 then j:=80;
end;
procedure s;
begin
  i:=i+1;
  if i=26 then i:=1;
end;
procedure d;
begin
  j:=j+1;
  if j=81 then j:=1;
end;
begin
  cursoroff;
  gotoxy(33,10);
  writeln('  大 逃 亡  ');
  writeln;
  writeln('w:向上 s:向下':46);
  writeln('a:向左 d:向右':46);
  writeln('*:你  #:炸弹':46);
  writeln('--:出口':43);
  writeln('按回车键开始':45);
  readln;
  clrscr;
  randomize;
  textcolor(red);
  for i:=1 to 25 do
    for j:=1 to 80 do
      t[i,j]:=false;
  for k:=1 to 500 do begin
    i:=random(25)+1;
    j:=random(80)+1;
    t[i,j]:=true;
    gotoxy(j,i);
    write('#');
  end;
  textcolor(yellow);
  gotoxy(39,24);
  write('--');
  gotoxy(39,25);
  write('--');
  textcolor(white);
  gotoxy(40,13);
  write('*');
  t[13,40]:=false;
  j:=40;
  i:=13;
  while true do begin
    if keypressed then begin
      c:=readkey;
      case c of
        'w':w;
        'a':a;
        's':s;
        'd':d;
      end;
      if ((j=39) and (i=24)) or ((j=39) and (i=25)) or
         ((j=40) and (i=24)) or ((j=40) and (i=25)) then begin
        clrscr;
        gotoxy(37,13);
        write('You win!');
        delay(1500);
        break;
      end;
      if t[i,j] then begin
        clrscr;
        gotoxy(37,13);
        write('You lose!');
        delay(1500);
        break;
      end;
      gotoxy(j,i);
      write('*');
      t[i,j]:=true;
    end;
  end;
end.