VCT làm game "sao băng" nhập số bước di chuyển sau đó đếm xem đươc bao nhiêu điểm game over
1 câu trả lời
uses crt;
var
ch: char;
x,y,m,xd,yd,diem: word;
xuat:string;
move,kt:real;
procedure dich;
begin
repeat
xd:=random(79); yd:=random(24);
until (xd>0) and (yd>0);
gotoxy(xd,yd); write('@');
end;
begin
repeat
clrscr;
gotoxy(23,10);
write('Nhap so buoc ban muon di chuyen: '); readln(kt);
until (kt>0) and (kt<10000000);
clrscr;
randomize;
x:=10;
y:=10;
move:=0;
diem:=0;
xuat:='*';
dich;
repeat
begin
clrscr;
if (x=xd) and (y=yd) then
begin
gotoxy(xd,yd); write(' ');
diem:=diem+1;
dich;
end;
gotoxy(x,y);
write(xuat);
gotoxy(1,1); write(move:3:0,' - ',diem); gotoxy(3,1);
gotoxy(75,25);write(x:2,',',y:2);
ch:=readkey;
move:=move+0.5;
gotoxy(x,y); write(' ');
if ord(ch)=72 then begin y:=y-1; if y<1 then y:=25; end;
if ord(ch)=80 then begin y:=y+1; if y>25 then y:=1; end;
if ord(ch)=75 then begin x:=x-1; if x<1 then x:=80; end;
if ord(ch)=77 then begin x:=x+1; if x>80 then x:=1; end;
{writeln(ch,' = ',ord(ch));}
if move=kt then
begin
clrscr;
gotoxy(23,10);
write('Sau ',move:3:0, ' buoc, so diem ban dat duoc: ',diem);
gotoxy(26,12);
write('Game over - nhan Enter de thoat');
readln;
exit;
end;
end;
until ord(ch)=27;
end.