Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.11 KB | None | 0 0
  1. Program Snake;
  2.  
  3. Uses crt;
  4.  
  5. Const max = 100;
  6.     dificuldade = 200;
  7.  
  8. Type tabuleiro = array [ 1 .. max , 1 .. max] of real;
  9.  
  10. Procedure inicializatab (var a : tabuleiro; var x, y : integer);
  11. Var i, j : integer;
  12. Begin
  13. (*  x := ParamInt(0);
  14.     y := ParamInt(1); *)
  15.     read (x,y);
  16.     for i := 1 to x do
  17.     begin
  18.         a [i] [1] := 0.5;
  19.         a [i] [y] := 0.5;
  20.     end;
  21.     for i := 1 to y do
  22.     begin
  23.         a [1] [i] := 0.5;
  24.         a [x] [i] := 0.5;
  25.     end;
  26.     for i := 2  to (x - 1) do
  27.     begin
  28.         for j := 2 to (y - 1) do
  29.             a [i] [j] := 0;
  30.     end;
  31.     a [(x div 2)] [(y div 2)] := 1;
  32. End; (* End do procedure inicializatab. *)
  33.  
  34. Procedure inicializavar (var hx, hy, tx, ty, k, l, ts : integer; x, y : integer; var d : char);
  35. Begin
  36.     hx := x div 2;
  37.     hy := y div 2;
  38.     tx := hx;
  39.     ty := hy;
  40.     d := 'd';
  41.     k := 1;
  42.     l := 1;
  43.     ts := 5;
  44. End; (* End do procedure inicializavar. *)
  45.  
  46. Procedure atualizatamanho (var a : tabuleiro; tx, ty : integer);
  47. Var i, j : integer;
  48. Begin
  49.     for i := 1 to tx do
  50.         for j := 1 to ty do
  51.         if a [i] [j] > 0 then
  52.             a[i] [j] := a [i] [j] + 1;
  53.  
  54. End; (* End do procedure atualizatamanho. *)
  55.  
  56. Procedure imprime (var a : tabuleiro; x, y, ts : integer);
  57. Var i, j : integer;
  58. Begin
  59.     for i := 1 to y do
  60.         for j := 1 to x do
  61.         if (a [j] [i] = 0) or (a [j] [i] > ts) then
  62.             write (' ')
  63.         else if (a [j] [i] = 0.5) then
  64.             write ('#')
  65.         else
  66.             write ('>');
  67.     writeln (' ');
  68.  
  69. End; (* End do procedure imprime. *)
  70.  
  71. Procedure movedireita (var a : tabuleiro; var cx, cy, j : integer);
  72. Begin
  73.     if (a [cx + 1] [cy] = 0) then
  74.     begin
  75.         a [cx] [cy] := 1;
  76.         cx := cx + 1;
  77.     end
  78.     else
  79.         j := 0;
  80. End;
  81.  
  82. Procedure moveesquerda (var a : tabuleiro; var cx, cy, j : integer);
  83. Begin
  84.     if (a [cx - 1] [cy] = 0) then
  85.     begin
  86.         a [cx] [cy] := 1;
  87.         cx := cx - 1;
  88.     end
  89.     else
  90.         j := 0;
  91. End;
  92.  
  93. Procedure movecima (var a : tabuleiro; var cx, cy, j : integer);
  94. Begin
  95.     if (a [cx] [cy - 1] = 0) then
  96.     begin
  97.         a [cx] [cy] := 1;
  98.         cy := cy - 1;
  99.     end
  100.     else
  101.         j := 0;
  102. End;
  103.  
  104. Procedure movebaixo (var a : tabuleiro; var cx, cy, j : integer);
  105. Begin
  106.     if (a [cx] [cy + 1] = 0) then
  107.     begin
  108.         a [cx] [cy] := 1;
  109.         cy := cy + 1;
  110.     end
  111.     else
  112.         j := 0;
  113. End;
  114.  
  115. Procedure move_(var a : tabuleiro; var i, j, x, cx, y, cy, tx, ty : integer; var d : char);
  116. Begin
  117.     if (d = 'd') then
  118.         movedireita (a, cx, cy, j)
  119.     else if (d = 'a') then
  120.         moveesquerda (a, cx, cy, j)
  121.     else if (d = 'w') then
  122.         movecima (a, cx, cy, j)
  123.     else if (d = 's') then
  124.         movebaixo (a, cx, cy, j);
  125.     a [cx] [cy] := 1;
  126.     atualizatamanho (a, x, y);
  127. End; (* End do procedure move. *)
  128.  
  129. VAR tab : tabuleiro;
  130.     contador, vida, cabecax, cabecay, caudax, cauday, tamtabx, tamtaby, tamsnake : integer;
  131.     direcao, d: char;
  132. BEGIN
  133.     inicializatab (tab, tamtabx, tamtaby);
  134.     inicializavar (cabecax, cabecay, caudax, cauday, vida, contador, tamsnake, tamtabx, tamtaby, direcao);
  135.     repeat
  136.         repeat
  137.             clrscr;
  138.             imprime (tab, tamtabx, tamtaby, tamsnake);
  139.             move_(tab, contador, vida, tamtabx, cabecax, tamtaby, cabecay, caudax, cauday, direcao);
  140.             delay (dificuldade);
  141.         until (keypressed = true) or (vida = 0);
  142.         d := readkey;
  143.     until (vida = 0);
  144.     writeln ('Perdeu, playboy!')
  145. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement