感谢1407刘可盈同学提供
uses crt;
var
p:array[1..4,1..5] of byte;
q:array[1..4,1..5] of char;
a,b,c,d,e,bs,g,i,j,f,s,x1,y1,x2,y2:byte;
begin
clrscr;
cursoroff;
gotoxy(33,12); //封面页
writeln('字 符 翻 翻 看');
gotoxy(35,14);
writeln('By 刘可盈');
delay(5000);
clrscr;
gotoxy(19,10);
writeln('规则:每次可以翻两个数,如果这两个数对应的');
gotoxy(19,12);
writeln('字符相同便消除,请在20步内消除尽量多的字符');
gotoxy(32,15);
writeln('按回车键开始游戏');
readln;
clrscr;
randomize; //随机生成字符
repeat
a:=0;b:=0;c:=0;d:=0;e:=0;
for i:=1 to 4 do
for j:=1 to 5 do begin
p[i,j]:=random(5);
case p[i,j] of
0:begin q[i,j]:='@'; a:=a+1; end;
1:begin q[i,j]:='#'; b:=b+1; end;
2:begin q[i,j]:='$'; c:=c+1; end;
3:begin q[i,j]:='&'; d:=d+1; end;
4:begin q[i,j]:='%'; e:=e+1; end;
end;
end;
until (a mod 2=0) and (b mod 2=0) and (c mod 2=0) and (d mod 2=0) and (e mod 2=0); //检查字符是否成对
bs:=21;
gotoxy(12,20);
write('the first: ');
gotoxy(12,21);
write('the second: ');
gotoxy(12,5);
write('step: ');
cursoron;
while (bs>1) and (g<20) do begin //当步数为0或全部消完时结束游戏
textcolor(white);
bs:=bs-1;
gotoxy(18,5);
write(bs:2);
for i:=1 to 4 do begin
gotoxy(32,7+i*2);
for j:=1 to 5 do if p[i,j]=6 then begin textcolor(darkgray);write(q[i,j]:3);end //已消除的变成灰色字符
else begin textcolor(yellow);write((i-1)*5+j:3);end; //输出编号
writeln;
end;
gotoxy(24,21);
clreol;
repeat //读入第一个数
gotoxy(23,20);
clreol;
textcolor(yellow);
readln(f);
x1:=(f-1) div 5+1;
y1:=(f-1) mod 5+1;
until (f>0) and (f<21) and (p[x1,y1]<6); //防止输入的数超出范围或已消除
gotoxy(30+y1*3,x1*2+7);
write(q[x1,y1]:2);
repeat //读入第二个数
gotoxy(24,21);
clreol;
textcolor(yellow);
readln(s);
x2:=(s-1) div 5+1;
y2:=(s-1) mod 5+1;
until (s>0) and (s<21) and (p[x2,y2]<6) and (f<>s);
gotoxy(30+y2*3,x2*2+7);
write(q[x2,y2]:2);
delay(2000);
if (p[x1,y1]=p[x2,y2]) then begin //标记消除
g:=g+2;
p[x1,y1]:=6;
p[x2,y2]:=6;
end;
end;
clrscr;
gotoxy(38,12);
textcolor(lightred);
if g=20 then write('Win!')
else write('Fail');
delay(5000);
end.