viết chương trình dùng 4 phím mũi tên điều khiển cái máy bay có dạng =|-
2 câu trả lời
uses crt;
var kt: char;
x,y,mau:byte;
i: longint;
begin
clrscr;
x:=10;
y:=10;
gotoxy (x,y);
writeln ('=|-');
repeat
{ randomize;
mau:=random (17);
if mau=0 then
mau:=random (17);
textcolor (mau); }
if keypressed then
kt:=readkey;
if kt=#72 then {len}
begin
y:=y-1;
clrscr;
gotoxy (x,y);
writeln ('=|-');
delay (100);
end;
if kt=#80 then {xuong}
begin
y:=y+1;
clrscr;
gotoxy (x,y);
writeln ('=|-');
delay (100);
end;
if kt=#77 then {phai}
begin
x:=x+1;
clrscr;
gotoxy (x,y);
writeln ('=|-');
delay (50);
end;
if kt=#75 then {trai}
begin
x:=x-1;
clrscr;
gotoxy (x,y);
writeln ('=|-');
delay (50);
end;
if x=78 then
begin
delay (7);
x:=1;
end;
if y=25 then
begin
delay (7);
y:=1;
end;
until kt=#27;
if kt=#27 then halt(1);
readln;
end.
uses crt;
var x,y:longint; k:string;
begin
clrscr;
x:=10; y:=10;
repeat
if keypressed then k:=readkey;
if (k='w')and(y<>0) then
begin
dec(y);
clrscr;
gotoxy(x,y);
write('=|-');
delay(100);
end;
if (k='a')and(x<>0) then
begin
dec(x);
clrscr;
gotoxy(x,y);
write('-|=');
delay(100);
end;
if (k='d') then
begin
inc(x);
clrscr;
gotoxy(x,y);
write('=|-');
delay(100);
end;
if (k='s') then
begin
inc(y);
clrscr;
gotoxy(x,y);
write('=|-');
delay(100);
end;
if k=#27 then break;
until 1=2;
readln
end.