Advertisement
wojtas626

[PAS] Rosnacy kwadrat

Jan 18th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.91 KB | None | 0 0
  1. program kwadrat;
  2.  
  3. uses
  4.     crt, DOS;
  5.  
  6. const
  7.      x=9;
  8.      y=3;
  9.  
  10. var
  11.      i, j, k, centralX, centralY, maxEdge, edge, direction: Integer;
  12.      positions: Array[1..x,1..y] of Boolean;
  13.  
  14. procedure reset();
  15.      begin
  16.           for j:=1 to y do
  17.           begin
  18.                for i:=1 to x do
  19.                begin
  20.                positions[i,j] := false;
  21.                end;
  22.           end;
  23.      end;
  24.  
  25. procedure draw();
  26.      begin
  27.           for j:=1 to y do    {rysowanie}
  28.           begin
  29.                for i:=1 to x do
  30.                begin
  31.                     if positions[i,j] = true then
  32.                     begin
  33.                          write('X ');
  34.                     end
  35.                     else write('O ');
  36.                end;
  37.                writeLn();
  38.           end;
  39.      end;
  40.  
  41. begin
  42.      reset;
  43.  
  44.      if x<=y then
  45.      begin
  46.           maxEdge := x;
  47.      end else maxEdge := y;
  48.      maxEdge := maxEdge div 2;
  49.      edge := maxEdge;
  50.  
  51.      centralX := (x div 2) + 1;
  52.      centralY := (y div 2) + 1;
  53.      positions[centralX,centralY] := true;
  54.  
  55.      while(true) do
  56.      begin
  57.  
  58.      draw;
  59.  
  60.      if edge = maxEdge then
  61.      begin
  62.           direction := 1;
  63.      end
  64.      else if edge = 0 then
  65.      begin
  66.           direction := 0;
  67.      end;
  68.  
  69.      if direction = 1 then
  70.      begin
  71.           for k := 2 to centralX do
  72.           begin
  73.                if positions[k, centralY] = true then
  74.                begin
  75.                     reset;
  76.                     for j := k-1 to 2*centralX-k+1 do
  77.                     begin
  78.                          positions[j, centralY - centralX + k - 1] := true;
  79.                          positions[j, centralY + centralX - k + 1] := true;
  80.                     end;
  81.                     for j:= centralY - centralX + k to centralY + centralX - k do
  82.                     begin
  83.                          positions[k-1 ,j] := true;
  84.                          positions[2*centralX-k+1 ,j] := true;
  85.                     end;
  86.  
  87.                     break;
  88.                end;
  89.           end;
  90.  
  91.           edge := edge - 1;
  92.      end else
  93.      begin
  94.           for k := 1 to centralX-1 do
  95.           begin
  96.                if positions[k, centralY] = true then
  97.                begin
  98.                     reset;
  99.                     for j := k+1 to 2*centralX-k-1 do
  100.                     begin
  101.                          positions[j, centralY - centralX + k + 1] := true;
  102.                          positions[j, centralY + centralX - k - 1] := true;
  103.                     end;
  104.                     for j:= centralY - centralX + k + 2 to centralY + centralX - k - 2 do
  105.                     begin
  106.                          positions[k+1 ,j] := true;
  107.                          positions[2*centralX-k-1 ,j] := true;
  108.                     end;
  109.  
  110.                     break;
  111.                end;
  112.           end;
  113.           edge := edge + 1;
  114.      end;
  115.      delay(300);
  116.      clrScr;
  117.      end;
  118.  
  119. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement