首页 > 代码库 > Pascal小游戏 不要消灭星星
Pascal小游戏 不要消灭星星
不要消灭星星 Pascal小游戏 Chaobs改编自pascal吧
控制台小游戏嘛,就当是练习一下结构化的写法。
program wxtw;
uses crt;
type
zbdy=record
x,y:integer; end;
var n,i,x,y,t,sjs:integer; ml:char;
zb: array [1..12] of zbdy;
begin
randomize;
sjs:=random(3);
zb[1].x:=15; zb[1].y:=15;
clrscr;
gotoxy(zb[1].x,zb[1].y);
write(‘☆‘);
delay(100);
zb[2].x:=1; zb[2].y:=20;
gotoxy(zb[2].x,zb[2].y);
write(‘◎‘);
zb[10].x:=18; zb[10].y:=20;
gotoxy(zb[10].x,zb[10].y);
write(‘◎‘);
zb[11].x:=36; zb[11].y:=20;
gotoxy(zb[11].x,zb[11].y);
write(‘◎‘);
zb[12].x:=53; zb[12].y:=20;
gotoxy(zb[12].x,zb[12].y);
write(‘◎‘);
zb[3].x:=1; zb[3].y:=5;
gotoxy(zb[3].x,zb[3].y);
write(‘◎‘);
zb[4].x:=18; zb[4].y:=5;
gotoxy(zb[4].x,zb[4].y);
write(‘◎‘);
zb[5].x:=36; zb[5].y:=5;
gotoxy(zb[5].x,zb[5].y);
write(‘◎‘);
zb[6].x:=53; zb[6].y:=5;
gotoxy(zb[6].x,zb[6].y);
write(‘◎‘);
zb[7].x:=1+sjs; zb[7].y:=1+sjs;
gotoxy(zb[7].x,zb[7].y);
write(‘△‘);
zb[8].x:=40+sjs; zb[8].y:=10+sjs;
gotoxy(zb[8].x,zb[8].y);
write(‘△‘);
zb[9].x:=1+sjs; zb[9].y:=20+sjs;
gotoxy(zb[9].x,zb[9].y);
write(‘△‘);
gotoxy(zb[1].x+8,zb[1].y-2);
write(‘不要消灭星星‘);
gotoxy(zb[1].x+3,zb[1].y-1);
write(‘回车键开始游戏 Chaos荣誉出品 For Games by Gamers!‘);
gotoxy(zb[1].x+3,zb[1].y);
write(‘操作 上:I 下:K 左:J 右:L ‘);
gotoxy(zb[1].x+3,zb[1].y+1);
write(‘注意:碰到边框将会结束!!!‘);
readln;
repeat
if keypressed=true then begin
ml:=readkey;
case ml of
‘i‘: begin
zb[1].y:=zb[1].y-1;
clrscr;
gotoxy(zb[1].x,zb[1].y);write(‘☆‘);
end;
‘k‘: begin
zb[1].y:=zb[1].y+1;
clrscr;
gotoxy(zb[1].x,zb[1].y);
write(‘☆‘);
end;
‘j‘ :begin
zb[1].x:=zb[1].x-1;
clrscr;
gotoxy(zb[1].x,zb[1].y);
write(‘☆‘);
end;
‘l‘ :begin
zb[1].x:=zb[1].x+1;
clrscr;
gotoxy(zb[1].x,zb[1].y);
write(‘☆‘);
end; end; end else begin
clrscr;
if zb[2].x<=70 then
zb[2].x:=zb[2].x+1 else zb[2].x:=1;
gotoxy(zb[2].x,zb[2].y);
write(‘◎‘);
if zb[3].x<=70 then
zb[3].x:=zb[3].x+1 else zb[3].x:=1;
gotoxy(zb[3].x,zb[3].y);
write(‘◎‘);
if zb[4].x<=70 then
zb[4].x:=zb[4].x+1 else zb[4].x:=1;
gotoxy(zb[4].x,zb[4].y);
write(‘◎‘);
if zb[5].x<=70 then
zb[5].x:=zb[5].x+1 else zb[5].x:=1;
gotoxy(zb[5].x,zb[5].y);
write(‘◎‘);
if zb[6].x<=70 then
zb[6].x:=zb[6].x+1 else zb[6].x:=1;
gotoxy(zb[6].x,zb[6].y);
write(‘◎‘);
if zb[10].x<=70 then
zb[10].x:=zb[10].x+1 else zb[10].x:=1;
gotoxy(zb[10].x,zb[10].y);
write(‘◎‘);
if zb[11].x<=70 then
zb[11].x:=zb[11].x+1 else zb[11].x:=1;
gotoxy(zb[11].x,zb[11].y);
write(‘◎‘);
if zb[12].x<=70 then
zb[12].x:=zb[12].x+1 else zb[12].x:=1;
gotoxy(zb[12].x,zb[12].y);
write(‘◎‘);
gotoxy(zb[1].x,zb[1].y);
write(‘☆‘);
sjs:=random(11); if sjs=2 then begin
if zb[7].x<zb[1].x then zb[7].x:=zb[7].x+1;
if zb[7].x>zb[1].x then zb[7].x:=zb[7].x-1;
if zb[7].y<zb[1].y then zb[7].y:=zb[7].y+1;
if zb[7].y>zb[1].y then zb[7].y:=zb[7].y-1;
gotoxy(zb[7].x,zb[7].y);
if ((zb[8].x=zb[7].x)) and ((zb[8].y=zb[7].y)) or ((zb[9].x=zb[8].x) and (zb[9].y=zb[8].y)) or ((zb[7].x=zb[9].x) and (zb[7].y=zb[9].y))
then gotoxy(zb[7].x-1,zb[7].y-1);
write(‘△‘); end else begin gotoxy(zb[7].x,zb[7].y);
write(‘△‘); end;
sjs:=random(11); if sjs=0 then begin
if zb[8].x<zb[1].x then zb[8].x:=zb[8].x+1;
if zb[8].x>zb[1].x then zb[8].x:=zb[8].x-1;
if zb[8].y<zb[1].y then zb[8].y:=zb[8].y+1;
if zb[8].y>zb[1].y then zb[8].y:=zb[8].y-1;
gotoxy(zb[8].x,zb[8].y);
if ((zb[8].x=zb[7].x)) and ((zb[8].y=zb[7].y)) or ((zb[9].x=zb[8].x) and (zb[9].y=zb[8].y)) or ((zb[7].x=zb[9].x) and (zb[7].y=zb[9].y))
then gotoxy(zb[8].x-1,zb[8].y-1);
write(‘△‘); end else begin gotoxy(zb[8].x,zb[8].y);
write(‘△‘); end;
sjs:=random(11); if sjs=5 then begin
if zb[9].x<zb[1].x then zb[9].x:=zb[9].x+1;
if zb[9].x>zb[1].x then zb[9].x:=zb[9].x-1;
if zb[9].y<zb[1].y then zb[9].y:=zb[9].y+1;
if zb[9].y>zb[1].y then zb[9].y:=zb[9].y-1;
gotoxy(zb[9].x,zb[9].y);
if ((zb[8].x=zb[7].x)) and ((zb[8].y=zb[7].y)) or ((zb[9].x=zb[8].x) and (zb[9].y=zb[8].y)) or ((zb[7].x=zb[9].x) and (zb[7].y=zb[9].y))
then gotoxy(zb[9].x-1,zb[9].y-1);
write(‘△‘); end else begin gotoxy(zb[9].x,zb[9].y);
write(‘△‘); end;
for i:=2 to 12 do if (zb[1].x=zb[i].x) and (zb[1].y=zb[i].y) then begin
clrscr;
writeln(‘逃亡失败!回车键退出‘);
readln;
halt; end;
delay(20); end;
until ml=‘q‘;
end.