saolei 用pascal可编什么游戏
- 二次元
- 2025-11-21 08:46:48
- 6
一、用pascal可编什么游戏
通过运用crt单元,可以编出一些简单的游戏。例如贪吃蛇、推箱子、扫雷等。这些都是我编过的游戏下面附上代码。

type shuzu=array[1..20,1..20] of char;
var a:shuzu;s:string;b:array[1..1000]of point;i,j,f,fen:integer;
if a[p,q]='' then a[p,q]:='#' else ran2;
if a[p,q]='' then a[p,q]:=chr(2) else ran;
if a[i,j]=chr(2) then textcolor(12);

writeln('Score:',fen);
3:fillchar(a,sizeof(a),'');
a[1,i]:='#';a[i,1]:='#';
a[20,i]:='#';a[i,20]:='#';
a[2,2]:='o';a[2,3]:='o';a[2,4]:='?;
if(keypressed)and(not(c)) then
if(f=3)or(f=4) then begin f:=1;c:=true; end;
if(f=3)or(f=4) then begin f:=2;c:=true end;
if(f=1)or(f=2) then begin f:=3;c:=true end;
if(f=1)or(f=2) then begin f:=4;c:=true end;
writeln('Do you want to exit(Y/N)?');
if(s='Y')or(s='y') then halt;
until(s='N')or(s='n');
a[b[tail].x,b[tail].y]:='o';
if(a[b[tail].x-1,b[tail].y]='#')or
((a[b[tail].x-1,b[tail].y]='o')and(not((b[tail].x-1=b[head mod 1000+1].x)and(b[tail].y=b[head mod 1000+1].y)))) then goto 2;
if a[b[tail].x-1,b[tail].y]=chr(2) then
a[b[head].x,b[head].y]:='';
b[1].x:=b[1000].x-1;b[1].y:=b[1000].y;
b[tail].x:=b[tail-1].x-1;b[tail].y:=b[tail-1].y;
if(a[b[tail].x+1,b[tail].y]='#')or
((a[b[tail].x+1,b[tail].y]='o')and(not((b[tail].x+1=b[head mod 1000+1].x)and(b[tail].y=b[head mod 1000+1].y)))) then goto 2;
if a[b[tail].x+1,b[tail].y]=chr(2) then
a[b[head].x,b[head].y]:='';
b[1].x:=b[1000].x+1;b[1].y:=b[1000].y;
b[tail].x:=b[tail-1].x+1;b[tail].y:=b[tail-1].y;
if(a[b[tail].x,b[tail].y-1]='#')or
((a[b[tail].x,b[tail].y-1]='o')and(not((b[tail].x=b[head mod 1000+1].x)and(b[tail].y-1=b[head mod 1000+1].y)))) then goto 2;
if a[b[tail].x,b[tail].y-1]=chr(2) then
a[b[head].x,b[head].y]:='';
b[1].x:=b[1000].x;b[1].y:=b[1000].y-1;
b[tail].x:=b[tail-1].x;b[tail].y:=b[tail-1].y-1;
if(a[b[tail].x,b[tail].y+1]='#')or
((a[b[tail].x,b[tail].y+1]='o')and(not((b[tail].x=b[head mod 1000+1].x)and(b[tail].y+1=b[head mod 1000+1].y)))) then goto 2;
if a[b[tail].x,b[tail].y+1]=chr(2) then
a[b[head].x,b[head].y]:='';
b[1].x:=b[1000].x;b[1].y:=b[1000].y+1;
b[tail].x:=b[tail-1].x;b[tail].y:=b[tail-1].y+1;
a[b[tail].x,b[tail].y]:='?;
2:writeln('Game Over!Score:',fen);

writeln('Play again(Y/N)?');
if(s='Y')or(s='y') then goto 3;
if(s='N')or(s='n') then halt;
until(s='Y')or(s='y')or(s='N')or(s='n');
var f:text;n,p,q,i,j:integer;s1,s:string;
a:sz1;b:sz2;top:integer;ren:poi;
if a[b[i].x,b[i].y]<>'? then exit(false);
write('Please choose a unit(1~11):');
2:str(n,s1);s:='c:\map'+s1+'.in';
if(a[ren.x-1,ren.y]='')or(a[ren.x-1,ren.y]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
if a[ren.x-1,ren.y]=chr(233) then
if(a[ren.x-2,ren.y]='')or(a[ren.x-2,ren.y]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
a[ren.x-1,ren.y]:=chr(2);a[ren.x-2,ren.y]:=chr(233);
if(a[ren.x+1,ren.y]='')or(a[ren.x+1,ren.y]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
if a[ren.x+1,ren.y]=chr(233) then
if(a[ren.x+2,ren.y]='')or(a[ren.x+2,ren.y]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
a[ren.x+1,ren.y]:=chr(2);a[ren.x+2,ren.y]:=chr(233);
if(a[ren.x,ren.y-1]='')or(a[ren.x,ren.y-1]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
if a[ren.x,ren.y-1]=chr(233) then
if(a[ren.x,ren.y-2]='')or(a[ren.x,ren.y-2]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
a[ren.x,ren.y-1]:=chr(2);a[ren.x,ren.y-2]:=chr(233);
if(a[ren.x,ren.y+1]='')or(a[ren.x,ren.y+1]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
if a[ren.x,ren.y+1]=chr(233) then
if(a[ren.x,ren.y+2]='')or(a[ren.x,ren.y+2]='o') then
if dong(ren.x,ren.y,top,b) then a[ren.x,ren.y]:='o' else a[ren.x,ren.y]:='';
a[ren.x,ren.y+1]:=chr(2);a[ren.x,ren.y+2]:=chr(233);
write('Are you sure to exit(Y/N)?');

if(s1='y')or(s1='Y') then
if(s1<>'n')and(s1<>'N') then goto 4;
write('Congratulations!Play again(Y/N)?');
if(s1='y')or(s1='Y') then
if(s1='n')or(s1='N') then halt
write('Congratulations!Go to next unit(Y/N)?');
if(s1='y')or(s1='Y') then
if(s1='n')or(s1='N') then halt
type sz1=array[1..50,1..50]of char;
function dong(x,y,top:integer;var b:sz2):boolean;
procedure print(x:integer;var ren:poi;var a:sz1;var b:sz2;var top:integer);
procedure pr(x,y,top:integer;a:sz1;b:sz2);
function dong(x,y,top:integer;var b:sz2):boolean;
if(b[i].x=x)and(b[i].y=y) then exit(true);
procedure print(x:integer;var ren:poi;var a:sz1;var b:sz2;var top:integer);
if dong(i,j,top,b) then textcolor(12);
str(x,s1);s:='c:\map'+s1+'.in';
writeln(f,'######o#');
writeln(f,'########');
procedure pr(x,y,top:integer;a:sz1;b:sz2);
if dong(i,j,top,b) then textcolor(12);
var a,b:array[1..14,1..14]of char;i,j,t,t2,l:integer;s:string;
b[i,j]:='?;a[i,j]:='?;
i:=random(t)+1;j:=random(t)+1;
until(a[i,j]='?)and(not((i=1)and(j=1)));
if(i>1)and(j>1) then if a[i-1,j-1]='' then inc(nu);
if(i>1) then if a[i-1,j]='' then inc(nu);
if(i>1)and(j<t) then if a[i-1,j+1]='' then inc(nu);
if(j>1) then if a[i,j-1]='' then inc(nu);
if(j<t) then if a[i,j+1]='' then inc(nu);
if(i<t)and(j>1) then if a[i+1,j-1]='' then inc(nu);
if(i<t) then if a[i+1,j]='' then inc(nu);
if(i<t)and(j<t) then if a[i+1,j+1]='' then inc(nu);
if nu>0 then a[i,j]:=chr(ord('0')+nu);
if b[p,q]='' then textcolor(12);
if(p=i)and(q=j) then textcolor(8);
if b[x,y]<>'? then exit;
if(x>1)and(b[x-1,y]='?) then find(x-1,y);
if(y>1)and(b[x,y-1]='?) then find(x,y-1);
if(x<t)and(b[x+1,y]='?) then find(x+1,y);
if(y<t)and(b[x,y+1]='?) then find(x,y+1);
if(x>1)and(y>1)and(b[x-1,y-1]='?) then find(x-1,y-1);
if(x>1)and(y<t)and(b[x-1,y+1]='?) then find(x-1,y+1);
if(x<t)and(y>1)and(b[x+1,y-1]='?) then find(x+1,y-1);
if(x<t)and(y<t)and(b[x+1,y+1]='?) then find(x+1,y+1);
if b[p,q]='? then exit(false);
writeln('Please choose the level:');
writeln('1--easy 2--normal3--hard');
'1':begin t:=11;t2:=20; end;
'2':begin t:=12;t2:=30; end;
'3':begin t:=14;t2:=50; end;
#72:if i>1 then dec(i) else wrong;
#80:if i<t then inc(i) else wrong;
#75:if j>1 then dec(j) else wrong;
#77:if j<t then inc(j) else wrong;
writeln('Do you want to exit(Y/N)?');
if(s='Y')or(s='y') then halt;
until(s='n')or(s='N');
if b[i,j]='? then find(i,j);
if b[i,j]='' then begin print2;goto 2;end;
'k':if(l>0)and(b[i,j]='?) then begin b[i,j]:='';dec(l); end;
'l':if b[i,j]='' then begin b[i,j]:='?;inc(l); end;
writeln('Congratulations!Play once again(Y/N)?');
if(s='N')or(s='n') then halt;
if(s='Y')or(s='y') then goto 3;
2:writeln('Game Over!Play once again(Y/N)?');
if(s='N')or(s='n') then halt;
if(s='Y')or(s='y') then goto 3;
另外我又用c++编了一次贪吃蛇,也一起提供给你。
char a[22][42];bool f;short i,j,fa;short x[5],y[5];
point s[1001];short h,t,p,q;char st;
if(fa>=3){f=true;fa=1;return(0);}
if(GetKeyState(VK_DOWN)<0)
if(fa>=3){f=true;fa=2;return(0);}
if(GetKeyState(VK_LEFT)<0)
if(fa<=2){f=true;fa=3;return(0);}
if(GetKeyState(VK_RIGHT)<0)
if(fa<=2){f=true;fa=4;return(0);}
{cout<<"您真的要退出吗(Y/N)?";
if(st=='Y'|| st=='y') exit(0); else
if(st=='N'|| st=='n') break;
if(a[x][y]=='') a[x][y]='T';return(0);
cout<<"本程序由聊城一中09级12班张凯开发\n";
cout<<"版权所有,翻版必究\n";cout<<endl<<endl;
cout<<"游戏说明:\n";
cout<<"方向键控制方向,Esc退出\n";
for(i=0;i<=41;i++){a[0][i]='#';a[21][i]='#';}
for(i=1;i<=20;i++){a[i][0]='#';a[i][41]='#';}
a[1][1]='0';a[1][2]='0';a[1][3]='8';ran();
h=0;t=3;s[1].x=1;s[1].y=1;s[2].x=1;s[2].y=2;s[3].x=1;s[3].y=3;fa=4;
{for(j=0;j<=41;j++) cout<<a[i][j];
p=s[t].x+x[fa];q=s[t].y+y[fa];
if(a[p][q]=='#'||(a[p][q]=='0'&&!(p==s[h+1].x&& q==s[h+1].y))) goto l2;
a[s[t].x][s[t].y]='0';
{a[p][q]='8';t++;if(t==1001)t=1;s[t].x=p;s[t].y=q;ran();
{h++;if(h==1001) h=1;a[s[h].x][s[h].y]='';a[p][q]='8';
t++;if(t==1001) t=1;s[t].x=p;s[t].y=q;
cout<<"游戏结束!再玩一次吗(Y/N)?";
if(st=='Y'|| st=='y') goto sta; else
if(st=='N'|| st=='n') return(0);
本文由游戏攻略于2025-11-21发表在游戏攻略网,如有疑问,请联系我们。
本文链接:https://www.zhubei.net/post/6565.html












