Дополнить игру лабиринт чем-нибудь интересным - Pascal ABC

Формулировка задачи:

Помогите дополнить лабиринт чем-нибудь интересным) в Pascal
uses crt;
 
const
  KEY_LEFT  = 37;
  KEY_RIGHT = 39;
  KEY_UP    = 38;
  KEY_DOWN  = 40;
 
  SPACE = 0;
  WALL  = 1;
  KEY   = 2;
  DOOR  = 3;
  MONEY = 4;
 
  WD = 10;
  HG = 10;
  MAZE: array [1..HG,1..WD] of integer =  
  (
    (1,1,1,1,1,1,1,1,1,1),
    (1,0,1,4,0,0,1,4,1,1),
    (1,0,1,0,1,1,1,0,0,1),
    (1,0,0,0,0,1,1,1,0,1),
    (1,0,1,1,0,4,0,1,0,0),
    (1,0,0,1,1,1,0,1,3,1),
    (1,1,0,1,0,1,4,1,0,1),
    (1,1,0,1,0,1,1,1,0,1),
    (1,2,0,0,0,0,0,0,0,1),
    (1,1,1,1,1,1,1,1,1,1)
  );
  
  ENDX = 10;
  ENDY = 5;
  
  DIST = 3;
 
var
  px,py:integer;
  m: array[1..HG,1..WD] of integer;
  keys: integer;
  moneys: integer;
  k: integer;
  
procedure Print (x,y: integer; s: string);
begin  
  gotoxy(x,y);
  write(s);  
end;
  
procedure Init;
var x,y: integer;
begin
  px := 2;
  py := 2;
  keys   := 0;
  moneys := 0;
  for y:=1 to HG do
    for x:=1 to WD do
      m[y,x] := MAZE[y,x];
end;
 
procedure Done;
begin
  clrscr;
  Print(10,5,'Congratulations!!! You found of ');
  write(moneys);
  writeln(' moneys!');
end;
 
procedure Draw;
const DX = 35; DY = 5;
var x,y: integer;
begin
  clrscr;
  
  //maze
  for y:=1 to HG do
    for x:=1 to WD do begin
      if ((x>=px-DIST)and(x<=px+DIST)and
          (y>=py-DIST)and(y<=py+DIST)) then begin
    
        if m[y,x] = SPACE then Print(DX+x,DY+y,' ');
        if m[y,x] = WALL  then Print(DX+x,DY+y,'#');
        if m[y,x] = KEY   then Print(DX+x,DY+y,'|');
        if m[y,x] = DOOR  then Print(DX+x,DY+y,'+');
        if m[y,x] = MONEY then Print(DX+x,DY+y,'$');
      end else
        Print(DX+x,DY+y,'.');
    end;
//hero

Код к задаче: «Дополнить игру лабиринт чем-нибудь интересным - Pascal ABC»

textual
uses crt;
 
const
  KEY_LEFT  = 37;
  KEY_RIGHT = 39;
  KEY_UP    = 38;
  KEY_DOWN  = 40;
 
  SPACE = 0;
  WALL  = 1;
  KEY   = 2;
  DOOR  = 3;
  MONEY = 4;
 
  WD = 10;
  HG = 10;
  MAZE: array [1..HG,1..WD] of integer =  
  (
    (1,1,1,1,1,1,1,1,1,1),
    (1,0,1,4,0,0,1,4,1,1),
    (1,0,1,0,1,1,1,0,0,1),
    (1,0,0,0,0,1,1,1,0,1),
    (1,0,1,1,0,4,0,1,0,0),
    (1,0,0,1,1,1,0,1,3,1),
    (1,1,0,1,0,1,4,1,0,1),
    (1,1,0,1,0,1,1,1,0,1),
    (1,2,0,0,0,0,0,0,0,1),
    (1,1,1,1,1,1,1,1,1,1)
  );
  
  ENDX = 10;
  ENDY = 5;
  
  DIST = 3;
 
var
  px,py:integer;
  m: array[1..HG,1..WD] of integer;
  keys: integer;
  moneys: integer;
  k: integer;
  
procedure Print (x,y: integer; s: string);
begin  
  gotoxy(x,y);
  write(s);  
end;
  
procedure Init;
var x,y: integer;
begin
  px := 2;
  py := 2;
  keys   := 0;
  moneys := 0;
  for y:=1 to HG do
    for x:=1 to WD do
      m[y,x] := MAZE[y,x];
end;
 
procedure Done;
begin
  clrscr;
  Print(10,5,'Congratulations!!! You found of ');
  write(moneys);
  writeln(' moneys!');
end;
 
procedure Draw;
const DX = 35; DY = 5;
var x,y: integer;
begin
  clrscr;
  
  //maze
  for y:=1 to HG do
    for x:=1 to WD do begin
      if ((x>=px-DIST)and(x<=px+DIST)and
          (y>=py-DIST)and(y<=py+DIST)) then begin
    
        if m[y,x] = SPACE then Print(DX+x,DY+y,' ');
        if m[y,x] = WALL  then Print(DX+x,DY+y,'#');
        if m[y,x] = KEY   then Print(DX+x,DY+y,'|');
        if m[y,x] = DOOR  then Print(DX+x,DY+y,'+');
        if m[y,x] = MONEY then Print(DX+x,DY+y,'$');
      end else
        Print(DX+x,DY+y,'.');
    end;  
    
  //hero
  Print(DX+px, DY+py, '@');
  
  //counts
  Print(DX+1, DY+HG+2, 'Money: ');
  Write(moneys);
  Print(DX+1, DY+HG+4, 'Keys:  ');
  Write(keys);
end;
 
procedure Move(dx,dy: integer);
var nx,ny: integer;
begin
  nx := px+dx;
  ny := py+dy;
  if ((nx>=1)and(nx<=WD)and
      (ny>=1)and(ny<=HG)) then begin
      
      if m[ny,nx] = SPACE then begin
        px := nx;
        py := ny;
      end else if m[ny,nx] = MONEY then begin
        px := nx;
        py := ny;
        m[ny,nx] := SPACE;
        moneys := moneys + 1;
      end else if m[ny,nx] = KEY then begin
        px := nx;
        py := ny;
        m[ny,nx] := SPACE;
        keys := keys + 1;
      end else if ((m[ny,nx] = DOOR)and(keys>0)) then begin
        px := nx;
        py := ny;
        m[ny,nx] := SPACE;
        keys := keys - 1;
      end;
  end;
end;
 
begin
  Init;
  while true do begin
    Draw;
    k := ord(readkey);
    if k = KEY_LEFT  then Move(-1,0);
    if k = KEY_RIGHT then Move(+1,0);
    if k = KEY_UP    then Move(0,-1);
    if k = KEY_DOWN  then Move(0,+1);
    if ((px = ENDX) and (py = ENDY)) then break;
  end;
  Done;
end.

7   голосов, оценка 3.857 из 5


СОХРАНИТЬ ССЫЛКУ