-
Notifications
You must be signed in to change notification settings - Fork 4
/
BOWLING.PAS
333 lines (319 loc) · 5.79 KB
/
BOWLING.PAS
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
{ @author: Sylvain Maltais ([email protected])
@created: 2011
@website(https://www.gladir.com/7iles)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program BOWLING;
Uses Crt;
Var
Screen:Array[0..25,0..40]of Char;
S,T:Array[0..4]of Integer;
NA:Array[0..4]of String;
A,B1,J,PS1,J1,Q,Score,T_,X1,X2,Z9:Integer;
PS,Terminated:Boolean;
Function Left(Const Str:String;Num:Byte):String;Begin
Left:=Copy(Str,1,Num);
End;
Function PadRight(S:String;Space:Byte):String;
Var
I:Byte;
Begin
If Length(S)<Space Then For I:=Length(S)+1 to Space do S:=S+' ';
PadRight:=S;
End;
Procedure InitGame;
Var
I:Byte;
K:Char;
Nom:String;
Begin
FillChar(Screen,SizeOf(Screen),#0);
Terminated:=False;
A:=1;
For I:=0 to 4 do NA[I]:='';
TextMode(CO80);
TextBackground(4);
TextColor(15);
ClrScr;
GotoXY(37,8);
WriteLn('BOWLING');
GotoXY(7,13);
Write('Combien de quilleurs doivent jouer (entre 1 et 4) ? ');
Repeat
K:=ReadKey;
Case K of
#27:Halt;
'1'..'4':Begin
A:=Ord(K)-Ord('0');
Break;
End;
End;
Until False;
For I:=1 to A do Begin
GotoXY(8,15+I);
Write('Entrez le nom du quilleur #',I,' : ');
ReadLn(Nom);
NA[I-1]:=Left(Nom,8);
End;
End;
Procedure DrawGameScreen;
Var
I:Byte;
Begin
TextMode(CO40);
TextBackground(4);
TextColor(15);
ClrScr;
GotoXY(10,1);
Write('1 2 3 4 5 6 7 8 9 10');
GotoxY(10,2);
For J:=1 to 31 do Write({$IFDEF FPC}'-'{$ELSE}Chr(196){$ENDIF});
For I:=1 to A do Begin
GotoXY(1,2*I+1);
TextColor(I+1);
Write(PadRight(NA[I-1],11));
J:=12;
While J<=36 do Begin
Write({$IFDEF FPC}'|'{$ELSE}Chr(179){$ENDIF},' ');
Inc(J,3);
End;
GotoXY(10,2*I+2);
For J:=1 to 31 do Write({$IFDEF FPC}'-'{$ELSE}Chr(196){$ENDIF});
End;
GotoXY(1,12);
For I:=0 to A-1 do Begin
If I=2 Then GotoXY(1,14);
TextColor(I+2);
Write(NA[I],' :',' ':19-Length(NA[I]));
End;
GotoXY(1,15);
For I:=1 to 39 do Write({$IFDEF FPC}'-'{$ELSE}Chr(196){$ENDIF});
GotoXY(1,25);
For I:=1 to 39 do Write({$IFDEF FPC}'-'{$ELSE}Chr(196){$ENDIF});
End;
Procedure InitScore;
Var
I:Byte;
Begin
For I:=0 to A-1 do S[I]:=1;
End;
Procedure RollBall;
Var
G,H,V,D:Integer;
K:Char;
Begin
H:=1;V:=24;D:=-1;
TextColor(0);
TextBackground(Z9+2);
While Not Keypressed do Begin
GotoXY(H,V);
Write(' ');
V:=V+D;
GotoXY(H,V);
Write('O');
Delay(200);
If V in[16,24]Then D:=-D;
End;
If ReadKey=#27 Then Terminated:=True;
For H:=2 to 35 do Begin
GotoXY(H-1,V);
Write(' O');
Delay(100);
End;
J:=0;
While H<40 do Begin
If Screen[V,H]=#234 Then Begin
J:=J+1;
D:=-1;
While D<=1 do Begin
X1:=V;X2:=H;
Repeat
X1:=X1+D;
X2:=X2+1;
If Screen[X1,X2]=#234 Then Begin
GotoXY(X2,X1);
Screen[X1,X2]:=#32;
Write(' ');
J:=J+1;
End
Else
Break;
Until False;
D:=D+2;
End;
End;
GotoXY(H-1,V);
Write(' O');
H:=H+1;
End;
J1:=J1+J;
GotoXY(7+3*Q+B1,2*Z9+3);
TextColor(Abs(-(2+Z9)*Byte(B1=0)));
TextBackground(Abs(-(2+Z9)*Byte(B1<>0)));
G:=J+48;
If J1=10 Then If PS Then G:=88 Else G:=47;
Write(Chr(G));
TextColor(0);
TextBackground(2+Z9);
GotoXY(H-1,V);
Write(' ');
End;
Procedure FirstBall;
Const
PC:Array[1..31]of Byte=(
234,31,29,29,234,31,29,29,234,28,
234,31,29,29,29,29,234,28,234,31,
29,29,234,28,234,31,29,29,234,31,234
);
Var
I:Byte;
Begin
GotoXY(39,17);
TextColor(0);
For I:=1 to 31 do Begin
Case PC[I]of
28:GotoXY(WhereX+1,WhereY);
29:GotoXY(WhereX-1,WhereY);
31:GotoXY(WhereX,WhereY+1);
Else Begin
Screen[WhereY,WhereX]:=Chr(PC[I]);
Write(Chr(PC[I]));
End;
End;
End;
PS1:=1;J1:=0;
RollBall;
T_:=T[Z9];Score:=S[Z9];T_:=T_+J;
Case S[Z9]of
0:Begin
If J1=10 Then If PS Then Score:=2 Else Score:=5;
End;
1:Begin
T_:=T_+J;
If J=10 Then Score:=3 Else Score:=4;
End;
2:Begin
T_:=T_+J*2;
If J<>10 Then Score:=4;
End;
3:Begin
T_:=T_+J;
If J1=10 Then Score:=5 Else Score:=1;
End;
4:Begin
T_:=T_+J;
If J=10 Then Score:=2 Else Score:=1;
End;
End;
T[Z9]:=T_;S[Z9]:=Score;
TextColor(Z9+2);
TextBackground(0);
GotoXY(31-Byte((Z9/2)=Trunc(Z9/2))*20,14-Byte(Z9<2)*2);
Write(T[Z9]);
TextColor(0);
TextBackground(Z9+2);
End;
Procedure SecondBall;Begin
PS:=False;
RollBall;
T_:=T[Z9];
Score:=S[Z9];
T_:=T_+J;
Case S[Z9]of
0:Begin
If J1=10 Then If PS Then Score:=2 Else Score:=5;
End;
1:Begin
T_:=T_+J;
If J=10 Then Score:=3 Else Score:=4;
End;
2:Begin
T_:=T_+J*2;
If J<>10 Then Score:=4;
End;
3:Begin
T_:=T_+J;
If J1=10 Then Score:=5 Else Score:=1;
End;
4:Begin
T_:=T_+J;
If J=10 Then Score:=2 Else Score:=1;
End;
End;
T[Z9]:=T_;S[Z9]:=Score;
TextColor(Z9+2);
TextBackground(0);
GotoXY(31-Byte((Z9/2)=Trunc(Z9/2))*20,14-Byte(Z9<2)*2);
Write(T[Z9]);
TextColor(0);
TextBackground(Z9+2);
End;
Procedure ExtraBalls;Begin
GotoXY(1,20);
Write('Jouez deux autres boules,',NA[Z9]);
Delay(1000);
GotoXY(1,WhereY);
Write(' ':29);
S[Z9]:=Score-1;
B1:=1;
FirstBall;
If J<>10 Then Begin
S[Z9]:=1;
B1:=2;
SecondBall;
End
Else
Begin
S[Z9]:=1;
B1:=2;
FirstBall;
End;
End;
Procedure MainLoop;
Var
I:Integer;
K:Char;
Begin
For Q:=1 to 10 do For Z9:=0 to A-1 do Begin
If Terminated Then Break;
TextBackground(Z9+2);
For I:=16 to 24 do Begin
GotoXY(1,I);
Write(' ':39);
End;
B1:=0;
FirstBall;
If J1<>10 Then Begin
B1:=1;
SecondBall;
End;
If Q=10 Then Begin
Case Score of
0:;
1,2:ExtraBalls;
3:;
4:Begin
GotoXY(1,20);
Write('Jouez une autre boule, ',NA[Z9]);
Delay(1000);
GotoXY(1,WhereY);
Write(' ':28);
S[Z9]:=1;B1:=2;
FirstBall;
End;
End;
End;
End;
GotoXY(3,16);
Write('Voulez-vous encore jouer (O ou N) ?');
If UpCase(ReadKey)='O'Then Terminated:=False
Else Terminated:=True;
End;
BEGIN
InitGame;
DrawGameScreen;
InitScore;
Repeat
MainLoop;
Until Terminated;
END.