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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
| program X_and_O;
uses crt;
var f : array[0..2,0..2] of integer;
game,pcalc,ccalc : word;
wv : integer;
p1,c1,xcur,ycur,sv,sv2,sv3,int,m,snd : byte;
com,p2,c2 : char;
move : boolean;
label start,plr_play,com_play,cp2,newgame,ng2,win,endgame;
begin
int:=1;
snd:=1;
p1:=10;
p2:='X';
c1:=14;
c2:='O';
randomize;
textbackground(2);
goto newgame;
{Начало игры}
start:
clrscr;
f[0,0]:=0;
f[0,1]:=0;
f[0,2]:=0;
f[1,0]:=0;
f[1,1]:=0;
f[1,2]:=0;
f[2,0]:=0;
f[2,1]:=0;
f[2,2]:=0;
textbackground(2);
clrscr;
textcolor(1);
gotoxy(3,4);
write('Игрок: 0 Компьютер(');
case int of
0 : write('проф');
1 : write('норма');
2 : write('кретин');
end;
write('): 0');
gotoxy(3,5);
write('Игра: 1');
textbackground(7);
textcolor(8);
gotoxy(1,1);
clreol;
write(#24#25#26#27,' >> движение курсора пробел >> ход 1 >> новая игра 2 >> выход ');
textbackground(2);
if move then goto plr_play else goto com_play;
{Ход игрока}
plr_play:
if (game=100) or (game=200) or (game=300) then goto endgame;
textcolor(1);
gotoxy(10,4);
write(pcalc);
gotoxy(24,4);
case int of
0 : write('проф');
1 : write('норма');
2 : write('кретин');
end;
write('): ');
write(ccalc);
gotoxy(9,5);
case game of
0..100 : wv:=100-game;
101..200 : wv:=200-game;
else wv:=300-game;
end;
write(game,'(до конца турнира осталось ',wv,' игр)');
gotoxy(35,10);
write('┌───┬───┬───┐');
gotoxy(35,11);
write('│ │ │ │');
gotoxy(35,12);
write('├───┼───┼───┤');
gotoxy(35,13);
write('│ │ │ │');
gotoxy(35,14);
write('├───┼───┼───┤');
gotoxy(35,15);
write('│ │ │ │');
gotoxy(35,16);
write('└───┴───┴───┘');
sv:=0;
repeat
sv2:=f[trunc(sv/3),sv mod 3];
if sv2<>0 then
begin
gotoxy(trunc(sv/3)*4+37,(sv mod 3)*2+11);
if sv2=1 then begin textcolor(p1); write(p2); end else begin textcolor(c1); write(c2); end;
end;
sv:=sv+1;
until sv=9;
textcolor(5);
gotoxy(xcur*4+38,ycur*2+11);
write('');
sv:=0;
repeat
wv:=f[sv,0]+f[sv,1]+f[sv,2];
if (wv=3) or (wv=-3) then goto win;
wv:=f[0,sv]+f[1,sv]+f[2,sv];
if (wv=3) or (wv=-3) then goto win;
sv:=sv+1;
until sv=3;
wv:=f[0,0]+f[1,1]+f[2,2];
if (wv=3) or (wv=-3) then goto win;
wv:=f[2,0]+f[1,1]+f[0,2];
if (wv=3) or (wv=-3) then goto win;
if (f[0,0]<>0) and (f[0,1]<>0) and (f[0,2]<>0) and (f[1,0]<>0) and (f[1,1]<>0) and (f[1,2]<>0) and (f[2,0]<>0) and (f[2,1]<>0)
and (f[2,2]<>0) then
begin
sound(snd*1000);
f[0,0]:=0;
f[0,1]:=0;
f[0,2]:=0;
f[1,0]:=0;
f[1,1]:=0;
f[1,2]:=0;
f[2,0]:=0;
f[2,1]:=0;
f[2,2]:=0;
delay(snd*2000);
nosound;
gotoxy(8,8);
textcolor(14);
write('Ничья. ');
game:=game+1;
if move then move:=false else move:=true;
readkey;
gotoxy(8,8);
write(' ');
if move then goto plr_play else goto com_play;
end;
com:=readkey;
case com of
'1' : goto newgame;
'2' : exit;
' ' : if f[xcur,ycur]=0 then begin f[xcur,ycur]:=1; goto com_play; end
else begin sound(snd*100); delay(snd*300); nosound; end;
#27 : exit;
#0 :
begin
com:=readkey;
case com of
#72 : if ycur>0 then ycur:=ycur-1;
#75 : if xcur>0 then xcur:=xcur-1;
#77 : if xcur<2 then xcur:=xcur+1;
#80 : if ycur<2 then ycur:=ycur+1;
end;
end;
end;
goto plr_play;
{Ход компютера}
com_play:
if (game=100) or (game=200) or (game=300) then goto endgame;
sv:=0;
repeat
sv2:=f[trunc(sv/3),sv mod 3];
if sv2<>0 then
begin
gotoxy(trunc(sv/3)*4+37,(sv mod 3)*2+11);
if sv2=1 then begin textcolor(p1); write(p2); end else begin textcolor(c1); write(c2); end;
end;
sv:=sv+1;
until sv=9;
sv:=0;
repeat
wv:=f[sv,0]+f[sv,1]+f[sv,2];
if (wv=3) or (wv=-3) then goto win;
wv:=f[0,sv]+f[1,sv]+f[2,sv];
if (wv=3) or (wv=-3) then goto win;
sv:=sv+1;
until sv=3;
wv:=f[0,0]+f[1,1]+f[2,2];
if (wv=3) or (wv=-3) then goto win;
wv:=f[2,0]+f[1,1]+f[0,2];
if (wv=3) or (wv=-3) then goto win;
if (f[0,0]<>0) and (f[0,1]<>0) and (f[0,2]<>0) and (f[1,0]<>0) and (f[1,1]<>0) and (f[1,2]<>0) and (f[2,0]<>0) and (f[2,1]<>0)
and (f[2,2]<>0) then goto plr_play;
if int=2 then goto cp2;
sv:=random(int+2);
if (sv=2) and (int<>0) then goto cp2;
if (f[1,1]=0) and (random(3)<>2) then begin f[1,1]:=-1; goto plr_play; end;
sv:=0;
repeat
if (f[sv,0]+f[sv,1]+f[sv,2]=2) or (f[sv,0]+f[sv,1]+f[sv,2]=-2) then
begin
sv2:=0;
repeat
if f[sv,sv2]=0 then f[sv,sv2]:=-1;
sv2:=sv2+1;
until sv2=3;
goto plr_play;
end;
if (f[0,sv]+f[1,sv]+f[2,sv]=2) or (f[0,sv]+f[1,sv]+f[2,sv]=-2) then
begin
sv2:=0;
repeat
if f[sv2,sv]=0 then f[sv2,sv]:=-1;
sv2:=sv2+1;
until sv2=3;
goto plr_play;
end;
sv:=sv+1;
until sv=3;
if (f[0,0]+f[1,1]+f[2,2]=2) or (f[0,0]+f[1,1]+f[2,2]=-2) then
begin
if f[0,0]=0 then f[0,0]:=-1;
if f[1,1]=0 then f[1,1]:=-1;
if f[2,2]=0 then f[2,2]:=-1;
goto plr_play;
end;
if (f[2,0]+f[1,1]+f[0,2]=2) or (f[2,0]+f[1,1]+f[0,2]=-2) then
begin
if f[2,0]=0 then f[2,0]:=-1;
if f[1,1]=0 then f[1,1]:=-1;
if f[0,2]=0 then f[0,2]:=-1;
goto plr_play;
end;
cp2:
repeat
sv:=random(10);
if f[trunc(sv/3),sv mod 3]=0 then begin f[trunc(sv/3),sv mod 3]:=-1; goto plr_play; end;
until sv=11;
goto plr_play;
{Настройки игры}
newgame:
clrscr;
textcolor(1);
write(' Настройки новой игры');
gotoxy(4,7);
write('1 >> Интеллект компьютера: ');
gotoxy(4,8);
write('2 >> Вы будете играть ');
gotoxy(4,11);
write('5 >> Первый ход');
gotoxy(4,12);
write('6 >> Звук');
gotoxy(4,16);
textcolor(1);
write('Пробел >> начать игру esc >> выход');
ng2:
textcolor(14);
gotoxy(31,7);
case int of
0 : write('профессионал');
1 : write('нормальный ');
2 : write('кретин ');
end;
gotoxy(26,8);
if p2='X' then write('крестиком') else write('ноликом ');
gotoxy(20,11);
case m of
0 : write('случайно ');
1 : write('ваш ');
2 : write('компьютера');
end;
gotoxy(14,12);
if snd=1 then write('включен ') else write('выключен');
gotoxy(4,9);
textcolor(p1);
write('3 >> Цвет вашей фишки');
gotoxy(4,10);
textcolor(c1);
write('4 >> Цвет фишки компьютера');
com:=readkey;
case com of
'1' : if int>0 then dec(int) else int:=2;
'2' : if p2='X' then begin p2:='O'; c2:='X'; end else begin p2:='X'; c2:='O'; end;
'3' : begin if p1<15 then p1:=p1+1 else p1:=0; if p1=2 then p1:=3; end;
'4' : begin if c1<15 then c1:=c1+1 else c1:=0; if c1=2 then c1:=3; end;
'5' : if m<2 then m:=m+1 else m:=0;
'6' : if snd=1 then snd:=0 else snd:=1;
#27 : exit;
' ' :
begin
sv:=random(2);
case m of
0 : if sv<1 then move:=true else move:=false;
1 : move:=true;
2 : move:=false;
end;
game:=1;
pcalc:=0;
ccalc:=0;
goto start;
end;
end;
goto ng2;
{Победа}
win:
gotoxy(8,8);
clreol;
if wv=3 then begin pcalc:=pcalc+1; textcolor(4); write('Вы выиграли!'); end
else begin textcolor(8); write('Вы проиграли.'); ccalc:=ccalc+1; end;
game:=game+1;
f[0,0]:=0;
f[0,1]:=0;
f[0,2]:=0;
f[1,0]:=0;
f[1,1]:=0;
f[1,2]:=0;
f[2,0]:=0;
f[2,1]:=0;
f[2,2]:=0;
sound(snd*500);
delay(snd*2000);
nosound;
delay(snd*1000);
sound(snd*500);
delay(snd*2000);
nosound;
readkey;
gotoxy(1,8);
clreol;
if move then move:=false else move:=true;
if move then goto plr_play else goto com_play;
{Окончание турнира}
endgame:
delay(6400);
while keypressed do readkey;
clrscr;
textcolor(7);
gotoxy(35,3);
if game<300 then write('Турнир окончен.') else write('Игра окончена.');
textcolor(5);
if pcalc>ccalc then begin gotoxy(15,6); write('Вы выиграли у компьютера со счётом ',pcalc,':',ccalc,' Поздравляю!'); end;
if pcalc=ccalc then begin gotoxy(36,6); write('Ничья. ',pcalc,':',ccalc); end;
if pcalc<ccalc then begin gotoxy(15,6); write('Сожалею, вы проиграли компьютеру со счётом ',pcalc,':',ccalc); end;
window(5,10,80,25);
textcolor(14);
write('Уровень интеллекта компьютера: ');
case int of
0 : writeln('профессионал.');
1 : writeln('нормальный игрок.');
2 : writeln('кретин.');
end;
writeln;
writeln(' Оценка ваших способностей:');
writeln('выигрышей: ',round(pcalc/game*100),'%');
writeln('проигрышей: ',round(ccalc/game*100),'%');
writeln('игр на ничью: ',100-round(pcalc/game*100)-round(ccalc/game*100),'%');
writeln;
writeln('Впечатления компьютера о вас и об игре с вами:');
textcolor(4);
wv:=round(pcalc/game*100);
case int of
1 : dec(wv,-5);
2 : dec(wv,-10);
end;
case wv of
-10..-6 : write('"Ну и тормоз!"');
-5..0 : write('"Вообще не умеет играть."');
1..10 : write('"Неужели кто-то играет ещё хуже?"');
11..20 : write('"Тебе нужно хорошенько потренироваться!"');
21..30 : write('"Фигово играешь."');
31..40 : write('"Мягко говоря, не очень."');
41..50 : write('"Неплохо, неплохо, но можно намного лучше."');
51..60 : write('"Неплохой результат. Хотя, конечно, можно и получше...');
61..70 : write('"Хорошо играешь!"');
71..80 : write('"Клёво играешь! У тебя сколько мегабайтов памяти?"');
81..90 : write('"Хороший результат! Эх, мне бы так..."');
91..97 : write('"Отличная игра!!!"');
98..100 : begin textcolor(6); write('"Ты что, суперкомпьютер?!"'); end;
end;
writeln;
writeln;
writeln;
textcolor(1);
if game<300 then write('Пробел >> продолжить игру esc >> выход') else write('Нажмите любую клавишу для выхода.');
window(1,1,80,25);
if game<300 then
repeat
com:=readkey;
case com of
' ' : begin inc(game); if move then move:=false else move:=true; goto start; end;
#27 : exit;
end;
until com=#27
else
begin
readkey;
exit;
end;
window(1,1,80,25);
goto start;
end. |