Автор: Гость_Вадим 15.11.2004 0:49
В этой программе выводится в верхней части экрана движущийся "корабль" с постоянной скоростью. Ее значение каждый раз задается генератором случайных чисел. В нижней части экрана расположена пушка. При нажатии клавиши "Ввод" происходит выстрел "торпедой" с постоянной, заранее заданной скоростью клавишами от 0 до 9. При попадании имитировать "взрыв"и исчезновение "корабля". При промахе "корабль" достигает правой границы и начинает движение сначала с новой постоянной скоростью.
Как сделать, чтобы происходил поворот ствола "пушки" вправо и влево с помощью клавиш управления курсором???
Код
[code]uses
crt,graph;
var
t,k,p,i,p0,p1:integer;
x,y:longint;
dx,dt:real;
Driver,Mode:integer;
Flag:boolean;
s:string;
procedure korabl(dx:integer);
begin
line(dx,130,dx+60,130);
line(dx,130,dx+15,150);
line(dx+15,150,dx+45,150);
line(dx+45,150,dx+60,130);
line(dx+20,130,dx+30,110);
line(dx+30,110,dx+40,130);
end;
procedure Pushka(p:integer);
begin
line(p,479,p+30,450);
line(p+30,450,p+60,479);
end;
procedure Torp(dt,p:integer);
begin
p:=p+29;
rectangle(p,479-dt,p+3,479-(dt+15));
end;
procedure ch(c:char);
begin
if c=#27 then halt(1);
if c=#77 then p:=p+2;
if c=#75 then p:=p-2;
if c='+' then t:=t+10;
if c='-' then t:=t-10;
if c=#13 then
begin
flag:=true;
p1:=p;
end;
if p<0 then p:=0;
if p>639 then p:=639;
if t<50 then t:=50;
if t>500 then t:=500;
setcolor(0);
outtextxy(20,20,s);
setcolor(5);
str(t,s);
outtextxy(20,20,s);
end;
begin
Driver:=VGA;
Mode:=VGAHi;
InitGraph(Driver,Mode,'C:\BP\BGI');
randomize;
settextstyle(4,0,5);
t:=300;
y:=0;
k:=random(64)+64;
x:=0;
p:=320;
p0:=p;
dx:=0;
dt:=0;
s:='300';
outtextxy(20,20,s);
setcolor(5);
Pushka(p);
repeat
setcolor(0);
Korabl( trunc(dx));
dx:=x*k/100;
setcolor(5);
Korabl( trunc(dx));
inc(x);
if Flag then
begin
setcolor(0);
Torp( trunc(dt),p1);
dt:=y*t/100;
setcolor(5);
Torp( trunc(dt),p1);
inc(y);
end;
for i:=1 to 50 do
begin
delay(1);
if keypressed then
ch(readkey);
end;
if p0<>p then
begin
setcolor(0);
Pushka(p0);
setcolor(5);
Pushka(p);
p0:=p;
end;
if 479-(dt+15)<=150 then
begin
if ((p1+29>=dx+15) and (p1+29<=dx+45)) then
begin
for i:=1 to 7 do
begin
setcolor(i);
circle(p1+29,150,i*10);
end;
outtextxy(200,200,'B-----U-----M');
readkey;
halt(1);
end
else
begin
outtextxy(200,200,'M I S S');
readkey;
halt(1);
end;
end;
until trunc(dx)>=580;
readkey;
end.
Код надо заключать в теги !!!. GoodWind
Автор: virt 15.11.2004 16:03
Код
uses crt,graph;
var t,k,p,i,p0,p1:integer;
x,y:longint;
dx,dt:real;
Driver,Mode:integer;
Flag:boolean;
s:string;
bol,kill:boolean;
procedure korabl(dx:integer);
begin
line(dx,130,dx+60,130);
line(dx,130,dx+15,150);
line(dx+15,150,dx+45,150);
line(dx+45,150,dx+60,130);
line(dx+20,130,dx+30,110);
line(dx+30,110,dx+40,130);
end;
procedure Pushka(p:integer);
begin
line(p,479,p+30,450);
line(p+30,450,p+60,479);
end;
procedure Torp(dt,p:integer);
begin
p:=p+29;
rectangle(p,479-dt,p+3,479-(dt+15));
end;
procedure ch(cha:char);
var c:char;
begin
if cha=#0 then c:=readkey else c:=cha;
if c=#27 then halt;
if c=#77 then p:=p+3;
if c=#75 then p:=p-3;
if c='+' then t:=t+10;
if c='-' then t:=t-10;
if c=#13 then
begin
flag:=true;
p1:=p;
end;
if p<0 then p:=0;
if p>639 then p:=639;
if t<50 then t:=50;
if t>500 then t:=500;
setcolor(0);
outtextxy(20,20,s);
setcolor(5);
str(t,s);
outtextxy(20,20,s);
end;
begin
Driver:=VGA;
Mode:=VGAHi;
InitGraph(Driver,Mode,'');
randomize;
settextstyle(4,0,5);
t:=300;
y:=0;
k:=random(64)+64;
x:=10;
p:=320;
p0:=p;
dx:=0;
dt:=0;
bol:=false;
kill:=false;
s:='300';
outtextxy(20,20,s);
setcolor(5);
Pushka(p);
repeat
inc(x);
if Flag then
begin
setcolor(0);
Torp( trunc(dt),p1);
dt:=dt+5;
setcolor(5);
Torp( trunc(dt),p1);
inc(y);
end;
if keypressed then
ch(readkey);
if p0<>p then
begin
setcolor(0);
Pushka(p0);
setcolor(5);
Pushka(p);
p0:=p;
end;
if 479-(dt+15)<=150 then
begin
if ((p1+29>=dx+15) and (p1+29<=dx+45)) then
begin
for i:=1 to 7 do
begin
setcolor(i);
circle(p1+29,150,i*10);
end;
outtextxy(200,200,'B-----U-----M');
readkey;
halt(1);
end
else
begin
outtextxy(200,200,'M I S S');
p1:=-100;
dt:=0;
flag:=false;
end;
end;
delay(1000);
setcolor(0);
Korabl( trunc(dx));
if bol then
dx:=dx+2 else dx:=dx-2;
if dx <= 10 then bol:=true;
if dx >= 580 then bol:=false;
setcolor(5);
Korabl( trunc(dx));
until kill;
end.
вот так что-ли надо было? а вообче посмотри в прикрепленном файле там нечто подобное.