-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLIFE.PAS
More file actions
212 lines (186 loc) · 3.46 KB
/
LIFE.PAS
File metadata and controls
212 lines (186 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{ @author: Sylvain Maltais ([email protected])
@created: 2025
@website(https://www.gladir.com/7iles)
@first version: Goupil Brother
@website(http://goupilbrother.free.fr)
@original concept: John Conway (1937-2020)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
@description: Une cellule survit si elle a 2 ou 3 voisins.
Elle peut prendre naissance si elle a 3 voisins
sinon elle meurt.
}
Program LIFE;
Uses {$IFDEF FPC}
Crt,PtcCrt
{$ELSE}
DOS,Crt
{$ENDIF};
Var
LifeValue,LifeValue2:Array[0..23,0..23] of Byte; {0:dead 1:alive}
Step,XLife,YLife:Byte;
{$IFNDEF FPC}
Procedure CursorOff;
Var
Regs:Registers;
Begin
Regs.AH:=1;
Regs.CH:=32;
Regs.CL:=0;
Intr($10,Regs);
End;
Procedure CursorOn;
Var
Regs:Registers;
Begin
Regs.AX:=$0100;
Regs.CX:=(7 shl 8)+9;
Intr($10,Regs);
End;
{$ENDIF}
Procedure Body_of_Game;
Var
I,J:Byte;
Begin
CursorOff;
TextBackground(Black);
TextColor(White);
GotoXY(8,1);
Write('Jeu de la Vie (Game of Life)');
For I:=0 to 23 do
For J:=0 to 23 do
Begin
GotoXY(I+1,J+2);
TextBackground(Black);
TextColor(White);
If LifeValue[I,J]<>0 Then
Begin
TextBackground(White);
TextColor(Black);
End;
Write(' ');
End;
TextBackground(White);
TextColor(Black);
GotoXY(26,6);
Write('Fleches');
GotoXY(26,8);
Write('Espace');
GotoXY(26,10);
Write('Entree');
GotoXY(26,17);
Write('Echap');
GotoXY(26,13);
Write('C');
GotoXY(26,15);
Write('R');
TextBackground(Black);
TextColor(White);
GotoXY(27,13);
Write('lear');
GotoXY(27,15);
Write('andom');
GotoXY(27,11);
Write('1 cycle');
GotoXY(XLife+1,YLife+2);
End;
Procedure Life_Cycle;
Var
I,J,K,L,Voisins:Integer;
Begin
For I:=0 to 23 do
For J:=0 to 23 do
LifeValue2[I,J]:=LifeValue[I,J];
For I:=0 to 23 do
For J:=0 to 23 do
Begin
Voisins:=0;
For K:=0 to 2 Do
For L:=0 to 2 Do
If not ((K=1) and (L=1)) Then
If (I+K-1)>=0 Then
If (I+K-1)<24 Then
If (J+L-1)>=0 Then
If (J+L-1)<24 Then
If LifeValue2[I+K-1,J+L-1]=1 Then
Inc(Voisins);
Case Voisins of
2:Begin End;
3:LifeValue[I,J]:=1;
Else LifeValue[I,J]:=0;
End;
End;
End;
Procedure Clear_Game;
Var
I,J:Integer;
Begin
XLife:=12;
YLife:=11;
For I:=0 to 23 do
For J:=0 to 23 do
LifeValue[I,J]:=0;
End;
Procedure Random_Game;
Var
I,J:Integer;
Begin
XLife:=12;
YLife:=11;
For I:=0 to 23 do
For J:=0 to 23 do
LifeValue[I,J]:=Random(2);
End;
Procedure Init_Game;
Begin
TextMode(BW40);
ClrScr;
Clear_Game;
End;
Procedure Play_Game;
Var
K,K2:Char;
I:Integer;
Begin
Repeat
Repeat
Body_of_Game;
CursorOn;
Repeat Until Keypressed;
K:=ReadKey;
K2:=Char(0);
Case K of
'c','C':Clear_Game;
'r','R':Random_Game;
' ':{Space}
Case LifeValue[XLife,YLife] of
0:LifeValue[XLife,YLife]:=1;
1:LifeValue[XLife,YLife]:=0;
End;
#0:Begin
K2:=ReadKey;
Case K2 of {Up Left Right Down}
#72:If YLife>0 Then Dec(YLife);
#75:If XLife>0 Then Dec(XLife);
#77:If XLife<23 Then Inc(XLife);
#80:If YLife<23 Then Inc(YLife);
End;
End;
End;
Until (K=#27) or (K=#13);
If K=#13 Then{Enter}
Begin
Life_Cycle;
Body_of_Game;
K:=#33;K2:=#33;
End;
Until K=#27; {Eskape}
End;
Var OrigMode:Integer;
BEGIN
OrigMode:=LastMode;
Init_Game;
Play_Game;
CursorOff;
CursorOn;
TextMode(OrigMode);
END.