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.
Mới học pascal nên làm làm thử game lấy cảm hứng, toàn dùng code cơ bản nên cũng hơi dài dòng văn tự.
Lấy ý tưởng game khủng long khi mất mạng, mình rảnh tạo game tương tự(mỗi tội ko biết dùng đồ họa nên thay con khủng long bằng cục gạch và hình cũng hơi cùi)
minh compile trên turbo pascal có một số lỗi như lệch điểm,dừng hình nên mình cho nó vào {} nếu muốn test thì xóa nó đi ạ
code nè:
uses crt,dos;
var x,z,b,diem,k,l,j:shortint;
const x1=1;y1=1;x2=45;y2=23;a=10;
procedure viet(x,y:integer;c:string);
begin gotoxy(x,y);write(c);end;
procedure mode;
var i:integer;
begin
textcolor(lightgreen);
viet(x1,y1,#201);viet(x2,y1,#187);viet(x1,y2,#200);viet(x2,y2,#188);
for i:=x1+1 to x2-1 do begin viet(i,y1,#205);viet(i,y2,#205);end;
for i:=y1+1 to y2-1 do begin viet(x1,i,#186);viet(x2,i,#186);end;
viet(49,4,'An phim S de tam dung');viet(49,6,'An phim E de ket thuc');viet(49,8,'An phim W de nhay.');
for i:=2 to 44 do begin viet(i,10,#31);viet(i,9,#219);viet(i,21,#176);viet(i,22,#176);end;
textcolor(lightcyan);gotoxy(10,3);write('So diem hien tai: ',diem);
end;
procedure cursoroff;
var regs:registers;
begin
regs.ah:=$01;regs.cl:=3;regs.ch:=$20;
intr($10,regs);
end;
procedure cnv(x:integer;c:string);
var y:integer;
begin
for y:=20 downto 19 do begin gotoxy(x,y);write(c);END;
end;
BEGIN
clrscr;randomize;
textmode(co40);textbackground(brown);
viet(5,10,'GAME MADE BY NGUYEN THU HIEU');
cursoroff;delay(2000);
textmode(40);textbackground(black);
textcolor(lightgray);
viet(34,12,'TEST GAME CO BAN');
textcolor(lightmagenta);
viet(15,13,'********************************************************');
textcolor(white);
viet(20,15,'An Alt+Enter neu muon choi full man hinh ^^');
viet(13,16,'Cach choi: An W de nhay tranh chuong ngai vat, an S de tam dung');cursoroff;
viet(30,17,'An ENTER de tiep tuc');cursoroff;readln;
clrscr;
textmode(40);textcolor(yellow);cursoroff;
viet(15,5,#177);viet(15,6,#177);viet(15,7,#177);viet(16,7,#177);delay(500);
viet(19,5,#177#177#177);viet(19,6,#177#32#177);viet(19,7,#177#177#177);delay(500);
viet(25,5,#177);viet(24,6,#177#22#177);viet(24,7,#177#32#177);delay(500);
viet(29,5,#177#177);viet(29,6,#177#32#177);viet(29,7,#177#177);delay(500);
viet(34,5,#177);viet(34,6,#177);viet(34,7,#177);delay(500);
viet(37,5,#177#32#177);viet(37,6,#177#92#177);viet(37,7,#177#32#177);delay(500);
viet(42,5,#177#177#177);viet(42,6,#177#45#176#45);viet(42,7,#177#177#177);delay(500);
viet(48,7,#177);delay(200);viet(50,7,#177);delay(200);viet(52,7,#177);delay(200);
clrscr;mode;viet(23,13,'An ENTER de bat dau choi');cursoroff;readln;clrscr;
z:=0;b:=20;viet(a,b,#178#178); x:=40;l:=50;k:=6;j:=1;
repeat
while not keypressed do
begin
while (not keypressed) and (x>1) do
begin
delay(l);gotoxy(23,13);write(' ');
mode;viet(a,20,#178#178);
if b<>20 then begin inc(b);viet(a,b,#178#178);viet(a,b-1,#32#32);viet(a-1,20,#32#32#32#32#32#32);end;
if b=20 then viet(a,20,#178#178);viet(a-1,20,#32);
dec(x,j);cnv(x,#219);cnv(x+j,#32);
if(a=x)or(x=a+1)then begin if b>19 then begin viet(30,13,'GAME OVER!!');sound(50);delay(100);nosound;delay(2000);exit;end;end;
end;
while x=abs(2-j) do begin mode; x:=40;diem:=diem+10;end;
end;
case upcase(readkey) of
'S':begin viet(23,13,'An Enter de tiep tuc');if upcase(readkey)='E' then exit else continue;readln;end;
'E':exit;
'W':begin viet(a,b,#32#32);cnv(x,#219);cnv(x+j,#32);dec(b,k);viet(a,b,#178#178);sound(500);delay(20);nosound;
end;
end;
if b<12 then begin viet(30,13,'GAME OVER!!');sound(50);delay(100);nosound;delay(2000);z:=1;end;
if diem=0 then viet(50,15,'EASY');
if diem=20 then begin viet(50,15,'STILL EASY');sound(500);delay(20);sound(1000);delay(30);nosound;dec(l,15);dec(k);end; {
if diem=40 then begin viet(50,15,'MEDIUM ');sound(500);delay(20);sound(1000);delay(30);nosound;j:=2;end; }
if diem=50 then begin viet(50,15,'HARD ');sound(500);delay(20);sound(1000);delay(30);nosound;j:=3;end;
if diem=80 then begin viet(50,15,'HARDER');sound(500);delay(20);sound(1000);delay(30);nosound;dec(k);end; {
if diem=110 then begin viet(50,15,'HARDEST');sound(40);textbackground(blue);end; }
if diem=140 then begin viet(50,15,'HAHAHAHA!!');
viet(50,17,'YOU SHOULD HAVE THE DOUBLE KICK ');nosound;textbackground(black);end;
until z<>0;
end.
Lấy ý tưởng game khủng long khi mất mạng, mình rảnh tạo game tương tự(mỗi tội ko biết dùng đồ họa nên thay con khủng long bằng cục gạch và hình cũng hơi cùi)
minh compile trên turbo pascal có một số lỗi như lệch điểm,dừng hình nên mình cho nó vào {} nếu muốn test thì xóa nó đi ạ
code nè:
uses crt,dos;
var x,z,b,diem,k,l,j:shortint;
const x1=1;y1=1;x2=45;y2=23;a=10;
procedure viet(x,y:integer;c:string);
begin gotoxy(x,y);write(c);end;
procedure mode;
var i:integer;
begin
textcolor(lightgreen);
viet(x1,y1,#201);viet(x2,y1,#187);viet(x1,y2,#200);viet(x2,y2,#188);
for i:=x1+1 to x2-1 do begin viet(i,y1,#205);viet(i,y2,#205);end;
for i:=y1+1 to y2-1 do begin viet(x1,i,#186);viet(x2,i,#186);end;
viet(49,4,'An phim S de tam dung');viet(49,6,'An phim E de ket thuc');viet(49,8,'An phim W de nhay.');
for i:=2 to 44 do begin viet(i,10,#31);viet(i,9,#219);viet(i,21,#176);viet(i,22,#176);end;
textcolor(lightcyan);gotoxy(10,3);write('So diem hien tai: ',diem);
end;
procedure cursoroff;
var regs:registers;
begin
regs.ah:=$01;regs.cl:=3;regs.ch:=$20;
intr($10,regs);
end;
procedure cnv(x:integer;c:string);
var y:integer;
begin
for y:=20 downto 19 do begin gotoxy(x,y);write(c);END;
end;
BEGIN
clrscr;randomize;
textmode(co40);textbackground(brown);
viet(5,10,'GAME MADE BY NGUYEN THU HIEU');
cursoroff;delay(2000);
textmode(40);textbackground(black);
textcolor(lightgray);
viet(34,12,'TEST GAME CO BAN');
textcolor(lightmagenta);
viet(15,13,'********************************************************');
textcolor(white);
viet(20,15,'An Alt+Enter neu muon choi full man hinh ^^');
viet(13,16,'Cach choi: An W de nhay tranh chuong ngai vat, an S de tam dung');cursoroff;
viet(30,17,'An ENTER de tiep tuc');cursoroff;readln;
clrscr;
textmode(40);textcolor(yellow);cursoroff;
viet(15,5,#177);viet(15,6,#177);viet(15,7,#177);viet(16,7,#177);delay(500);
viet(19,5,#177#177#177);viet(19,6,#177#32#177);viet(19,7,#177#177#177);delay(500);
viet(25,5,#177);viet(24,6,#177#22#177);viet(24,7,#177#32#177);delay(500);
viet(29,5,#177#177);viet(29,6,#177#32#177);viet(29,7,#177#177);delay(500);
viet(34,5,#177);viet(34,6,#177);viet(34,7,#177);delay(500);
viet(37,5,#177#32#177);viet(37,6,#177#92#177);viet(37,7,#177#32#177);delay(500);
viet(42,5,#177#177#177);viet(42,6,#177#45#176#45);viet(42,7,#177#177#177);delay(500);
viet(48,7,#177);delay(200);viet(50,7,#177);delay(200);viet(52,7,#177);delay(200);
clrscr;mode;viet(23,13,'An ENTER de bat dau choi');cursoroff;readln;clrscr;
z:=0;b:=20;viet(a,b,#178#178); x:=40;l:=50;k:=6;j:=1;
repeat
while not keypressed do
begin
while (not keypressed) and (x>1) do
begin
delay(l);gotoxy(23,13);write(' ');
mode;viet(a,20,#178#178);
if b<>20 then begin inc(b);viet(a,b,#178#178);viet(a,b-1,#32#32);viet(a-1,20,#32#32#32#32#32#32);end;
if b=20 then viet(a,20,#178#178);viet(a-1,20,#32);
dec(x,j);cnv(x,#219);cnv(x+j,#32);
if(a=x)or(x=a+1)then begin if b>19 then begin viet(30,13,'GAME OVER!!');sound(50);delay(100);nosound;delay(2000);exit;end;end;
end;
while x=abs(2-j) do begin mode; x:=40;diem:=diem+10;end;
end;
case upcase(readkey) of
'S':begin viet(23,13,'An Enter de tiep tuc');if upcase(readkey)='E' then exit else continue;readln;end;
'E':exit;
'W':begin viet(a,b,#32#32);cnv(x,#219);cnv(x+j,#32);dec(b,k);viet(a,b,#178#178);sound(500);delay(20);nosound;
end;
end;
if b<12 then begin viet(30,13,'GAME OVER!!');sound(50);delay(100);nosound;delay(2000);z:=1;end;
if diem=0 then viet(50,15,'EASY');
if diem=20 then begin viet(50,15,'STILL EASY');sound(500);delay(20);sound(1000);delay(30);nosound;dec(l,15);dec(k);end; {
if diem=40 then begin viet(50,15,'MEDIUM ');sound(500);delay(20);sound(1000);delay(30);nosound;j:=2;end; }
if diem=50 then begin viet(50,15,'HARD ');sound(500);delay(20);sound(1000);delay(30);nosound;j:=3;end;
if diem=80 then begin viet(50,15,'HARDER');sound(500);delay(20);sound(1000);delay(30);nosound;dec(k);end; {
if diem=110 then begin viet(50,15,'HARDEST');sound(40);textbackground(blue);end; }
if diem=140 then begin viet(50,15,'HAHAHAHA!!');
viet(50,17,'YOU SHOULD HAVE THE DOUBLE KICK ');nosound;textbackground(black);end;
until z<>0;
end.
Attachments
Last edited: