?? 1.pas
字號:
program game;
uses crt;
var fl,flag,fst,fq:boolean;
a:string[10];
fa,fb,ga,k,ab,db,i,j,b:integer;
shu,shub:array[1..4]of integer;
his:array[1..8,1..3] of integer;
z:set of 1..9;
procedure list1;
begin
writeln ('It is a guess number game. Made by Pan xiao huai');
writeln ('----------------game menu------------');
writeln (' 1------start');
writeln (' 2------view help');
writeln (' 3------end');
write ('Please enter your choice(1-3):');
readln (ab);
if ab=3 then ab:=4;
end;
procedure list2;
begin
writeln ('----------------game menu------------');
writeln (' 1------start');
writeln (' 2------view help');
writeln (' 3------view the history');
writeln (' 4------end');
write ('Please enter you choice(1-4):');
readln (ab);
end;
procedure creat;
var
i,j:integer;
z:set of 1..9;
begin
randomize;
j:=1;
z:=[1..9];
ga:=0;
repeat
i:=round(random*10);
if i in z then begin
z:=z-[i];
shu[j]:=i;
ga:=ga*10+shu[j];
inc(j)
end;
until j=5;
end;
procedure inputdata;
begin
repeat
flag:=true;
writeln('please input the number you guess(the for number must be different 1-9):');
write ('the ',k,' time:');
readln (a);
b:=0;
z:=[1..9];
for i:=1 to 4 do
if a[i] in ['1'..'9'] then
begin
shub[i]:=ord(a[i])-ord('0');
b:=b*10+shub[i];
if not(shub[i] in z) then flag:=false
else z:=z-[shub[i]];
end
else flag:=false;
if (b<1000) or (b>9999) then flag:=false;
if length(a)<>4 then flag:=false;
if flag=false then writeln ('----------wrong input!----------');
until flag=true;
his[k,1]:=b;
end;
procedure comp;
begin
fl:=false;
fa:=0;
fb:=0;
for i:=1 to 4 do
for j:=1 to 4 do
if shub[i]=shu[j] then if i=j then begin inc(fa);inc(fb) end
else inc(fb);
writeln (fa,' ',fb);
his[k,2]:=fa;
his[k,3]:=fb;
if fa=4 then fl:=true;
end;
procedure helpd;
begin
clrscr;
writeln ('-----------------------------help file---------------------------');
writeln (' This is a guess number game.Though it is very simple ,it is');
writeln ('very intresting');
writeln (' ----------------how to play?------------------');
writeln (' When game start,the computer will creat four different number,t');
writeln ('you just guess the four number.when you guess the four numbers');
writeln ('for the first time ,the computer will tell you how many number');
writeln ('you guessed is right.the first rusult is the number of right ');
writeln ('ones and the right position.the second result is the total ');
writeln ('right number you guessed');
writeln (' -----------------------------------------------');
writeln ('remember you just have 10 times');
writeln (' the end, wish you have a good time!');
writeln (' -----made by Panxiaohuai');
end;
procedure history;
begin
clrscr;
writeln ('The meant number is: ',ga);
writeln ('The numbers you guessed is as follows:');
for i:=1 to k-1 do
writeln (' ',his[i,1],' ',his[i,2],' ',his[i,3]);
end;
procedure mainp;
begin
fst:=false;
creat;
db:=0;
k:=1;
writeln ('--------you just have 10 choices,now begin---------------');
writeln;
repeat
inputdata;
comp;
inc(db);
inc(k);
until (fl=true) or (db=10);
if fl=true then begin
writeln ('--------------Great!You win!---------');
end
else begin
writeln ('--------------ha,ha,you lost!!-------');
writeln ('------The meant number is:',ga);
end;
writeln ('press enter to continue...');
readln
end;
begin
clrscr;
list1;
fst:=true;
repeat
case ab of
1:mainp;
2:helpd;
3:history;
4:exit
end;
if fst=true then list1
else list2;
until ab=4;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -