Đến nội dung

Hình ảnh

[Pascal] Game: Banh nảy


  • Please log in to reply
Chủ đề này có 12 trả lời

#1
hack258147

hack258147

    Binh nhất

  • Thành viên
  • 22 Bài viết

ai thích màu thì down cái BOUNCING_BAL_MÀU.rar ở dưới nhé

mọi người test thử cái game em mới làm này 

tên game : banh nảy;

Đây là bản Demo nên có thể sẽ còn lỗi ,thông cảm gõ vậy là rụng tay rồi .
dùng phím <- và ->  để di chuyển thanh tưng bóng ;
ESC : để thoát khỏi game ;

có 3 mức độ khó

Chế độ banh nảy dùng hàm random dở hơi của pascal nên nhiều lúc banh cứ nảy một chỗ
mỗi lần tưng bóng để bóng không rớt sẽ được cộng điểm ;

ban đầu có 3 mạng;
(phải đi kèm với key.tpu nhé);(có ở dưới đó);

lưu ý: game hơi lag , di chuyển từng nút một nha

{ BÁ ĐẠO PASCAL

HACK CHEAT : Insert : hack mạng;       :biggrin:   :biggrin:   :biggrin:

Home : hack điểm

 }

Có lỗi gì báo để em cải thiện tiếp
Code : (hơi bị dài); 

program gameball;
uses crt,KEY;
var h1,h2,h3,h4,banh1,banh2,can1,can2,chay1,chay2,i : integer;
diem,mang,gach1,gach2,phim,chon,dokho,muiten:integer;
chondokho : integer;
label thoat;
procedure banh;
begin
CLRSCR;
for i:=20 to 62 do begin
gotoxy(i,7);
write('__');
end;
for i:=8 to 20 do begin
gotoxy(20,i);
write('|');
end;
for i:=20 to 62 do begin
gotoxy(i,20);
write('__'); {IN giao dien game}
end;
for i:=8 to 20 do begin
gotoxy(62,i);
write('|');
end;
gotoxy(30,8);
Write('BOUNCING BALL I');
GOTOXY(25,11);
write('CHAO MUNG DEN VOI GAME BOUNCING BALL');
GOTOXY(25,13);
WRITE('DUNG PHIM "<-" DE DI CHUYEN SANG TRAI');
GOTOXY(25,14);
WRITE('DUNG PHIM "->" DE DI CHUYEN SANG PHAI');
gotoxy(25,15);
write('DUNG PHIM "ESC" DE THOAT [ QUIT ] ');
GOTOXY(25,17);
WRITE('NHAN ENTER DE BAT DAU CHOI !');
GOTOXY(25,19);
WRITE('--> ENTER !');
GOTOXY(25,23);
write('WRITE BY HACK258147');

READLN;
clrscr;
diem:=0;
banh1:=40 ; banh2:=18; {toa do cua banh}
gotoxy(banh1,banh2);
write('o'); {in banh}
{ Phan Choi game }
h2:=7;
for h1:=3 to 19 do begin
gotoxy(h2,h1);
write('//');
end;
h4:=67;
for h3:=3 to 19 do begin
gotoxy(h4,h3);
write('//');
end;
for h2:=7 to 67 do begin
gotoxy(h2,2);
write('//');
end;
for h2:=7 to 67 do begin
gotoxy(h2,20);
write('//');
end;
gotoxy(70,3);
write('BOUNCING');
GOTOXY(70,4);
WRITE('BALL I');
FOR i:=5 to 20 do begin
gotoxy(70,i);
write('/////////'); end;
{phan tao gach}
for i:=12 to 62 do begin
gotoxy(i,3);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,4);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,5);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,6);
write('');
end;

end;
procedure chaybanh;
label top,thoat,tiep,tiep2,chinhdokho,dieukhien;
begin
can1:=39;
can2:=19; {39,19}
gotoxy(30,24);
write('ESC : Thoat game');
gotoxy(50,24);
write('Write By hack258147');
gotoxy(50,25);
write('diendantoanhoc.net');

mang:=3;
top:
chay1:=0;
chay2:=-1;
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(banh1,banh2);
write(' ');
banh1:=40;
banh2:=18;
gotoxy(5,24);
write('Diem : ',diem);
if chondokho=enterkey then goto tiep;
muiten:=13;
chinhdokho:
gotoxy(10,12);
write('Chon do kho');
gotoxy(14,13);
write('De');
gotoxy(14,14);
write('Binh thuong');
gotoxy(14,15);
write('Kho');
gotoxy(10,muiten);
write('-->');
dokho:=getkey;
keypressed;
repeat

if (dokho=upkey) and (muiten=13) then goto chinhdokho;
if (dokho=upkey) then begin
gotoxy(10,muiten);
write(' ');
muiten:=muiten-1;
gotoxy(10,muiten);
write('-->');
end;
if (dokho=dnkey) and (muiten=15) then goto chinhdokho;
if (dokho=dnkey) then begin
gotoxy(10,muiten);
write(' ');
muiten:=muiten+1;
gotoxy(10,muiten);write('-->'); end;
chondokho:=getkey;
if chondokho=enterkey then begin
gotoxy(10,12);
write(' ');
gotoxy(14,13);
write(' ');
gotoxy(14,14);
write(' ');
gotoxy(14,15);
write(' ');
gotoxy(10,muiten);
write(' ');
end;
until (chondokho=enterkey);
tiep:
repeat
if muiten=13 then delay(50000);
if muiten=14 then delay(40000);
if muiten=15 then delay(30000);
gotoxy(banh1,banh2); {CT chay Banh}
write(' ');
banh1:=banh1+chay1;
banh2:=banh2+chay2;
gotoxy(banh1,banh2);
write('o');
gotoxy(can1,can2);
write('MMMM');

if keypressed then begin
dieukhien:
phim:=Getkey;

tiep2: {39:19 toa do cua can}
if phim=leftkey then begin
gotoxy(can1,can2);
write(' '); {dieu khien can qua trai}
can1:=can1-3;
if (can1=9) and (can2=19) then can1:=can1+3;
gotoxy(can1,can2);
write('MMMM');
end;

if phim=rightkey then begin
gotoxy(can1,can2);
write(' '); {dieu khien can qua phai}
can1:=can1+3;
if (can1=66) and (can2=19) then can1:=can1-3;
gotoxy(can1,can2);
write('MMMM');
end;
end;

if phim=inskey then begin
mang:=9999;
gotoxy(5,25);
write(' '); {hack mang}
gotoxy(5,25);
write('Mang : ',mang);
end;
if phim=homekey then begin
diem:=9999;
gotoxy(5,24);
write(' '); {hack diem}
gotoxy(5,24);
write('Diem : ',diem);
end;

if (can1=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1; {banh trung can_1}
chay2:=-1;
gotoxy(can1,can2);
write('M');
end;

if (can1+1=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1+1,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;
{banh trung can 2}
chay2:=-1;
gotoxy(can1+1,can2);
write('M');
end;
if (can1+2=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1,can2);
write('M');

chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1; {banh trung can 3}
chay2:=-1;
gotoxy(can1+2,can2);
write('M');
end;
if (can1+3=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1+3,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;

{banh trung can 4}
chay2:=-1;
gotoxy(can1+3,can2);
write('M');
end;
{ 9:2/ toa do ban dau cua banh }
for i:=8 to 66 do begin

if (banh1=i) and (banh2=3) then begin {neu banh dung tuong tren}
chay1:=random(3) ;
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;
chay2:=+1; end; {66:3}
end;

for i:=4 to 20 do begin

if (banh2=i) and (banh1=10) then begin {neu banh dung tuong trai}
chay1:=+1;
randomize;
chay2:=random(3);
if chay2 = 1 then chay2:=+1;
if chay2 = 2 then chay2:=-1;
if chay2 = 3 then chay2:=+1;
if chay2 = 0 then chay2:=-1; end;
end; {9:3:19}
for i:=4 to 19 do begin

if (banh2=i) and (banh1=66) then begin
chay1:=-1;
randomize;
chay2:=random(3); {neu banh dung tuong phai}
if chay2 = 1 then chay2:=+1;
if chay2 = 2 then chay2:=-1;
if chay2 = 3 then chay2:=+1;
if chay2 = 0 then chay2:=-1;end;
end;
for i:=9 to 66 do begin
if (banh1<>can1) and (banh1<>can1+1) and (banh1<>can1+2) and (banh1<>can1+3) then begin
if (banh2=19) and (banh1=i) then begin
delay(60000);
delay(60000);
mang:=mang-1; {neu banh dung day}
gotoxy(10,12);
write('Ban bi mat mot mang/ bam ENTER de choi tiep ');
gotoxy(10,13);
write('Nhan ESC de thoat ');
chon:=Getkey;
gotoxy(10,12);
write(' ');
gotoxy(10,13);
write(' ');
gotoxy(5,25);
write(' ');
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
if chon=enterkey then goto top;
if chon=Esckey then exit;
if chon=rightkey then goto top;
if chon=leftkey then goto top;
if chon=upkey then goto top;
if chon=dnkey then goto top;
end;
end;
end;



if mang = -1 then begin
gotoxy(10,12);
write('GAME OVER/Nhan Esc de thoat , nhan Space de choi tiep');
gotoxy(10,13);
write('Diem cua ban : ',diem);
chon:=getkey;
gotoxy(10,12);
write(' ');
gotoxy(10,13);
write(' ');
if chon=esckey then exit;
if chon=spacekey then begin
mang:=3;
diem:=0;
gotoxy(5,25);
write(' '); {diem :24,5 / mang:25,5}
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(5,24);
write('Diem : ',diem);
goto top;
end;
end;
until (phim=esckey);
end;

begin
banh;
can1:=39; { CT chinh }
can2:=19;
gotoxy(can1,can2); {in can}
write('MMMM');
chaybanh;

clrscr;
gotoxy(20,5);
write('GAME OVER /nhan Enter de thoat');
gotoxy(20,6);
write('Diem cua ban : ',diem);
readln;
end.

File gửi kèm


Bài viết đã được chỉnh sửa nội dung bởi hack258147: 03-09-2014 - 23:07


#2
hack258147

hack258147

    Binh nhất

  • Thành viên
  • 22 Bài viết
BẠn cũng thuộc dạng Cao Thủ Pascal rồi

chưa đâu bởi vì em mới học lớp 9 và chưa hiểu rõ fuction vs boolean lắm


mấy game này gõ muốn rụng tay mà nhanh nhàm ghê


Nghệ thuật 102 , ông nghĩ tôi nên đặt cái Intime ở đâu ,chưa làm ra cứ bị lỗi gì ấy


ai thích màu thì down cái BOUNCING_BAL_MÀU.rar nha


HAIZ không chạy song song, được chơi thì ấn từng nút một để khỏi bị lag nha

#3
hxthanh

hxthanh

    Tín đồ $\sum$

  • Hiệp sỹ
  • 3915 Bài viết

Góp ý cho bạn:

- Delay hơi lâu

- Ẩn con trỏ nhấp nháy đi

- Viền nên dùng ký tự khác cho nổi bật lên

- Game lag do không chạy được đa nhiệm (banh di chuyển thì tấm đỡ phải chờ)

- Tạo thêm màu mè cho nó đẹp

- Code chương trình rất dài và thiếu tính kế thừa (tạo procedure, function, chương trình con, v.v...)

 

- Dù sao bạn cũng rất sáng tạo đấy!



#4
hack258147

hack258147

    Binh nhất

  • Thành viên
  • 22 Bài viết

vậy làm sao để Banh và tấm có thể chạy một lúc vậy



#5
hxthanh

hxthanh

    Tín đồ $\sum$

  • Hiệp sỹ
  • 3915 Bài viết

Unit MTime, được tôi viết ra nhằm thực hiện điều này!

File gửi kèm  MTIME.rar   667bytes   315 Số lần tải

Unit MTime cung cấp cho bạn 1 Procedure và 2 Function

TimeStart; là procedure ghi nhận thời gian bắt đầu

TimeCurrent; là function kiểu longint; cho kết quả thời gian tức thời (kể từ lần gọi TimeStart; gần nhất)

InTime(x:longint); là function kiểu Boolean; cho biết đã quá thời gian $x$ hay chưa. Nếu chưa quá thì true; quá thì false;

Mỗi đơn vị giá trị $x$ tương đương với $0,15$ giây

 

Chương trình sau đây thực hiện song song việc hiển thị thời gian đếm ngược và kết thúc tức thời.

Uses Crt,Key,Mtime;
Var ch:integer;
Begin
ClrScr;
TimeStart;
Write('Chuong trinh se ket thuc sau       giay. Nhan Enter ket thuc!');
While InTime(450) do
 begin
  if keypressed then ch:=Getkey;
  if ch=EnterKey then exit;
  gotoxy(30,1); Write((450-TimeCurrent)/15:2:2);
 end;
End.


#6
hxthanh

hxthanh

    Tín đồ $\sum$

  • Hiệp sỹ
  • 3915 Bài viết

Ok, cuối cùng cũng xong (chưa test kỹ lắm)

Sản phẩm đây, tác giả cho ý kiến! ^_^

File gửi kèm  BBall.rar   8.22K   705 Số lần tải

b_ball.png



#7
hack258147

hack258147

    Binh nhất

  • Thành viên
  • 22 Bài viết
code nhẹ hơn . đẹp hơn . vậy thì đi làm game khác được rồi . công nhận anh giỏi thiệt

Bài viết đã được chỉnh sửa nội dung bởi hack258147: 05-09-2014 - 18:41


#8
nghethuat102

nghethuat102

    Trung sĩ

  • Thành viên
  • 147 Bài viết
uses crt,mtime,key;
const s1='BAT DAU';
      s2='DIEM';
      s3='THOAT';
    vt:array[1..6] of 1..100=(42,47,52,57,62,67);
var a:array[1..6,1..5000] of 0..1;
    c:array[1..5000] of 1..30;
    diem:array[1..10] of word;
    ten:array[1..10] of string[10];
    t:boolean;
    f:text;
    n:word;
    sodiem:longint;
    procedure nguoichoi(i,j:integer);
     begin
      textcolor(3);
      gotoxy(vt[i],j);
      write(chr(-78));
      textcolor(10);
      write('/\');
      textcolor(3);
      write(chr(-78));
      gotoxy(vt[i],j+1);
      textcolor(10);
      write(' ',chr(-37),chr(-37),' ');
      gotoxy(vt[i],j+2);
      textcolor(3);
      write(chr(-78),'  ',chr(-78));
     end;
    procedure may(i,j:integer);
     begin
      textcolor(15);
      if (j>0)and(j<25) then
       begin
      gotoxy(vt[i],j);
      write(chr(-78),'\/',chr(-78));
       end;
      if (j>=0)and(j<25) then
       begin
      gotoxy(vt[i],j-1);
      write(' ',chr(-37),chr(-37),' ');
      end;
      if (j>0)and(j<25) then
       begin
      gotoxy(vt[i],j-2);
      write(chr(-78),'  ',chr(-78));
      gotoxy(1,1);
       end;
     end;
    procedure xoa(i,j:integer);
     var z:integer;
     begin
      for z:=0 to 2 do
       if j+z<=24 then
        begin
         gotoxy(i,j+z);
         write('    ');
        end;
     end;
    procedure batdau;
     var   soxe,khoangcach,m,k,vty,vtx,i,j,batdau,d,w:integer;
           b:boolean;
     begin
     gotoxy(7,10);
     write('             ');
     gotoxy(7,11);
     write('             ');
     gotoxy(7,12);
     write('             ');
     textcolor(7);
     gotoxy(8,21);
     write('Nhan ESC de thoat');
     gotoxy(8,22);
     write('Nhan SPACE or ENTER de dung');
     sodiem:=0;
     vty:=22;
     vtx:=3;
     b:=true;
     nguoichoi(vtx,vty);
     gotoxy(10,8);
     textcolor(10);
     write('DIEM :  ');
     textcolor(15);
     write(sodiem);
     khoangcach:=0;
     batdau:=1;
     d:=0;
     repeat
    if khoangcach=0 then
     begin
     repeat
      khoangcach:=random(10);
     until khoangcach>5;
      d:=d+1;
      for i:=1 to 6 do
        a[i,d]:=random(2);
        c[d]:=1;
        w:=0;
      for i:=1 to 6 do
       if a[i,d]=1 then w:=w+1;
       if w>4 then
        begin
        for i:=1 to w-4 do;
         begin
        repeat
         w:=random(7);
        until (a[w,d]=1)and(w<>0);
        a[w,d]:=0;
         end;
        end;
     end
    else khoangcach:=khoangcach-1;
    for i:=batdau to d do
       begin
        c[i]:=c[i]+1;
        if c[i]=28 then batdau:=batdau+1;
        if c[i]>vty+6 then
         for j:=1 to 6 do
           if a[j,i]=1 then
            begin
            textcolor(15);
            gotoxy(18,8);
            write(sodiem+1);
            sodiem:=sodiem+1;
            end;
       end;
      timestart;
      while intime(10) do
        begin
         k:=0;
         if keypressed then
         begin
         k:=getkey;
         if (k=upkey)or(k=dnkey)or(k=rightkey)or(k=leftkey) then
         xoa(vt[vtx],vty);
           if (k=upkey)and(vty>2) then
            vty:=vty-1;
         if (k=dnkey)and(vty<22) then
           vty:=vty+1;
         if (k=rightkey)and(vtx<6) then
           vtx:=vtx+1;
         if (k=leftkey)and(vtx>1) then
           vtx:=vtx-1;
         if (k=upkey)or(k=dnkey)or(k=rightkey)or(k=leftkey) then
         nguoichoi(vtx,vty);
          if (k=enterkey)or (k=spacekey) then
            begin
            gotoxy(8,22);
            textcolor(15);
            write('Nhan SPACE or ENTER de tiep tuc');
            repeat
             m:=getkey;
            until (m=enterkey)or(m=spacekey);
            gotoxy(8,22);
            textcolor(7);
            write('Nhan SPACE or ENTER de dung     ');
            end;
          if k=esckey then
           begin
            gotoxy(8,21);
            textcolor(15);
            write('Ban thuc su muon thoat? ',chr(16));
            textcolor(10);
            write('Y');
            textcolor(15);
            write(chr(17));
            textcolor(12);
            write(' N ');
            gotoxy(33,21);
            i:=32;
            textcolor(15);
            repeat
              m:=getkey;
              if (m=rightkey)and(i=32) then
               begin
                i:=35;
                gotoxy(32,21);
                write(' ');
                gotoxy(34,21);
                write(' ');
                gotoxy(35,21);
                write(chr(16));
                gotoxy(37,21);
                write(chr(17));
                gotoxy(36,21);
               end;
              if (m=leftkey)and(i=35) then
               begin
                i:=32;
                gotoxy(35,21);
                write(' ');
                gotoxy(37,21);
                write(' ');
                gotoxy(32,21);
                write(chr(16));
                gotoxy(34,21);
                write(chr(17));
                gotoxy(33,21);
               end;
            until m=enterkey;
            if i=32 then
             begin
              b:=false;
              t:=false;
             end;
            if i=35 then
             begin
              textcolor(7);
              gotoxy(8,21);
              write('Nhan ESC de thoat               ');
             end;
            end;
           end;
           for i:=batdau to d do
          begin
           for j:=1 to 6 do
             if a[j,i]=1 then
              begin
               if (c[i]-1>=0)and(c[i]<=26) then
                 begin
                 gotoxy(vt[j],c[i]-1);
                 write('    ');
                 end;
               if (c[i]-2>=0)and(c[i]-1<=26) then
                 begin
                 gotoxy(vt[j],c[i]-2);
                 write('    ');
                 end;
                if (c[i]-3>=0)and(c[i]-2<=26) then
                 begin
                 gotoxy(vt[j],c[i]-3);
                 write('    ');
                 end;
                 nguoichoi(vtx,vty);
            end;
           for j:=1 to 6 do
           if a[j,i]=1 then
            begin
              may(j,c[i]);
            {  nguoichoi(vtx,vty); }
            end;
          end;
           delay(1000);
          end;
         {cho nay dat code no khi dung nhau}
     until b=false;
     end;
    procedure khoitao;
     var i,j:integer;
     begin
       for i:=1 to 25 do
         begin
         textcolor(3);
          gotoxy(40,i);
          write(chr(-78));
          gotoxy(72,i);
          write(chr(-78));
         textcolor(red);
          write('o o o o');
         end;
       for i:=1 to 6 do
         begin
         gotoxy(vt[i],12);
         write('0000');
          end;
       for i:=41 to 71 do
        begin
         textcolor(3);
         gotoxy(i,25);
         write(chr(-36));
        end;
       textcolor(12);
       gotoxy(15,4);
       write('RACING GAME');
       gotoxy(5,2);
       textcolor(green);
       write('*******************************');
       gotoxy(5,6);
       write('*******************************');
     end;
    procedure luachon;
     var i,k:integer;
      begin
       textcolor(8);
       gotoxy(8,21);
       write('Nhan ESC de thoat');
       gotoxy(8,22);
       write('Nhan SPACE or ENTER de dung');
       i:=10;
       gotoxy(10,i);
       textcolor(15);
       write(chr(-81),'  ',s1);
       gotoxy(10,i+1);
       textcolor(7);
       write('   ',s2);
       gotoxy(10,i+2);
       write('   ',s3);
       repeat
         k:=getkey;
         if (k=dnkey)and(i<12) then
          begin
           textcolor(7);
           gotoxy(10,i);
           write('   ');
           if i=10 then write(s1)
           else if i=11 then write(s2);
           i:=i+1;
           textcolor(15);
           gotoxy(10,i);
           write(chr(-81),'  ');
           if i=11 then write(s2)
           else if i=12 then write(s3);
          end;
         if (k=upkey)and(i>10) then
          begin
           textcolor(7);
           gotoxy(10,i);
           write('   ');
           if i=11 then write(s2)
           else if i=12 then write(s3);
           i:=i-1;
           textcolor(15);
           gotoxy(10,i);
           write(chr(-81),'  ');
           if i=10 then write(s1)
           else if i=11 then write(s2);
          end;
       until k=enterkey;
       if i=12 then t:=false
       else if i=11 then
              begin
               gotoxy(7,10);
               write('                ');
               gotoxy(7,11);
               write('                ');
               gotoxy(7,12);
               write('                ');
               textcolor(15);
               gotoxy(10,10);
               write(chr(-81),'  QUAY LAI');
               for k:=1 to 9 do
                 begin
                  textcolor(red);
                  gotoxy(11,10+k);
                  write(k);
                  textcolor(7);
                  write(' ',ten[k]);
                  gotoxy(22,10+k);
                  write(diem[k]);
                 end;
                 gotoxy(10,10);
                 repeat
                 k:=getkey;
                 until k=enterkey;
                 for k:=0 to 9 do
                  begin
                   gotoxy(10,10+k);
                   write('                ');
                  end;
              end
            else batdau;
      end;
begin
  clrscr;
  khoitao;
  t:=true;
  assign(f,'pacing.out');
  reset(f);
  for n:=1 to  9 do
   readln(f,diem[n]);
  for n:=1 to 9 do
   readln(f,ten[n]);
   close(f);
  repeat
    luachon;
     assign(f,'pacing.out');
    rewrite(f);
  for n:=1 to 9 do
  writeln(f,diem[n]);
  for n:=1 to 9 do
  writeln(f,ten[n]);
   close(f);
  until  t=false;
end. 

code nhẹ hơn . đẹp hơn . vậy thì đi làm game khác được rồi . công nhận anh giỏi thiệt

Mình sắp hoàn thành game đua xe rồi bạn :) , tuy có hơi rối nhưng và thiếu 1 ít  thuật toán cho việc đụng xe!, nhưng dù sao cũng thấy vui vì làm đc như thế này 



#9
turbopascal

turbopascal

    Binh nhất

  • Thành viên
  • 26 Bài viết
11802024_493121840864366_1791639463_n.jp

        "Triết lý của tôi rất giản đơn. Cái gì trống thì làm đầy. Cái gì đầy thì đổ ra. Chỗ nào ngứa thì gãi."           -Alice Roosevelt Longworth.  :biggrin:  :biggrin:  :biggrin: 

 


#10
huynhthanhloc

huynhthanhloc

    Lính mới

  • Thành viên mới
  • 1 Bài viết

MẤY BẠN GHÊ GIỎI GHÊ NHA :like  :like  :like  :like  :like  :like  :like  :ukliam2:  :ukliam2:  :ukliam2:  :ukliam2:

MÌNH LÀ THÀNH VIÊN MỚI CỦNG XIN GÓP TÍ MÃ NGUỒN GAME PASCAL DO MÌNH VIẾT

 

ĐÂY LÀ MÃ NGUỒN CỦA GAME 

CÁC BẠN CÓ THỂ BIÊN DỊCH NÓ BẰNG LAZARUS IDE HOẶC FREE PASCAL IDE 

 

CÁC BẠN DÙNG PHÍM UP, DOWN, LEFT, RIGHT ĐỂ DUY CHUYỂN, PHÍM PASPACE ĐỂ BẮN

VÌ GAME ĐANG TRONG THỜI GIAN THỬ NGHIỆM NÊN CÒN NHIỀU LỔI VÀ CHƯA ĐẸP NÊN CÁC BẠN CỨ CHO Ý KIẾN ĐÓNG GÓP 

GIÚP MÌNH HOÀNG THIỆN GAME NÀY NHA

THANK NHIỀU  :D  :D  :D  :D  :D  :D  :D  :D  :D  :D

program Tank_Game;

uses Tools, Windows;

Var
  Game : TGame;
begin
  Game := TGame.Create;
  Game.Init;
  While True do
   begin
     Game.UpDate;
     Game.ClearnCreen;
     Game.Render;
     Game.Delays;
   end;
  Game.Destroy;
end.
 

CÒN ĐÂY LÀ THƯ VIÊN TOOLS.PAS

unit Tools;

interface

uses
 SysUtils, Crt, Windows;

Const
  // TÊN CỬA SỔ
  CAPTION = ' MY TANK GAME ';
  // THÔNG SÔ CỬA SỔ
  MAXCOLUM = 70;
  MAXCELL = 30;
  // CÁC CHAR HÌNH ẢNH
  IMAGETANK1 = #179;
  IMAGETANK2 = #2;
  IMAGETANK3 = #196;

  IMAGEAMMO = #1;

  IMAGELINE = #220;

  MAXENEMYTANK = 2;


Type
  // LƯU VỊ TRÍ CỦA CÁC ĐỐI TƯƠNG TRONG KHÔNG GAN 2D
  TPoint = Record Colum, Cell : Byte; end;
  // HƯỚNG ĐI CỦA CÁC ĐỐI TƯỢNG
  TDirection = (NODIRECTION = 0, UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4);
  //CÁC PHE PHÁI TRONG GAME
  TFaction = (NOFACTION, PLAYER, ENEMY);
  // CÁC LỆNH TRONG GAME
  TCommand = (NOCOMMAND, TANKUP, TANKRIGHT, TANKLEFT, TANKDOWN, TANKFIRE);



  TTank = Record
    T_Point : TPoint;
    T_Direction : TDirection;
    T_Faction :  TFaction;
    T_Death : Boolean;
    T_Fire : Boolean;
  end;

  TTankEnemy = Record
    TE_Point : TPoint;
    TE_Direction : TDirection;
    TE_Faction :  TFaction;
    TE_Death,
    TE_AtTheEnd: Boolean;
    //TE_Fire : Boolean;
    TE_End : TPoint;
  end;


  TAmmo = Record
    A_Point : TPoint;
    A_Direction : TDirection;
    A_Death : Boolean;
  end;

  TTankEnemys = TTankEnemy;

  { TGame }

  TGame = Class
    Private
      Command : TCommand;
      Tank : TTank;
      TankEnemy : TTankEnemys;
      Ammo : TAmmo;
      Score : Integer;
    Protected
      //CẬP NHẬT CÁC LỆNH TRONG GAME
      Procedure UpDateCommand;
      // XE TANH NGƯỜI CHƠI NHẬN LỆNH TRONG GAME
      Procedure TankUpDateCommand;
      Procedure TankMove;
      Procedure TankDraw;
      Procedure TankEnemyCreate;
      Procedure TankEnemyMove;
      Procedure TankEnemyDraw;
      //KIỂM TRA ĐẠN BẮN TRÚNG XE TANK ĐỊCH
      Procedure CheckAmmoHitTankEnemy;
      Procedure AmmoMove;
      Procedure AmmoDraw;
      //THIẾT LẬP THÔNG SỐ CHO CỦA SỔ CONSOLE
      Procedure SetWindowConsole;
      Procedure DrawLine;
    Public
      Procedure Init;
      Procedure UpDate;
      Procedure ClearnCreen;
      Procedure Render;
      Procedure Delays;
  end;


implementation

{ TGame }

Procedure DrawImage(Colum, Cell : Byte; Image : Char);
begin
    Gotoxy(Colum, Cell);
    Write(Image);
end;

procedure TGame.Init;
begin
  Score := 0;
  Randomize;
  Command := NOCOMMAND;
  With Tank do
   begin
    T_Point.Colum:=10;
    T_Point.Cell:=10;
    T_Direction := NODIRECTION;
    T_Faction := NOFACTION;
    T_Fire := False;
   end;

  With Ammo do
   begin
    A_Death := True;
   end;
   SetWindowConsole;

    With TankEnemy Do
     Begin
      //TE_Point.Cell:=16;
      //TE_Point.Colum:=16;
      //TE_Direction := NODIRECTION;
      TE_Faction := ENEMY;
      TE_Death := True;
     end;
end;

procedure TGame.UpDateCommand;
begin
  Command := NOCOMMAND;
  If GetAsyncKeyState(VK_UP) <> 0 Then
   Command := TANKUP;
  If GetAsyncKeyState(VK_DOWN) <> 0 Then
   Command := TANKDOWN;
  If GetAsyncKeyState(VK_LEFT) <> 0 Then
   Command := TANKLEFT;
  If GetAsyncKeyState(VK_RIGHT) <> 0 Then
   Command := TANKRIGHT;
  If GetAsyncKeyState(VK_SPACE) <> 0 Then
   Command := TANKFIRE;
  If GetAsyncKeyState(VK_ESCAPE) <> 0 Then
   Halt;
end;

procedure TGame.TankUpDateCommand;
begin
  Case Command Of
    TANKUP:Tank.T_Direction:=UP;
    TANKDOWN:Tank.T_Direction:=DOWN;
    TANKLEFT:Tank.T_Direction:=LEFT;
    TANKRIGHT:Tank.T_Direction:=RIGHT;
    TANKFIRE:
      begin
       IF Ammo.A_Death = True Then
        Begin
         Ammo.A_Point := Tank.T_Point;
         Ammo.A_Direction:= Tank.T_Direction;
         Ammo.A_Death := False;
        end;
      end;
  end;
end;

procedure TGame.TankMove;
begin
  If Tank.T_Point.Cell < 2 Then
   Tank.T_Point.Cell:=2
  Else
    If Tank.T_Point.Cell > MAXCELL Then
     Tank.T_Point.Cell:=MAXCELL
    Else
      If Tank.T_Point.Colum < 2 Then
       Tank.T_Point.Colum:=2
      Else
        If Tank.T_Point.Colum > MAXCOLUM Then
         Tank.T_Point.Colum:= MAXCOLUM
        Else
          Case Tank.T_Direction Of
            UP:Dec(Tank.T_Point.Cell);
            DOWN:Inc(Tank.T_Point.Cell);
            LEFT:Dec(Tank.T_Point.Colum);
            RIGHT:Inc(Tank.T_Point.Colum);
          end;
end;

procedure TGame.TankDraw;
begin
  With Tank Do
  Case T_Direction OF
    UP:
      Begin
       DrawImage(T_Point.Colum,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell-1,IMAGETANK1);
       DrawImage(T_Point.Colum-1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell+1,IMAGETANK2);
      End;
    DOWN:
      Begin
       DrawImage(T_Point.Colum,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell+1,IMAGETANK1);
       DrawImage(T_Point.Colum-1,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell-1,IMAGETANK2);
      End;
    LEFT:
      Begin
       DrawImage(T_Point.Colum,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell,IMAGETANK3);
       DrawImage(T_Point.Colum-1,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell+1,IMAGETANK2);
      End;
    RIGHT:
      Begin
       DrawImage(T_Point.Colum,T_Point.Cell,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum+1,T_Point.Cell,IMAGETANK3);
       DrawImage(T_Point.Colum+1,T_Point.Cell+1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell-1,IMAGETANK2);
       DrawImage(T_Point.Colum-1,T_Point.Cell+1,IMAGETANK2);
      End;
  end;
end;

procedure TGame.TankEnemyCreate;
Var
  Point : TPoint;

Function PointInGame(Point : TPoint): Boolean;
begin
  Result := False;
  IF Point.Cell >2 Then
   IF Point.Cell < MAXCELL Then
    IF Point.Colum > 2 Then
     IF Point.Colum < MAXCOLUM Then
      Result := True;
end;

begin
  IF TankEnemy.TE_Death = True Then
   Begin
    Point.Colum:=Random(MAXCOLUM);
    Point.Cell:=Random(MAXCELL);
    IF PointINGame(Point) = True Then
     Begin
      Tankenemy.TE_Point := Point;
      TankEnemy.TE_Faction:=ENEMY;
      TankEnemy.TE_Direction:=TDirection(Random(4));
      Case TankEnemy.TE_Direction OF
        UP, DOWN:
          Begin
           Point.Cell:=Random(MAXCELL);
           Point.Colum:=TankEnemy.TE_Point.Colum;
           IF PointInGame(Point) = True Then
            Begin
             TankEnemy.TE_End := Point;
             TankEnemy.TE_AtTheEnd:=False;
            End;

          End;
        LEFT, RIGHT:
          Begin
           Point.Colum:=Random(MAXCOLUM);
           Point.Cell:=TankEnemy.TE_Point.Cell;
           IF PointInGame(Point) = True Then
            Begin
             TankEnemy.TE_End := Point;
             TankEnemy.TE_AtTheEnd:=False;
            End;
          End;
      End;
      TankEnemy.TE_Death:=False;
     End
    Else
     TankEnemy.TE_Death:=True;
   End
  Else
   Begin
    IF TankEnemy.TE_AtTheEnd = True Then
     Begin
       TankEnemy.TE_Direction:=TDirection(Random(4));
    Case TankEnemy.TE_Direction OF
      UP, DOWN:
        Begin
         Point.Cell:=Random(MAXCELL);
         Point.Colum:=TankEnemy.TE_Point.Colum;
         IF PointInGame(Point) = True Then
          Begin
           TankEnemy.TE_End := Point;
           TankEnemy.TE_AtTheEnd:=False;
          End;

        End;
      LEFT, RIGHT:
        Begin
         Point.Colum:=Random(MAXCOLUM);
         Point.Cell:=TankEnemy.TE_Point.Cell;
         IF PointInGame(Point) = True Then
          Begin
           TankEnemy.TE_End := Point;
           TankEnemy.TE_AtTheEnd:=False;
          End;
        End;
      NODIRECTION : TankEnemy.TE_AtTheEnd:=True;
     End;
   End;
end;
end;

procedure TGame.TankEnemyMove;
begin
  With TankEnemy Do
   Begin
    IF (TE_Death <> True) And (TE_AtTheEnd <> True) Then
     Begin
      Case TE_Direction OF
        UP, DOWN:
          Begin
           IF TE_End.Cell > TE_Point.Cell Then
            Inc(TE_Point.Cell)
           Else
             IF TE_End.Cell < TE_Point.Cell Then
              Dec(TE_Point.Cell)
             Else
               TE_AtTheEnd:=True;
          End;
        LEFT, RIGHT:
          Begin
           IF TE_End.Colum > TE_Point.Colum Then
            Inc(TE_Point.Colum)
           Else
             IF TE_End.Colum < TE_Point.Colum Then
              Dec(TE_Point.Colum)
             Else
               TE_AtTheEnd:=True;
          End;
        NODIRECTION:TE_AtTheEnd:=True;
      End;
     End;
   End;
end;

procedure TGame.TankEnemyDraw;
begin
  TextColor(Red);
    With TankEnemy Do
     IF TankEnemy.TE_Death=False Then
      Begin
        Case TE_Direction OF
          UP:
            Begin
             DrawImage(TE_Point.Colum,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell-1,IMAGETANK1);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell+1,IMAGETANK2);
            End;
          DOWN:
            Begin
             DrawImage(TE_Point.Colum,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell+1,IMAGETANK1);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell-1,IMAGETANK2);
            End;
          LEFT:
            Begin
             DrawImage(TE_Point.Colum,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell,IMAGETANK3);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell+1,IMAGETANK2);
            End;
          RIGHT:
            Begin
             DrawImage(TE_Point.Colum,TE_Point.Cell,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell,IMAGETANK3);
             DrawImage(TE_Point.Colum+1,TE_Point.Cell+1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell-1,IMAGETANK2);
             DrawImage(TE_Point.Colum-1,TE_Point.Cell+1,IMAGETANK2);
            End;
      end;
     End;
  TextColor(White);
end;

procedure TGame.CheckAmmoHitTankEnemy;
begin
  IF (Ammo.A_Point.Cell >= TankEnemy.TE_Point.Cell-1) Then
   IF (Ammo.A_Point.Cell <= TankEnemy.TE_Point.Cell+1) Then
    IF (Ammo.A_Point.Colum >= TankEnemy.TE_Point.Colum-1) Then
     IF (Ammo.A_Point.Cell <= TankEnemy.TE_Point.Cell+1) Then
      Begin
       TankEnemy.TE_Death:=True;
       Ammo.A_Death:=True;
       Inc(Score,10);
      End;
end;

procedure TGame.AmmoMove;
begin
  IF (Ammo.A_Point.Cell < 1) Then
   Ammo.A_Death:=True
  Else
   IF (Ammo.A_Point.Cell > MAXCELL) Then
    Ammo.A_Death:=True
   Else
    IF (Ammo.A_Point.Colum < 1) Then
     Ammo.A_Death:=True
    Else
     IF (Ammo.A_Point.Colum > MAXCOLUM) Then
      Ammo.A_Death:=True
     Else
       Case Ammo.A_Direction of
         UP:Dec(Ammo.A_Point.Cell,2);
         DOWN:Inc(Ammo.A_Point.Cell,2);
         LEFT:Dec(Ammo.A_Point.Colum,2);
         RIGHT:Inc(Ammo.A_Point.Colum,2);
       end;
end;

procedure TGame.AmmoDraw;
begin
  IF Ammo.A_Death = False Then
   DrawImage(Ammo.A_Point.Colum, Ammo.A_Point.Cell,IMAGEAMMO);
end;

procedure TGame.SetWindowConsole;
Var
  IHand, OHand : HANDLE;
  Res : SMALL_RECT;
  ConsoleSize : COORD;
begin
  IHand := GetStdHandle(STD_INPUT_HANDLE);
  OHand := GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTitle(CAPTION);
  ConsoleSize.X:=MAXCOLUM;
  ConsoleSize.Y:=MAXCELL+10;
  SetConsoleScreenBufferSize(IHand,ConsoleSize);
  Res.Top:=10;
  Res.Left:=10;
  Res.Right:=MAXCOLUM;
  Res.Bottom:=MAXCELL+10;
end;

procedure TGame.DrawLine;
Var
  I : Byte;
begin
  GoToXy(1,MAXCELL + 3);
  Writeln('DIEM SO CUA BAN LA : ',Score);

end;

procedure TGame.UpDate;
begin
  UpDateCommand;
  TankUpDateCommand;
  TankMove;
  AmmoMove;
  TankEnemyCreate;
  TankEnemyMove;
  CheckAmmoHitTankEnemy;
end;

procedure TGame.ClearnCreen;
begin
  Clrscr;
end;

procedure TGame.Render;
begin
  TankDraw;
  AmmoDraw;
  TankEnemyDraw;
  DrawLine;
end;

procedure TGame.Delays;
begin
  Sleep(80);
end;

end.

 


#11
phile1290

phile1290

    Lính mới

  • Thành viên mới
  • 3 Bài viết

cho em hỏi sao code,chạy pascal báo lỗi vậy



#12
phile1290

phile1290

    Lính mới

  • Thành viên mới
  • 3 Bài viết

 

ai thích màu thì down cái BOUNCING_BAL_MÀU.rar ở dưới nhé

mọi người test thử cái game em mới làm này 

tên game : banh nảy;

Đây là bản Demo nên có thể sẽ còn lỗi ,thông cảm gõ vậy là rụng tay rồi .
dùng phím <- và ->  để di chuyển thanh tưng bóng ;
ESC : để thoát khỏi game ;

có 3 mức độ khó

Chế độ banh nảy dùng hàm random dở hơi của pascal nên nhiều lúc banh cứ nảy một chỗ
mỗi lần tưng bóng để bóng không rớt sẽ được cộng điểm ;

ban đầu có 3 mạng;
(phải đi kèm với key.tpu nhé);(có ở dưới đó);

lưu ý: game hơi lag , di chuyển từng nút một nha

{ BÁ ĐẠO PASCAL

HACK CHEAT : Insert : hack mạng;       :biggrin:   :biggrin:   :biggrin:

Home : hack điểm

 }

Có lỗi gì báo để em cải thiện tiếp
Code : (hơi bị dài); 

program gameball;
uses crt,KEY;
var h1,h2,h3,h4,banh1,banh2,can1,can2,chay1,chay2,i : integer;
diem,mang,gach1,gach2,phim,chon,dokho,muiten:integer;
chondokho : integer;
label thoat;
procedure banh;
begin
CLRSCR;
for i:=20 to 62 do begin
gotoxy(i,7);
write('__');
end;
for i:=8 to 20 do begin
gotoxy(20,i);
write('|');
end;
for i:=20 to 62 do begin
gotoxy(i,20);
write('__'); {IN giao dien game}
end;
for i:=8 to 20 do begin
gotoxy(62,i);
write('|');
end;
gotoxy(30,8);
Write('BOUNCING BALL I');
GOTOXY(25,11);
write('CHAO MUNG DEN VOI GAME BOUNCING BALL');
GOTOXY(25,13);
WRITE('DUNG PHIM "<-" DE DI CHUYEN SANG TRAI');
GOTOXY(25,14);
WRITE('DUNG PHIM "->" DE DI CHUYEN SANG PHAI');
gotoxy(25,15);
write('DUNG PHIM "ESC" DE THOAT [ QUIT ] ');
GOTOXY(25,17);
WRITE('NHAN ENTER DE BAT DAU CHOI !');
GOTOXY(25,19);
WRITE('--> ENTER !');
GOTOXY(25,23);
write('WRITE BY HACK258147');

READLN;
clrscr;
diem:=0;
banh1:=40 ; banh2:=18; {toa do cua banh}
gotoxy(banh1,banh2);
write('o'); {in banh}
{ Phan Choi game }
h2:=7;
for h1:=3 to 19 do begin
gotoxy(h2,h1);
write('//');
end;
h4:=67;
for h3:=3 to 19 do begin
gotoxy(h4,h3);
write('//');
end;
for h2:=7 to 67 do begin
gotoxy(h2,2);
write('//');
end;
for h2:=7 to 67 do begin
gotoxy(h2,20);
write('//');
end;
gotoxy(70,3);
write('BOUNCING');
GOTOXY(70,4);
WRITE('BALL I');
FOR i:=5 to 20 do begin
gotoxy(70,i);
write('/////////'); end;
{phan tao gach}
for i:=12 to 62 do begin
gotoxy(i,3);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,4);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,5);
write('');
end;
for i:=12 to 62 do begin
gotoxy(i,6);
write('');
end;

end;
procedure chaybanh;
label top,thoat,tiep,tiep2,chinhdokho,dieukhien;
begin
can1:=39;
can2:=19; {39,19}
gotoxy(30,24);
write('ESC : Thoat game');
gotoxy(50,24);
write('Write By hack258147');
gotoxy(50,25);
write('diendantoanhoc.net');

mang:=3;
top:
chay1:=0;
chay2:=-1;
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(banh1,banh2);
write(' ');
banh1:=40;
banh2:=18;
gotoxy(5,24);
write('Diem : ',diem);
if chondokho=enterkey then goto tiep;
muiten:=13;
chinhdokho:
gotoxy(10,12);
write('Chon do kho');
gotoxy(14,13);
write('De');
gotoxy(14,14);
write('Binh thuong');
gotoxy(14,15);
write('Kho');
gotoxy(10,muiten);
write('-->');
dokho:=getkey;
keypressed;
repeat

if (dokho=upkey) and (muiten=13) then goto chinhdokho;
if (dokho=upkey) then begin
gotoxy(10,muiten);
write(' ');
muiten:=muiten-1;
gotoxy(10,muiten);
write('-->');
end;
if (dokho=dnkey) and (muiten=15) then goto chinhdokho;
if (dokho=dnkey) then begin
gotoxy(10,muiten);
write(' ');
muiten:=muiten+1;
gotoxy(10,muiten);write('-->'); end;
chondokho:=getkey;
if chondokho=enterkey then begin
gotoxy(10,12);
write(' ');
gotoxy(14,13);
write(' ');
gotoxy(14,14);
write(' ');
gotoxy(14,15);
write(' ');
gotoxy(10,muiten);
write(' ');
end;
until (chondokho=enterkey);
tiep:
repeat
if muiten=13 then delay(50000);
if muiten=14 then delay(40000);
if muiten=15 then delay(30000);
gotoxy(banh1,banh2); {CT chay Banh}
write(' ');
banh1:=banh1+chay1;
banh2:=banh2+chay2;
gotoxy(banh1,banh2);
write('o');
gotoxy(can1,can2);
write('MMMM');

if keypressed then begin
dieukhien:
phim:=Getkey;

tiep2: {39:19 toa do cua can}
if phim=leftkey then begin
gotoxy(can1,can2);
write(' '); {dieu khien can qua trai}
can1:=can1-3;
if (can1=9) and (can2=19) then can1:=can1+3;
gotoxy(can1,can2);
write('MMMM');
end;

if phim=rightkey then begin
gotoxy(can1,can2);
write(' '); {dieu khien can qua phai}
can1:=can1+3;
if (can1=66) and (can2=19) then can1:=can1-3;
gotoxy(can1,can2);
write('MMMM');
end;
end;

if phim=inskey then begin
mang:=9999;
gotoxy(5,25);
write(' '); {hack mang}
gotoxy(5,25);
write('Mang : ',mang);
end;
if phim=homekey then begin
diem:=9999;
gotoxy(5,24);
write(' '); {hack diem}
gotoxy(5,24);
write('Diem : ',diem);
end;

if (can1=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1; {banh trung can_1}
chay2:=-1;
gotoxy(can1,can2);
write('M');
end;

if (can1+1=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1+1,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;
{banh trung can 2}
chay2:=-1;
gotoxy(can1+1,can2);
write('M');
end;
if (can1+2=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1,can2);
write('M');

chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1; {banh trung can 3}
chay2:=-1;
gotoxy(can1+2,can2);
write('M');
end;
if (can1+3=banh1) and (can2=banh2) then begin
diem:=diem+1;
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
gotoxy(can1+3,can2);
write('M');
chay1:=random(3);
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;

{banh trung can 4}
chay2:=-1;
gotoxy(can1+3,can2);
write('M');
end;
{ 9:2/ toa do ban dau cua banh }
for i:=8 to 66 do begin

if (banh1=i) and (banh2=3) then begin {neu banh dung tuong tren}
chay1:=random(3) ;
if chay1 = 1 then chay1:=+1;
if chay1 = 2 then chay1:=-1;
if chay1 = 3 then chay1:=+1;
if chay1 = 0 then chay1:=-1;
chay2:=+1; end; {66:3}
end;

for i:=4 to 20 do begin

if (banh2=i) and (banh1=10) then begin {neu banh dung tuong trai}
chay1:=+1;
randomize;
chay2:=random(3);
if chay2 = 1 then chay2:=+1;
if chay2 = 2 then chay2:=-1;
if chay2 = 3 then chay2:=+1;
if chay2 = 0 then chay2:=-1; end;
end; {9:3:19}
for i:=4 to 19 do begin

if (banh2=i) and (banh1=66) then begin
chay1:=-1;
randomize;
chay2:=random(3); {neu banh dung tuong phai}
if chay2 = 1 then chay2:=+1;
if chay2 = 2 then chay2:=-1;
if chay2 = 3 then chay2:=+1;
if chay2 = 0 then chay2:=-1;end;
end;
for i:=9 to 66 do begin
if (banh1<>can1) and (banh1<>can1+1) and (banh1<>can1+2) and (banh1<>can1+3) then begin
if (banh2=19) and (banh1=i) then begin
delay(60000);
delay(60000);
mang:=mang-1; {neu banh dung day}
gotoxy(10,12);
write('Ban bi mat mot mang/ bam ENTER de choi tiep ');
gotoxy(10,13);
write('Nhan ESC de thoat ');
chon:=Getkey;
gotoxy(10,12);
write(' ');
gotoxy(10,13);
write(' ');
gotoxy(5,25);
write(' ');
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(5,24);
write(' ');
gotoxy(5,24);
write('Diem : ',diem);
if chon=enterkey then goto top;
if chon=Esckey then exit;
if chon=rightkey then goto top;
if chon=leftkey then goto top;
if chon=upkey then goto top;
if chon=dnkey then goto top;
end;
end;
end;



if mang = -1 then begin
gotoxy(10,12);
write('GAME OVER/Nhan Esc de thoat , nhan Space de choi tiep');
gotoxy(10,13);
write('Diem cua ban : ',diem);
chon:=getkey;
gotoxy(10,12);
write(' ');
gotoxy(10,13);
write(' ');
if chon=esckey then exit;
if chon=spacekey then begin
mang:=3;
diem:=0;
gotoxy(5,25);
write(' '); {diem :24,5 / mang:25,5}
gotoxy(5,25);
write('Mang : ',mang);
gotoxy(5,24);
write('Diem : ',diem);
goto top;
end;
end;
until (phim=esckey);
end;

begin
banh;
can1:=39; { CT chinh }
can2:=19;
gotoxy(can1,can2); {in can}
write('MMMM');
chaybanh;

clrscr;
gotoxy(20,5);
write('GAME OVER /nhan Enter de thoat');
gotoxy(20,6);
write('Diem cua ban : ',diem);
readln;
end.

 

sao code chạy trong pascal báo lỗi vậy



#13
phile1290

phile1290

    Lính mới

  • Thành viên mới
  • 3 Bài viết

code bị lỗi bạn ơi






2 người đang xem chủ đề

0 thành viên, 2 khách, 0 thành viên ẩn danh