回 帖 发 新 帖 刷新版面

主题:[原创]自制赛车游戏(模仿单色液晶屏)

program race;
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.

回复列表 (共31个回复)

11 楼

12 楼

还不错。

13 楼

有创意呀!
I like racing!

14 楼


请问用PASCAL,怎么复制你打的程序呀?难道要自己打吗?我是新手告诉我下谢谢!

15 楼

为什么运行不了:
ERROR 200:Division by zero.

16 楼

你肯定用的TP编译的吧!
TP有BUG,如果你的CPU主频过高使用CRT单元时就会报错说除数为0,所以建议使用FP编译.或者找补丁把TP的BUG补上

17 楼

你这是转帖还是原创啊?我曾经见过!

18 楼

绝对原创,因为我在其它帖中连接过这个所以看见过也很正常

而且这个游戏也不是我发明的,很早就有了,我只是用了我自己的实现方法而已

19 楼

我怎么运行不了?

20 楼

要用FP编译,或者将TP的漏洞补上,还有一楼的那个东西需要按要求复制进一个文件

我来回复

您尚未登录,请登录后再回复。点此登录或注册