i信息学奥赛

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

导航

顽皮的小人

Posted on 2016-12-10 15:54  shnoip  阅读(339)  评论(0编辑  收藏  举报

感谢上外静中任淳同学提供

uses crt;
var
  x,y:byte;
  c:char;

procedure move;
begin
  clrscr;
  gotoxy(x,y-1);
  write('*');
  gotoxy(x-1,y);
  write('/|\');
  gotoxy(x,y+1);
  write('^');
end;

procedure still;
begin
  clrscr;
  gotoxy(x,y-1);
  write('*');
  gotoxy(x,y);
  write('|');
  gotoxy(x,y+1);
  write('^');
end;

procedure a;
begin
  x:=x-1;
  if x=1 then x:=79;
  move;
  delay(100);
  still;
end;

procedure d;
begin
  x:=x+1;
  if x=80 then x:=2;
  move;
  delay(100);
  still;
end;

procedure w;
begin
  y:=y-1;
  if y=1 then y:=24;
  move;
  delay(100);
  still;
end;

procedure s;
begin
  y:=y+1;
  if y=25 then y:=2;
  move;
  delay(100);
  still;
end;

begin
  x:=2;
  y:=2;
  still;
  while true do begin
    if keypressed then begin
      c:=readkey;
      if c='a' then a;
      if c='s' then s;
      if c='d' then d;
      if c='w' then w;
    end;
  end;
end.