Tin học Game Đua xe viết bằng Pascal

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

Code đây nha :
Mã:
 Program Duaxe;
 uses crt,dos;
 const
      width = 35;
      high = 24;
      Soduong = 12;
      tgchay = 100;
      Soxe = 5;

      Up = #72;
      Down = #80;
      Left = #75;
      Right = #77;
      Boom = #32;
      ESC = #27;
      PauseS = 'd';
      PauseB = 'D';

      V_Life = 3;
      V_Clear = 1;
      V_Money = 2;
      V_Bom = 0;

      SoItem = 5;
      Items : array[1..SoItem] of string =
      ('    New Game    ','    Continue    ','      Help      ',
      '     Sound:     ','      Quit      ');

 type Xe = object
      x,y: integer;
      mau,maucabin: Word;
      tgxe: longint;
 Procedure InXe;
 Procedure XoaXe;
 Procedure DiChuyen(k: char);
           end;
 type Vatpham = object
      x,y: integer;
      name: integer;
      tgvp: integer;
 Procedure InVatpham;
 Procedure XoaVatpham;
 Procedure Dichuyen;
                end;

 var XeC: xe;
     k: char;
     duong,tgduong: longint;
     XeD: array[1..soxe] of xe;
     VP: array[1..Soxe] of Vatpham;
     Tainguyen: array[0..3] of integer;
     Chet,Onsound: Boolean;
     Diem: longint;

 procedure setcusor(bot,top: byte);
 var regs : registers;
 begin
 regs.ah :=1;
 regs.ch:=bot;
 regs.cl:=top;
 intr($10,regs);
 end;

 Procedure Psound(f,t: longint);
 Begin
      if OnSound then begin Sound(f);delay(t);nosound;end;
 End;

 Procedure DuongDi;
 var i,kduong: integer;
 Begin
      if duong = 1 then kduong := 0 else kduong := 1;
      for i := 1 to soduong do
      begin
           Textcolor(white);
           gotoxy(width div 2 + 1,i*2-duong);
           write('Û');
           gotoxy(width div 2 + 1,i*2-kduong);
           write(' ');
      end;
      if duong = 1 then duong:= 0 else duong := 1;
 End;

 Procedure InManHinh;
 var i,j: integer;
 Begin
      textbackground(green);
      for i := 1 to width do
      for j := 1 to high do
          begin gotoxy(i,j); write(' '); end;
      textbackground(black);
      gotoxy((width - 20) div 2,high+1);
      TextColor(Red);
      write('R A C I N G   ');
      TextColor(Brown);
      Write('G A M E');
      textbackground(green);
 End;

 Function XeDVaCham(i: integer): Boolean;
 var j: integer;
 Begin
      XeDVacham := False;
      for j := 1 to SoXe do
      begin
           if i <> j then
           if ((XeD[i].X >= XeD[j].X) and (XeD[i].X <= XeD[j].X+3))
           or ((XeD[j].X >= XeD[i].X) and (XeD[j].X <= XeD[i].X+3)) then
           XeDVaCham := True;
           if (XeD[i].X <= width div 2 +1) and (XeD[i].X+3 >= width div 2 +1)
           then XeDVaCham := True;
      end;
 End;

 Procedure TaoXeDich(i: integer);
 Begin
      repeat
            XeD[i].X := 1 + Random(width - 6);
      until not XeDVaCham(i);
      XeD[i].Y := 2;
      XeD[i].Mau := 3 + random(7);
      XeD[i].tgxe := 0;
      repeat
            XeD[i].MauCabin := 3 + Random(7);
      until XeD[i].Mau <> XeD[i].MauCabin;
      XeD[i].InXe;
 End;

 Procedure TaoVatpham(i: integer);
 Begin
      VP[i].X := 1 + Random(width - 6);
      VP[i].Y := 1 + Random(10);
      VP[i].Name := random(16) div 5;
      VP[i].InVatPham;
 End;

 Procedure Clear;
 var i: integer;
 Begin
      for i := 1 to Soxe do
          if ((XeD[i].X >= XeC.X) and (XeD[i].X <=XeC.X+3))
          or ((XeD[i].X+3 <= XeC.X+3) and (XeD[i].X+3 >=XeC.X))
          then begin XeD[i].XoaXe;TaoXeDich(i);end;
 End;

 Procedure Xe.InXe;
 Begin
      textcolor(Mau);
      gotoxy(x,y);  write(' ÛÛ ');
      gotoxy(x,y+1);write('Þ  Ý');
      gotoxy(x,y+2);write(' ÛÛ ');
      Textcolor(White);
      gotoxy(x,y);write('0');
      gotoxy(x+3,y);write('0');
      gotoxy(x,y+2);write('0');
      gotoxy(x+3,y+2);write('0');
      Textcolor(Maucabin);
      gotoxy(x+1,y+1);write('ÛÛ');
 End;

 Procedure Xe.XoaXe;
 Begin
      Gotoxy(x,y);  write('    ');
      Gotoxy(x,y+1);write('    ');
      Gotoxy(x,y+2);write('    ');
 End;

 Procedure Xe.DiChuyen(k: char);
 Begin
      XoaXe;
      case k of
           Down: if y < high - 2 then Inc(y);
           Up: if y > 1 then Dec(y);
           Left: if x > 1 then Dec(x);
           Right: if x < width - 3 then Inc(x);
           Boom: if TaiNguyen[V_Clear] > 0 then
                 begin Clear;Dec(Tainguyen[V_Clear]);end;
      end;
      InXe;
 End;

 Procedure Vatpham.InVatpham;
 Begin
      gotoxy(x,y);
      case name of
      V_Life: begin textcolor(red);write(#3);end;
      V_Clear: begin textcolor(Cyan);write(#15);end;
      V_Money: begin textcolor(Yellow);write('@');end;
      V_Bom: begin textcolor(Black);write('ê');end;
                end;
 End;

 Procedure Vatpham.XoaVatpham;
 Begin
      gotoxy(x,y);write(' ');
 End;

 Procedure Vatpham.DiChuyen;
 Begin
      XoaVatpham;
      inc(Y);
      InVatPham;
 End;

 Procedure XedichChay;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      begin
           inc(XeD[i].tgxe);
           if XeD[i].tgxe >= TgChay+i*10 then
           begin
                XeD[i].Dichuyen(Down);
                XeD[i].TgXe := 0;
           end;
           if XeD[i].Y >= high - 2 then
           begin XeD[i].XoaXe;TaoXeDich(i);end;
      end;
 End;

 Procedure VatPhamChay;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      begin
           inc(VP[i].tgvp);
           if VP[i].tgvp >= TgChay then
           begin
                VP[i].Dichuyen;
                VP[i].Tgvp := 0;
           end;
           if VP[i].Y >= high then
           begin VP[i].XoaVatPham;TaoVatPham(i);end;
      end;
 End;

 Procedure AnVatPham;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      if (VP[i].X >= XeC.X) and (VP[i].X <= XeC.X+3)
      and (VP[i].Y >= XeC.Y) and (VP[i].Y <= XeC.Y + 2) then
      begin
           if VP[i].Name <> V_Bom then
           begin
                Psound(1000,50);
                Inc(Tainguyen[VP[i].Name]);
                VP[i].XoaVatPham;
                TaoVatPham(i);
           end
           else begin
                     PSound(350,150);Chet := True;
                end;
      end;
 End;

 Procedure KhoiTao;
 var i: integer;
 Begin
      Randomize;
      xeC.X := width div 2 - 1;
      XeC.y := high - 5;
      XeC.Mau := Blue;
      XeC.Maucabin := Yellow;
      duong := 0;
      tgduong := 0;
      Chet := False;
      for i := 1 to Soxe do
      begin
           TaoXeDich(i);
           TaoVatpham(i);
      end;
 End;

 Procedure VaCham;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      if (((XeD[i].X >= XeC.X) and (XeD[i].X <= XeC.X+3))
      or ((XeD[i].X+3 <= XeC.X+3) and (XeD[i].X+3 >= XeC.X)))
      and (((XeD[i].Y >= XeC.Y) and (XeD[i].Y <= XeC.Y+2))
      or ((XeD[i].Y+2 <= XeC.Y+2) and (XeD[i].Y+2 >= XeC.Y))) then
      begin
           Chet := True;
           Psound(350,150);
           break;
      end;
 End;

 Procedure NewGame;
 Begin
      TextBackGround(Black);
      SetCusor(32,0);
      clrscr;
      KhoiTao;
      TaiNguyen[V_Life] := 1;
      TaiNguyen[V_Clear] := 3;
      TaiNguyen[V_Money] := 0;
      Diem := 0;
 End;

 Procedure InGiupDo;
 Begin
      TextBackground(lightgreen);
      clrscr;
      TextColor(White);
      Writeln(#24,': Up');
      Writeln(#25,': Down');
      Writeln(#26,': Right');
      Writeln(#27,': Left');
      Writeln('Space: Clear In Line');
      writeln('D: Pause Game and Continue Game');
      Textcolor(Red);
      Writeln(#3,': Life');
      Textcolor(Blue);
      Writeln(#15,': Bullet');
      TextColor(Yellow);
      Writeln('@: Money');
      Textcolor(Black);
      Writeln(#234,': Bom');
      Textcolor(Red+Blink);
      Writeln('Press ESC to back Menu...');
      repeat
      until readkey = ESC;
      TextBackground(black);
      clrscr;
 End;

 Procedure SetSound;
 Begin
      Textbackground(black);clrscr;
      repeat
            Textcolor(White);
            gotoxy(1,1);
            Write('Sound: ');
            if onsound then write('on ') else write('off');
            TextColor(Cyan);
            gotoxy(1,2);write('Press Enter to change sound!');
            Textcolor(Brown+Blink);
            Gotoxy(1,3);write('Press ESC to back Menu...');
            k := #0;
            if keypressed then k := readkey;
            if k = #13 then
                  if onsound then onsound := false else onsound := true;
      until k = ESC;

 End;

 Procedure InThongTin;
 Begin
      TextBackGround(Black);
      Gotoxy(Width+15,2);
      TextColor(Red+Blink);
      Write(' R A C I N G ');
      TextColor(Brown+Blink);
      Write(' G A M E ');

      TextBackGround(Cyan);
      TextColor(Black);
      Gotoxy(Width + 10,5);Write('Score: ',diem,'  ');
      TextColor(Red);
      Gotoxy(Width + 10,7);Write('Life: ',Tainguyen[V_Life],'  ');
      TextColor(Blue);
      Gotoxy(Width + 10,9);Write('Bullet: ',TaiNguyen[V_Clear],'  ');
      TextColor(Yellow);
      Gotoxy(Width + 10,11);Write('Money: ',Tainguyen[V_Money],'  ');
      TextColor(White);
      TextBackground(Black);
      Gotoxy(Width + 10,17);Write('Game made by Tra Nguyen Huu Nghia');
      Gotoxy(Width + 10,18);Write('Fb: fb.com/nghia.lvc');
      TextBackground(Green);
 End;

 Procedure GameOver;
 var i: integer;
 Begin
      for i := 1 to 60 do
      begin
           gotoxy(1,12);clreol;
           TextBackGround(Cyan);
           TextColor(Red);
           gotoxy(i,12);write('G A M E  O V E R');
           Psound(i*10,50);
           delay(25);
      end;
      for i := 60 downto 30 do
      begin
           gotoxy(1,12);clreol;
           TextBackGround(Cyan);
           TextColor(Red);
           gotoxy(i,12);write('G A M E  O V E R');
           Psound((60-i)*10,50);
           delay(25);
      end;
      TextColor(Red+Blink);
      gotoxy(i,12);write('G A M E  O V E R');
      Delay(2000);
 End;

 Procedure Main;
 var i: integer;
 Begin
      TextBackground(Black);
      clrscr;
      InManHinh;
      XeC.InXe;
      repeat
            InThongTin;
            if keypressed then
            begin
                 k := readkey;
                 if (k = PauseS) or (k = PauseB) then
                 repeat
                       k := #0;
                       if keypressed then k := readkey;
                 until (k=PauseS) or (k=PauseB) or (k = ESC);
                 Xec.Dichuyen(k);
            end;
            inc(tgduong);
            XedichChay;
            VatPhamChay;
            AnVatPham;
            VaCham;
            if chet then
            begin
                 Dec(TaiNguyen[V_Life]);
                 Chet := False;
                 KhoiTao;
                 InManHinh;
                 XeC.InXe;
            end;
            if tgduong >= Tgchay then
            begin
                 duongdi;
                 Inc(Diem);
                 tgduong := 0;
            end;
      until (k = ESC) or (TaiNguyen[V_Life] < 0) ;
      if k <> ESC then Gameover;
 End;

 Procedure Menu;
 var x0,y0,y,i: integer;
 Begin
      y0 := 8;
      x0 := 30;
      y := 1;
      onsound := true;
      repeat
      TextBackground(black);
      SetCusor(32,0);
      clrscr;
      Gotoxy(X0-3,Y0-2);
      TextColor(Red+Blink);
      TextBackGround(Cyan);
      Write(' R A C I N G ');
      TextColor(Cyan+Blink);
      TextBackground(Red);
      Write(' G A M E ');

      Gotoxy(X0+4,Y0);
      TextColor(Yellow);
      TextBackground(Green);
      Write(' M E N U ');
      repeat
      k := #0;
      if keypressed then k := readkey;
      case k of
      Up: if y > 1 then begin Dec(y);PSound(1000,50);end;
      Down: if y < Soitem then begin Inc(y);PSound(1000,50);end;
             end;
      for i := 1 to soItem do
      begin
           Gotoxy(X0,Y0+i*2);
           TextColor(Black);
           if i = y then TextBackground(Brown) else TextBackground(LightGray);
           Write(Items[i]);
      end;
      until (k = #13);
      TextBackground(Black);
      case y of
      1: begin NewGame;Main;end;
      2: if not chet then Main;
      3: InGiupDo;
      4: SetSound;
      5: chet := True;
             end;
      until chet;
 End;

 BEGIN
      NewGame;
      Menu;
 END.
Code Game này cũng khá dễ, bạn nào muốn có thể thay đổi cả Menu cũng được
Game này cực kỳ đẹp luôn nha, Demo cái Menu là biết liền à :D:
upload_2019-2-12_14-21-54.png
 

Lê Quang Đông

Banned
Banned
Thành viên
10 Tháng mười 2018
771
1,039
161
Đồng Tháp
trường TRUNG HỌC CƠ SỞ THANH BÌNH
upload_2019-2-21_18-35-16.png
Thú vị thật anh ạ!
Nhưng chơi ròi chả biết cách thoát!
 

Dương Nhạt Nhẽo

Học sinh tiêu biểu
Thành viên
7 Tháng tám 2018
2,945
7,443
621
18
Lào Cai
Trường THPT số 1 Lào Cai
Code đây nha :
Mã:
 Program Duaxe;
 uses crt,dos;
 const
      width = 35;
      high = 24;
      Soduong = 12;
      tgchay = 100;
      Soxe = 5;

      Up = #72;
      Down = #80;
      Left = #75;
      Right = #77;
      Boom = #32;
      ESC = #27;
      PauseS = 'd';
      PauseB = 'D';

      V_Life = 3;
      V_Clear = 1;
      V_Money = 2;
      V_Bom = 0;

      SoItem = 5;
      Items : array[1..SoItem] of string =
      ('    New Game    ','    Continue    ','      Help      ',
      '     Sound:     ','      Quit      ');

 type Xe = object
      x,y: integer;
      mau,maucabin: Word;
      tgxe: longint;
 Procedure InXe;
 Procedure XoaXe;
 Procedure DiChuyen(k: char);
           end;
 type Vatpham = object
      x,y: integer;
      name: integer;
      tgvp: integer;
 Procedure InVatpham;
 Procedure XoaVatpham;
 Procedure Dichuyen;
                end;

 var XeC: xe;
     k: char;
     duong,tgduong: longint;
     XeD: array[1..soxe] of xe;
     VP: array[1..Soxe] of Vatpham;
     Tainguyen: array[0..3] of integer;
     Chet,Onsound: Boolean;
     Diem: longint;

 procedure setcusor(bot,top: byte);
 var regs : registers;
 begin
 regs.ah :=1;
 regs.ch:=bot;
 regs.cl:=top;
 intr($10,regs);
 end;

 Procedure Psound(f,t: longint);
 Begin
      if OnSound then begin Sound(f);delay(t);nosound;end;
 End;

 Procedure DuongDi;
 var i,kduong: integer;
 Begin
      if duong = 1 then kduong := 0 else kduong := 1;
      for i := 1 to soduong do
      begin
           Textcolor(white);
           gotoxy(width div 2 + 1,i*2-duong);
           write('Û');
           gotoxy(width div 2 + 1,i*2-kduong);
           write(' ');
      end;
      if duong = 1 then duong:= 0 else duong := 1;
 End;

 Procedure InManHinh;
 var i,j: integer;
 Begin
      textbackground(green);
      for i := 1 to width do
      for j := 1 to high do
          begin gotoxy(i,j); write(' '); end;
      textbackground(black);
      gotoxy((width - 20) div 2,high+1);
      TextColor(Red);
      write('R A C I N G   ');
      TextColor(Brown);
      Write('G A M E');
      textbackground(green);
 End;

 Function XeDVaCham(i: integer): Boolean;
 var j: integer;
 Begin
      XeDVacham := False;
      for j := 1 to SoXe do
      begin
           if i <> j then
           if ((XeD[i].X >= XeD[j].X) and (XeD[i].X <= XeD[j].X+3))
           or ((XeD[j].X >= XeD[i].X) and (XeD[j].X <= XeD[i].X+3)) then
           XeDVaCham := True;
           if (XeD[i].X <= width div 2 +1) and (XeD[i].X+3 >= width div 2 +1)
           then XeDVaCham := True;
      end;
 End;

 Procedure TaoXeDich(i: integer);
 Begin
      repeat
            XeD[i].X := 1 + Random(width - 6);
      until not XeDVaCham(i);
      XeD[i].Y := 2;
      XeD[i].Mau := 3 + random(7);
      XeD[i].tgxe := 0;
      repeat
            XeD[i].MauCabin := 3 + Random(7);
      until XeD[i].Mau <> XeD[i].MauCabin;
      XeD[i].InXe;
 End;

 Procedure TaoVatpham(i: integer);
 Begin
      VP[i].X := 1 + Random(width - 6);
      VP[i].Y := 1 + Random(10);
      VP[i].Name := random(16) div 5;
      VP[i].InVatPham;
 End;

 Procedure Clear;
 var i: integer;
 Begin
      for i := 1 to Soxe do
          if ((XeD[i].X >= XeC.X) and (XeD[i].X <=XeC.X+3))
          or ((XeD[i].X+3 <= XeC.X+3) and (XeD[i].X+3 >=XeC.X))
          then begin XeD[i].XoaXe;TaoXeDich(i);end;
 End;

 Procedure Xe.InXe;
 Begin
      textcolor(Mau);
      gotoxy(x,y);  write(' ÛÛ ');
      gotoxy(x,y+1);write('Þ  Ý');
      gotoxy(x,y+2);write(' ÛÛ ');
      Textcolor(White);
      gotoxy(x,y);write('0');
      gotoxy(x+3,y);write('0');
      gotoxy(x,y+2);write('0');
      gotoxy(x+3,y+2);write('0');
      Textcolor(Maucabin);
      gotoxy(x+1,y+1);write('ÛÛ');
 End;

 Procedure Xe.XoaXe;
 Begin
      Gotoxy(x,y);  write('    ');
      Gotoxy(x,y+1);write('    ');
      Gotoxy(x,y+2);write('    ');
 End;

 Procedure Xe.DiChuyen(k: char);
 Begin
      XoaXe;
      case k of
           Down: if y < high - 2 then Inc(y);
           Up: if y > 1 then Dec(y);
           Left: if x > 1 then Dec(x);
           Right: if x < width - 3 then Inc(x);
           Boom: if TaiNguyen[V_Clear] > 0 then
                 begin Clear;Dec(Tainguyen[V_Clear]);end;
      end;
      InXe;
 End;

 Procedure Vatpham.InVatpham;
 Begin
      gotoxy(x,y);
      case name of
      V_Life: begin textcolor(red);write(#3);end;
      V_Clear: begin textcolor(Cyan);write(#15);end;
      V_Money: begin textcolor(Yellow);write('@');end;
      V_Bom: begin textcolor(Black);write('ê');end;
                end;
 End;

 Procedure Vatpham.XoaVatpham;
 Begin
      gotoxy(x,y);write(' ');
 End;

 Procedure Vatpham.DiChuyen;
 Begin
      XoaVatpham;
      inc(Y);
      InVatPham;
 End;

 Procedure XedichChay;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      begin
           inc(XeD[i].tgxe);
           if XeD[i].tgxe >= TgChay+i*10 then
           begin
                XeD[i].Dichuyen(Down);
                XeD[i].TgXe := 0;
           end;
           if XeD[i].Y >= high - 2 then
           begin XeD[i].XoaXe;TaoXeDich(i);end;
      end;
 End;

 Procedure VatPhamChay;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      begin
           inc(VP[i].tgvp);
           if VP[i].tgvp >= TgChay then
           begin
                VP[i].Dichuyen;
                VP[i].Tgvp := 0;
           end;
           if VP[i].Y >= high then
           begin VP[i].XoaVatPham;TaoVatPham(i);end;
      end;
 End;

 Procedure AnVatPham;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      if (VP[i].X >= XeC.X) and (VP[i].X <= XeC.X+3)
      and (VP[i].Y >= XeC.Y) and (VP[i].Y <= XeC.Y + 2) then
      begin
           if VP[i].Name <> V_Bom then
           begin
                Psound(1000,50);
                Inc(Tainguyen[VP[i].Name]);
                VP[i].XoaVatPham;
                TaoVatPham(i);
           end
           else begin
                     PSound(350,150);Chet := True;
                end;
      end;
 End;

 Procedure KhoiTao;
 var i: integer;
 Begin
      Randomize;
      xeC.X := width div 2 - 1;
      XeC.y := high - 5;
      XeC.Mau := Blue;
      XeC.Maucabin := Yellow;
      duong := 0;
      tgduong := 0;
      Chet := False;
      for i := 1 to Soxe do
      begin
           TaoXeDich(i);
           TaoVatpham(i);
      end;
 End;

 Procedure VaCham;
 var i: integer;
 Begin
      for i := 1 to Soxe do
      if (((XeD[i].X >= XeC.X) and (XeD[i].X <= XeC.X+3))
      or ((XeD[i].X+3 <= XeC.X+3) and (XeD[i].X+3 >= XeC.X)))
      and (((XeD[i].Y >= XeC.Y) and (XeD[i].Y <= XeC.Y+2))
      or ((XeD[i].Y+2 <= XeC.Y+2) and (XeD[i].Y+2 >= XeC.Y))) then
      begin
           Chet := True;
           Psound(350,150);
           break;
      end;
 End;

 Procedure NewGame;
 Begin
      TextBackGround(Black);
      SetCusor(32,0);
      clrscr;
      KhoiTao;
      TaiNguyen[V_Life] := 1;
      TaiNguyen[V_Clear] := 3;
      TaiNguyen[V_Money] := 0;
      Diem := 0;
 End;

 Procedure InGiupDo;
 Begin
      TextBackground(lightgreen);
      clrscr;
      TextColor(White);
      Writeln(#24,': Up');
      Writeln(#25,': Down');
      Writeln(#26,': Right');
      Writeln(#27,': Left');
      Writeln('Space: Clear In Line');
      writeln('D: Pause Game and Continue Game');
      Textcolor(Red);
      Writeln(#3,': Life');
      Textcolor(Blue);
      Writeln(#15,': Bullet');
      TextColor(Yellow);
      Writeln('@: Money');
      Textcolor(Black);
      Writeln(#234,': Bom');
      Textcolor(Red+Blink);
      Writeln('Press ESC to back Menu...');
      repeat
      until readkey = ESC;
      TextBackground(black);
      clrscr;
 End;

 Procedure SetSound;
 Begin
      Textbackground(black);clrscr;
      repeat
            Textcolor(White);
            gotoxy(1,1);
            Write('Sound: ');
            if onsound then write('on ') else write('off');
            TextColor(Cyan);
            gotoxy(1,2);write('Press Enter to change sound!');
            Textcolor(Brown+Blink);
            Gotoxy(1,3);write('Press ESC to back Menu...');
            k := #0;
            if keypressed then k := readkey;
            if k = #13 then
                  if onsound then onsound := false else onsound := true;
      until k = ESC;

 End;

 Procedure InThongTin;
 Begin
      TextBackGround(Black);
      Gotoxy(Width+15,2);
      TextColor(Red+Blink);
      Write(' R A C I N G ');
      TextColor(Brown+Blink);
      Write(' G A M E ');

      TextBackGround(Cyan);
      TextColor(Black);
      Gotoxy(Width + 10,5);Write('Score: ',diem,'  ');
      TextColor(Red);
      Gotoxy(Width + 10,7);Write('Life: ',Tainguyen[V_Life],'  ');
      TextColor(Blue);
      Gotoxy(Width + 10,9);Write('Bullet: ',TaiNguyen[V_Clear],'  ');
      TextColor(Yellow);
      Gotoxy(Width + 10,11);Write('Money: ',Tainguyen[V_Money],'  ');
      TextColor(White);
      TextBackground(Black);
      Gotoxy(Width + 10,17);Write('Game made by Tra Nguyen Huu Nghia');
      Gotoxy(Width + 10,18);Write('Fb: fb.com/nghia.lvc');
      TextBackground(Green);
 End;

 Procedure GameOver;
 var i: integer;
 Begin
      for i := 1 to 60 do
      begin
           gotoxy(1,12);clreol;
           TextBackGround(Cyan);
           TextColor(Red);
           gotoxy(i,12);write('G A M E  O V E R');
           Psound(i*10,50);
           delay(25);
      end;
      for i := 60 downto 30 do
      begin
           gotoxy(1,12);clreol;
           TextBackGround(Cyan);
           TextColor(Red);
           gotoxy(i,12);write('G A M E  O V E R');
           Psound((60-i)*10,50);
           delay(25);
      end;
      TextColor(Red+Blink);
      gotoxy(i,12);write('G A M E  O V E R');
      Delay(2000);
 End;

 Procedure Main;
 var i: integer;
 Begin
      TextBackground(Black);
      clrscr;
      InManHinh;
      XeC.InXe;
      repeat
            InThongTin;
            if keypressed then
            begin
                 k := readkey;
                 if (k = PauseS) or (k = PauseB) then
                 repeat
                       k := #0;
                       if keypressed then k := readkey;
                 until (k=PauseS) or (k=PauseB) or (k = ESC);
                 Xec.Dichuyen(k);
            end;
            inc(tgduong);
            XedichChay;
            VatPhamChay;
            AnVatPham;
            VaCham;
            if chet then
            begin
                 Dec(TaiNguyen[V_Life]);
                 Chet := False;
                 KhoiTao;
                 InManHinh;
                 XeC.InXe;
            end;
            if tgduong >= Tgchay then
            begin
                 duongdi;
                 Inc(Diem);
                 tgduong := 0;
            end;
      until (k = ESC) or (TaiNguyen[V_Life] < 0) ;
      if k <> ESC then Gameover;
 End;

 Procedure Menu;
 var x0,y0,y,i: integer;
 Begin
      y0 := 8;
      x0 := 30;
      y := 1;
      onsound := true;
      repeat
      TextBackground(black);
      SetCusor(32,0);
      clrscr;
      Gotoxy(X0-3,Y0-2);
      TextColor(Red+Blink);
      TextBackGround(Cyan);
      Write(' R A C I N G ');
      TextColor(Cyan+Blink);
      TextBackground(Red);
      Write(' G A M E ');

      Gotoxy(X0+4,Y0);
      TextColor(Yellow);
      TextBackground(Green);
      Write(' M E N U ');
      repeat
      k := #0;
      if keypressed then k := readkey;
      case k of
      Up: if y > 1 then begin Dec(y);PSound(1000,50);end;
      Down: if y < Soitem then begin Inc(y);PSound(1000,50);end;
             end;
      for i := 1 to soItem do
      begin
           Gotoxy(X0,Y0+i*2);
           TextColor(Black);
           if i = y then TextBackground(Brown) else TextBackground(LightGray);
           Write(Items[i]);
      end;
      until (k = #13);
      TextBackground(Black);
      case y of
      1: begin NewGame;Main;end;
      2: if not chet then Main;
      3: InGiupDo;
      4: SetSound;
      5: chet := True;
             end;
      until chet;
 End;

 BEGIN
      NewGame;
      Menu;
 END.
Code Game này cũng khá dễ, bạn nào muốn có thể thay đổi cả Menu cũng được
Game này cực kỳ đẹp luôn nha, Demo cái Menu là biết liền à :D:
View attachment 101297
làm sao để thoát ra vậy anh :(
 
Top Bottom