Advertisement
tolikpunkoff

GRLIFE.PAS

Feb 18th, 2018
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.00 KB | None | 0 0
  1. Uses Graph,Crt;
  2. label qwerty;
  3. const clr:FillPatternType=(255,255,255,255,255,255,255,255);
  4.       max=159; maxb=79;
  5. VAR
  6.    _Pole1:Array [ 0..max , 0..101 ] of byte;
  7.    _Pole2:Array [ 0..max , 0..101 ] of byte;
  8.    _X,_Y,__X,__Y,_I,_J,__i:byte;
  9.    _A:char;
  10.    FilNam:string;
  11.    F:File of byte;
  12.    Kom:array [0..135] of char;
  13.    Pocol:longInt;
  14. function _Str(a:LongInt):String;
  15. var qw:String;
  16. begin
  17. Str(a:28,qw);
  18. _Str:=qw;
  19. end;
  20. Procedure Load;
  21. var GD,GR:Integer;
  22.  
  23. begin
  24. GD:=9{Detect};GR:=2;Pocol:=0;
  25. InitGraph(GD,GR,'DRIVERS');
  26. setbkcolor(0);
  27. SetFillPattern( clr , 1 );
  28. bar(0,2,639,404);
  29. end;
  30.  
  31. Begin
  32. Load;
  33. For _J:=0 to 101 do
  34. For _I:=0 to maxb do begin
  35. _Pole1[_I*2+1,_j]:=0;_Pole2[_I*2+1,_j]:=0;_Pole1[_I*2,_j]:=0;_Pole2[_I*2,_j]:=0;
  36. end;
  37. _X:=1;_Y:=1;_A:=#0;__X:=0;__Y:=0;
  38. while _A<>#27  do
  39. begin
  40. _A:=readkey;
  41.                                SetFillPattern( clr , 1 );
  42.                                bar(_X*4-2,_Y*4,3+_X*4-2,3+_Y*4);
  43. if _Pole1[_X,_Y]=0 then begin {setcolor(0);} SetFillPattern( clr , 0 ); bar(_I*4,_J*4,2+_I*4,2+_J*4); end
  44.    else begin {setcolor(7);} SetFillPattern( clr , 2 ); bar(_I*4,_J*4,2+_I*4,2+_J*4); end;
  45.  
  46. if _A=#60 Then
  47. begin
  48. while not keypressed do
  49. BEGIN
  50. {delay (1);}
  51. Pocol:=Pocol+1;
  52. FOR _I:=1 to max do
  53. for _J:=1 to 100 do
  54. begin
  55. if 3=_pole1[_i-1,_j-1]
  56. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  57. then _Pole2[_I,_J]:=1;
  58. if 4<=_pole1[_i-1,_j-1]
  59. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  60. then _Pole2[_I,_J]:=0;
  61. if 1>=_pole1[_i-1,_j-1]
  62. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  63. then _Pole2[_I,_J]:=0;
  64. if 2=_pole1[_i-1,_j-1]
  65. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  66. then _Pole2[_I,_J]:=_Pole1[_I,_J];
  67. end;
  68. FOR _I:=1 to max do
  69. for _J:=1 to 100 do
  70. begin
  71. _Pole1[_I,_J]:=_Pole2[_I,_J];
  72. end;
  73. For _I:=1 to max do
  74. For _J:=1 to 100 do
  75. begin
  76. textbackground(1);
  77. textcolor(7);
  78. gotoxy(_I-__X,_J-__Y);
  79. if (_I=_X)and(_J=_Y) then begin
  80.                                textbackground(7);
  81.                                textcolor(1);
  82.                                end;
  83. if _Pole1[_I,_J]=0 then begin {setcolor(0);} SetFillPattern( clr , 0 ); bar(_I*4-2,_J*4,2+_I*4-2,2+_J*4); end
  84.    else begin {setcolor(7);} SetFillPattern( clr , 2 ); bar(_I*4-2,_J*4,2+_I*4-2,2+_J*4); end;
  85. end;
  86. for _I:=1 to 24 do
  87. {begin
  88. gotoxy(51,_I); WRITE('                              '); end;
  89. gotoxy(51,1); WRITE(' _X=',_X,' __X=',__X);
  90. gotoxy(51,3); WRITE(' _Y=',_Y,' __Y=',__Y);
  91. gotoxy(51,5); WRITE(' Очистить все    F1');
  92. gotoxy(51,7); WRITE(' жизнь до клавиши F2');}
  93. {OutTextXY(_I,1,'                              ');}
  94. {OutTextXY(1,_I*10+410,'*                              *');
  95. OutTextXY(10,420,'F1....Очистить все    ');
  96. OutTextXY(10,430,'F2....Жизнь до клавиши');
  97. OutTextXY(10,440,'F3....Сохранить, как???');
  98. OutTextXY(10,450,'F4....Загрузить, что???');
  99.  }
  100. SetFillPattern( clr , 1 ); bar(245,458,640,468);
  101. OutTextXY(270,460,'Текущее значение: '+_Str(pocol));
  102.  
  103.  
  104. end;
  105.  
  106. end;
  107.  
  108. if _A=#59 Then
  109. begin
  110. For _J:=0 to 101 do
  111. For _I:=0 to maxb do begin
  112. _Pole1[_I*2+1,_j]:=0;_Pole2[_I*2+1,_j]:=0;_Pole1[_I*2,_j]:=0;_Pole2[_I*2,_j]:=0;
  113. end;
  114. end;
  115. if _A=#49 Then Begin _Y:=_Y+10; _X:=_X-10; end;
  116. if _A=#51 Then Begin _Y:=_Y+10; _X:=_X+10; end;
  117. if _A=#55 Then Begin _Y:=_Y-10; _X:=_X-10; end;
  118. if _A=#57 Then Begin _Y:=_Y-10; _X:=_X+10; end;
  119. if _A=#50 Then _Y:=_Y+10;
  120. if _A=#52 Then _X:=_X-10;
  121. if _A=#54 Then _X:=_X+10;
  122. if _A=#56 Then _Y:=_Y-10;
  123. if _A=#77 Then _X:=_X+1;
  124. if _A=#75 Then _X:=_X-1;
  125. if _A=#80 Then _Y:=_Y+1;
  126. if _A=#72 Then _Y:=_Y-1;
  127. if _A=#32 Then If _Pole1[_X,_Y]=0 then _Pole1[_X,_Y]:=1 else _Pole1[_X,_Y]:=0;
  128. if _A=#53 Then If _Pole1[_X,_Y]=0 then _Pole1[_X,_Y]:=1 else _Pole1[_X,_Y]:=0;
  129.  
  130. if _A=#61 Then
  131. begin
  132. RestoreCRTMode;
  133. clrscr;
  134. WriteLn('Введи, г..д, имя файла.      * Сохранение *');
  135. ReadLn(FilNam);
  136. Assign(F,FilNam);
  137. {$I-}
  138. ReWrite(F);
  139. IF IOResult<>0 Then begin FilNam:='ErrorFil.TMP'; WriteLn('Имя файла: ','ErrorFil.TMP'); Assign(F,FilNam); ReWrite(F); end;
  140. {$I+}
  141. Write(F,_X);
  142. Write(F,_Y);
  143. FOR _I:=1 to max do
  144. for _J:=1 to 100 do
  145.           Write(F,_Pole1[_I,_J]);
  146. WriteLn('Введите строку комментария.(не более 135 символов)');
  147. ReadLn(Kom);
  148. for _i:=0 to Length(Kom) do
  149. begin
  150. _J:=Ord(Kom[_I]);
  151. Write(F,_J);
  152. end;
  153.  
  154. SetGraphMode(GetGraphMode);
  155. SetFillPattern( clr , 1 );
  156. bar(2,2,564,404);
  157. Close(F);
  158. end;
  159. if _A=#62 Then
  160. begin
  161. RestoreCRTMode;
  162. clrscr;
  163. WriteLn('Введи, г..д, имя файла.      * Открытие *');
  164. ReadLn(FilNam);
  165. Assign(F,FilNam);
  166. {$I-}
  167. Reset(F);
  168. IF IOResult<>0 Then begin WriteLn('Ошибка.');delay(60000); Goto qwerty; end;
  169. {$I+}
  170. Read(F,_X);
  171. Read(F,_Y);
  172. FOR _I:=1 to max do
  173. for _J:=1 to 100 do
  174.           Read(F,_Pole1[_I,_J]);
  175. for _i:=0 to Length(Kom) do
  176. begin
  177. {_J:=Ord(Kom[_I]);}
  178. if not(eof(F)) Then begin
  179. read(F,_J);
  180. Kom[_I]:=Chr(_J);        end;
  181. end;
  182.  
  183. Close(F);
  184. qwerty:
  185. SetGraphMode(GetGraphMode);
  186. SetFillPattern( clr , 1 );
  187. bar(2,2,564,404);
  188.  
  189. end;
  190. if _A=#63 Then Pocol:=0;
  191.  
  192. if _A=#13 Then
  193. BEGIN
  194. Pocol:=Pocol+1;
  195. FOR _I:=1 to max do
  196. for _J:=1 to 100 do
  197. begin
  198. if 3=_pole1[_i-1,_j-1]
  199. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  200. then _Pole2[_I,_J]:=1;
  201. if 4<=_pole1[_i-1,_j-1]
  202. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  203. then _Pole2[_I,_J]:=0;
  204. if 1>=_pole1[_i-1,_j-1]
  205. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  206. then _Pole2[_I,_J]:=0;
  207. if 2=_pole1[_i-1,_j-1]
  208. +_pole1[_i,_j-1]+_pole1[_i+1,_j-1]+_pole1[_i-1,_j]+_pole1[_i+1,_j]+_pole1[_i-1,_j+1]+_pole1[_i,_j+1]+_pole1[_i+1,_j+1]
  209. then _Pole2[_I,_J]:=_Pole1[_I,_J];
  210. end;
  211. FOR _I:=1 to max do
  212. for _J:=1 to 100 do
  213. begin
  214. _Pole1[_I,_J]:=_Pole2[_I,_J];
  215. end;
  216.  
  217. END;
  218.  
  219. if _X<1   then _x:=1   ;
  220. if _X>max then _X:=max ;
  221. if _Y<1   then _Y:=1   ;
  222. if _Y>100 then _Y:=100 ;
  223.  
  224. {if (_Y<=__Y)AND(_Y>0)    then __Y:=__Y-1  ;}
  225. {if (_Y>__Y+25)and(_Y<=100) then __Y:=__Y+1  ;}
  226. {if __Y<0   then __Y:=0   ;
  227. if __Y>76 then __Y:=76 ;
  228. if (_X<=__X)AND(_X>0)    then __X:=__X-1  ;
  229. if (_X>__X+50)and(_X<=100) then __X:=__X+1  ;
  230. if __X<0   then __X:=0   ;
  231. if __X>51 then __X:=76 ;}
  232.  
  233.  
  234. For _I:=1 to max do
  235. For _J:=1 to 100 do
  236. begin
  237. textbackground(1);
  238. textcolor(7);
  239. gotoxy(_I-__X,_J-__Y);
  240. if (_I=_X)and(_J=_Y) then begin
  241.                                SetFillPattern( clr , 15 );
  242.                                bar(_I*4-2,_J*4,3+_I*4-2,3+_J*4);
  243.                                end;
  244. if _Pole1[_I,_J]=0 then begin {setcolor(0);} SetFillPattern( clr , 0 ); bar(_I*4-2,_J*4,2+_I*4-2,2+_J*4); end
  245.    else begin {setcolor(7);}  SetFillPattern( clr , 2 ); bar(_I*4-2,_J*4,2+_I*4-2,2+_J*4); end;
  246. end;
  247. for _I:=1 to 5 do
  248. {begin gotoxy(51,_I); WRITE('                              '); end;
  249. gotoxy(51,1); WRITE(' _X=',_X,' __X=',__X);
  250. gotoxy(51,3); WRITE(' _Y=',_Y,' __Y=',__Y);
  251. gotoxy(51,5); WRITE(' Очистить все    F1');
  252. gotoxy(51,7); WRITE(' жизнь до клавиши F2');}
  253. {OutTextXY(1,_I*10+410,'*                              *');}
  254. OutTextXY(10,420,'*F1....Очистить все         *');
  255. OutTextXY(10,430,'*F2....Жизнь до клавиши     *');
  256. OutTextXY(10,440,'*F3....Сохранить, как???    *');
  257. OutTextXY(10,450,'*F4....Загрузить, что???    *');
  258. OutTextXY(10,460,'*F5....Обнулить счетчик     *');
  259.  
  260. OutTextXY(270,420,copy(Kom,1,45));
  261. OutTextXY(270,430,copy(Kom,46,45));
  262. OutTextXY(270,440,copy(Kom,91,45));
  263. SetFillPattern( clr , 1 ); bar(245,458,640,468);
  264. OutTextXY(270,460,'Текущее значение: '+_Str(pocol));
  265.  
  266.  
  267. end;
  268. CloseGraph;
  269. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement