Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Snake;
- Uses crt;
- Const max = 100;
- dificuldade = 200;
- Type tabuleiro = array [ 1 .. max , 1 .. max] of real;
- Procedure inicializatab (var a : tabuleiro; var x, y : integer);
- Var i, j : integer;
- Begin
- (* x := ParamInt(0);
- y := ParamInt(1); *)
- read (x,y);
- for i := 1 to x do
- begin
- a [i] [1] := 0.5;
- a [i] [y] := 0.5;
- end;
- for i := 1 to y do
- begin
- a [1] [i] := 0.5;
- a [x] [i] := 0.5;
- end;
- for i := 2 to (x - 1) do
- begin
- for j := 2 to (y - 1) do
- a [i] [j] := 0;
- end;
- a [(x div 2)] [(y div 2)] := 1;
- End; (* End do procedure inicializatab. *)
- Procedure inicializavar (var hx, hy, tx, ty, k, l, ts : integer; x, y : integer; var d : char);
- Begin
- hx := x div 2;
- hy := y div 2;
- tx := hx;
- ty := hy;
- d := 'd';
- k := 1;
- l := 1;
- ts := 5;
- End; (* End do procedure inicializavar. *)
- Procedure atualizatamanho (var a : tabuleiro; tx, ty : integer);
- Var i, j : integer;
- Begin
- for i := 1 to tx do
- for j := 1 to ty do
- if a [i] [j] > 0 then
- a[i] [j] := a [i] [j] + 1;
- End; (* End do procedure atualizatamanho. *)
- Procedure imprime (var a : tabuleiro; x, y, ts : integer);
- Var i, j : integer;
- Begin
- for i := 1 to y do
- for j := 1 to x do
- if (a [j] [i] = 0) or (a [j] [i] > ts) then
- write (' ')
- else if (a [j] [i] = 0.5) then
- write ('#')
- else
- write ('>');
- writeln (' ');
- End; (* End do procedure imprime. *)
- Procedure movedireita (var a : tabuleiro; var cx, cy, j : integer);
- Begin
- if (a [cx + 1] [cy] = 0) then
- begin
- a [cx] [cy] := 1;
- cx := cx + 1;
- end
- else
- j := 0;
- End;
- Procedure moveesquerda (var a : tabuleiro; var cx, cy, j : integer);
- Begin
- if (a [cx - 1] [cy] = 0) then
- begin
- a [cx] [cy] := 1;
- cx := cx - 1;
- end
- else
- j := 0;
- End;
- Procedure movecima (var a : tabuleiro; var cx, cy, j : integer);
- Begin
- if (a [cx] [cy - 1] = 0) then
- begin
- a [cx] [cy] := 1;
- cy := cy - 1;
- end
- else
- j := 0;
- End;
- Procedure movebaixo (var a : tabuleiro; var cx, cy, j : integer);
- Begin
- if (a [cx] [cy + 1] = 0) then
- begin
- a [cx] [cy] := 1;
- cy := cy + 1;
- end
- else
- j := 0;
- End;
- Procedure move_(var a : tabuleiro; var i, j, x, cx, y, cy, tx, ty : integer; var d : char);
- Begin
- if (d = 'd') then
- movedireita (a, cx, cy, j)
- else if (d = 'a') then
- moveesquerda (a, cx, cy, j)
- else if (d = 'w') then
- movecima (a, cx, cy, j)
- else if (d = 's') then
- movebaixo (a, cx, cy, j);
- a [cx] [cy] := 1;
- atualizatamanho (a, x, y);
- End; (* End do procedure move. *)
- VAR tab : tabuleiro;
- contador, vida, cabecax, cabecay, caudax, cauday, tamtabx, tamtaby, tamsnake : integer;
- direcao, d: char;
- BEGIN
- inicializatab (tab, tamtabx, tamtaby);
- inicializavar (cabecax, cabecay, caudax, cauday, vida, contador, tamsnake, tamtabx, tamtaby, direcao);
- repeat
- repeat
- clrscr;
- imprime (tab, tamtabx, tamtaby, tamsnake);
- move_(tab, contador, vida, tamtabx, cabecax, tamtaby, cabecay, caudax, cauday, direcao);
- delay (dificuldade);
- until (vida = 0) or (keypressed = true);
- d := readkey;
- until (vida = 0);
- writeln ('Perdeu, playboy!')
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement