主题:[原创]自制赛车游戏(模仿单色液晶屏)
uses
crt;
type
cartype=record
x,y:byte;
end;
var
map:array[1..10,1..200] of 0..1;
screen:byte;
car:cartype;
i,speed:byte;
procedure createscreen;
var
i,j:byte;
begin
window(35,5,44,24);
textbackground(yellow);
textcolor(blue);
for i:=1 to 20 do
for j:=1 to 10 do
begin
gotoxy(j,i);
write(' ');
end;
end;
procedure init;
var
fin:text;
i,j,n:byte;
x:char;
begin
assign(fin,'road.map');
reset(fin);
readln(fin,n);
for i:=n downto 1 do
begin
for j:=1 to 10 do
begin
read(fin,x);
if x='x' then map[j,i]:=1
else map[j,i]:=0;
end;
readln(fin);
end;
close(fin);
car.x:=5;
car.y:=5;
screen:=0;
end;
function crash:boolean;
begin
crash:=false;
if map[car.x,car.y]=1 then crash:=true;
if map[car.x-1,car.y-1]=1 then crash:=true;
if map[car.x-1,car.y-3]=1 then crash:=true;
if map[car.x+1,car.y-1]=1 then crash:=true;
if map[car.x+1,car.y-3]=1 then crash:=true;
end;
procedure goleft;
begin
if car.x>0 then car.x:=car.x-1;
end;
procedure goright;
begin
if car.x<10 then car.x:=car.x+1;
end;
procedure gogogo;
begin
car.y:=car.y+1;
screen:=screen+1;
end;
procedure print;
var
i,j:byte;
begin
for i:=1 to 20 do
for j:=1 to 10 do
begin
gotoxy(j,21-i);
if map[j,screen+i]=1 then write(#219)
else write(' ');
end;
{print car}
for i:=15 to 18 do
begin
textcolor(red);
gotoxy(car.x,i);
write(#219);
end;
gotoxy(car.x-1,16);
write(#219);
gotoxy(car.x-1,18);
write(#219);
gotoxy(car.x+1,16);
write(#219);
gotoxy(car.x+1,18);
write(#219);
textcolor(blue);
{print information}
textbackground(blue);
textcolor(white);
gotoxy(1,1);
delline;
write('speed:',speed);
textbackground(yellow);
textcolor(blue);
end;
procedure playmusic(s:string);
var
i:byte;
begin
for i:=1 to length(s) do
begin
case s[i] of
'a':sound(264);
's':sound(297);
'd':sound(330);
'f':sound(352);
'j':sound(396);
'k':sound(440);
'l':sound(495);
';':sound(528);
'.':nosound;
end;
delay(100);
end;
nosound;
end;
{main program}
begin
for speed:=1 to 10 do
begin
createscreen;
init;
print;
playmusic('aaddjjddjj;;;;;;.......aaaaaa.....aaaaaa.....aaaaaa.....;;;;;;;;;..');
sound(100);
repeat
if keypressed then
begin
case upcase(readkey) of
'A':goleft;
'D':goright;
'Q':halt;
end;
print;
end
else
begin
gogogo;
print;
delay(400-speed*20);
end;
if crash then
begin
textbackground(blue);
textcolor(yellow);
gotoxy(1,10);
write('game over!');
sound(200);
delay(1000);
nosound;
delay(10000);
halt;
textbackground(yellow);
textcolor(blue);
end;
until car.y>=120;
playmusic('aaadddjjjjjjkkkjjj');
nosound;
delay(5000);
end;
nosound;
delay(10000);
end.