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
| program numbers;
uses Crt;
const
MAXLEV=5; //
K_ENTER=13;//
K_ESC=27;//
type
ArOfint=array[1..MAXLEV] of integer;
type
win=record
nik: string[20];
step: integer;
end;
winner=file of win;
var
F:winner;
igrok:ArOfint;//
comp:ArOfint; //
level:integer;//
nu:integer;//
nm:integer;//
KeyCode:integer;//
otl:boolean;
i,n,ans:integer;
b: array[1..20] of win;
w: win;
{=====================================================================}
procedure GetComp(var a:ArOfInt;n:integer);
var
i:integer;//
begin
randomize;
for i:=1 to n do
a[i]:=random(10);
if otl then begin
writeln;
write('Combinaciya computera:');
for i:=1 to n do write(a[i]);
writeln;
end;
end;
{====================================================================}
function ugad(comp,igrok:ArOfInt;n:integer):integer;
var
u:integer; //
i,j:integer;
found:boolean;{TRUE,if igrok[i]=comp[j]}
begin
u:=0;
for i:=1 to n do //
begin
j:=1;
found:=FALSE;
repeat
if igrok[i]=comp[j] then//
begin
comp[j]:= -1;//
u:=u+1;
found:=TRUE;
end
else j:=j+1;
until(j>n) or found;
end;
ugad:=u;
end;
{====================================================================}
function mesto(comp,igrok:ArOfInt;n:integer):integer;
var
m:integer;
i:integer;
begin
m:=0;
for i:=1 to n do
if comp[i]=igrok[i]
then m:=m+1;
mesto:=m;
end;
{===================================================================}
function GetIgrok(var a:ArOfint; n:integer; mes:string):integer;
var
ch:char; //
dec:integer;//
x,y:integer;//
i:integer;
code:integer;
begin
i:=1;
write(mes);
repeat
ch:=readkey;
dec:=ord(ch);//
if(ch>='0')and (ch<='9') and (i<=n)//
then //
begin //
write(ch);
val(ch,a[i],code);
i:=i+1;
end
else //*
if (dec=8) and (i>1)
then
begin
i:=i-1;
x:=whereX;
y:=whereY;
gotoXY(x-1,y);//
write(' ');
gotoXY(x-1,y);
end;
until((i>n) and (dec=K_ENTER)) or (dec=K_ESC);
GetIgrok:=dec;
end;
{=====================================================================}
procedure pravila(n:integer);//
begin
writeln;
writeln;
writeln('Computer zadumal cislo iz' ,n, 'cifr.Vi dolgni ego otgodat.');
write('Posle vvoda ocherdnogo cisla programma');
writeln('soobhaet,skolko cifr');
writeln('ugadano,i skolko iz nih nahoditsya na svoih mestah.','Naprimer,');
writeln('esli zadumano cislo 435 i vvedeno 457','to ugadani 2 cifri,');
writeln('i odna cifra nahoditsya na svoem meste.');
writeln('Pri vvode mogno ispolzovat <BackSpase>.','Posle vvoda chisla');
writeln('sleduet nagat klavishu <Enter> ili <Esc> dlya prekrasheniya igri.');
writeln;
end;
{====================================================================}
procedure NewRecord;
var n,i: integer;
begin
assign (F, 'records.txt');
reset (F);
while not eof(F) do read (F,b[i]);
b[i+1]:=w;
begin
for i:=1 to sizeof(F) do
if b[i].step>b[i+1].step then
begin
w:=b[i];
b[i]:=b[i+1];
b[i+1]:=w;
end;
end;
close(F);
end;
{=====================================================================}
begin//
writeln ('Угадай число');
writeln ('1. Играть');
writeln ('2. �Просмотреть таблицу рекордов ');
writeln ('‚Выберете действие');
readln (ans);
case ans of
1:
begin
writeln ('Введети уровень сложности(от 2 до 5) ');
readln (level);
otl:=FALSE;
n:=0;
pravila(level);//
GetComp(comp,level);
repeat
KeyCode:=GetIgrok(igrok,level,'Vah variant -> ');
if KeyCode<>K_ESC then begin
nu:=ugad(comp,igrok,level);
nm:=mesto(comp,igrok,level);
n:=n+1;
writeln('Ugadano:',nu,'.Na svoih mestah:',nm);
writeln('Сделано попыток',n);
end;
until
((nu=level)and (nm=level)) or (KeyCode=K_ESC);
if KeyCode<>K_ESC
then
begin
writeln('Yra!Vi ugadali chislo!!!');
writeln('Сделано',n,'ходов');
w.step:=n;
writeln('Введите ваше имя- ');
readln(w.nik);
NewRecord;
end
else
begin
writeln('Igra zavershena po nagatiu <Esc>.');
write('Zadumannoe chislo:');
for i:=1 to level do
write(comp[i]);
writeln;
end;
write('Nagmite klavishu <Enter> dlya zaversheniya.');
readln;
end;
{2:writeln('boo'); }
end;
end. |