Vladimir_S |
10.04.2011 12:38 |
Ну вот Вам Ваша игрушка, как обещал:
Код:
uses CRT, graph;
VAR
X,Y:Integer;
R,Xmax,Ymax,Ytxt:Word;
Col,Fig_Tp,Tp_Old:Byte;
Ch:Char;
Procedure Figure(Tf,Cl:Byte;Xf,Yf:Integer;Rf:Word);
begin
SetFillStyle(1,Cl);
If Tf=0 then
begin
SetColor(Cl);
FillEllipse(Xf,Yf,Rf,Rf);
end
else
Bar((Xf-Rf),(Yf-(Rf div 2)),(Xf+Rf),(Yf+(Rf div 2)));
end;
Function B:Boolean;
begin
If Fig_Tp=0 then
B:=((X-R)>=0) and ((X+R)<=Xmax) and ((Y+R)<=Ymax) and ((Y-R)>=0)
else
B:=((X-R)>=0) and ((X+R)<=Xmax)
and ((Y+(R div 2))<=Ymax) and ((Y-(R div 2))>=0);
end;
BEGIN
InitGraph( ); {ПАРАМЕТРЫ ПРОЦЕДУРЫ InitGraph ЗАДАЙТЕ САМОСТОЯТЕЛЬНО!!!}
Randomize;
ClearDevice;
Xmax:=GetMaxX;
Ymax:=GetMaxY-80;
Ytxt:=GetMaxY-72;
SetBkColor(0);
SetColor(white);
SetTextStyle(DefaultFont,HorizDir,1);
SetTextJustify(LeftText,CenterText);
OutTextXY(0,Ytxt,'Keys (latin keyboard only!):');
OutTextXY(0,Ytxt+16,'Arrow Up');
OutTextXY(0,Ytxt+32,'Arrow Left');
OutTextXY(0,Ytxt+48,'Arrow Down');
OutTextXY(0,Ytxt+64,'Arrow Right');
OutTextXY((Xmax div 2),Ytxt,'T - change figure type');
OutTextXY((Xmax div 2),Ytxt+16,'C - change color');
OutTextXY((Xmax div 2),Ytxt+32,'+ - increase the size');
OutTextXY((Xmax div 2),Ytxt+48,'- - decrease the size');
OutTextXY((Xmax div 2),Ytxt+64,'Esc - quit');
Fig_Tp:=0;
X:=320;
Y:=240;
R:=60;
Col:=4;
Figure(Fig_Tp,Col,X,Y,R);
Repeat
Ch:=ReadKey;
If Ch=#72 then
begin
Y:=Y-2;
if b then
begin
Figure(Fig_Tp,0,X,Y+2,R);
Figure(Fig_Tp,Col,X,Y,R)
end else Y:=Y+2;
end else
If (Ch=#75) then
begin
X:=X-2;
If b then
begin
Figure(Fig_Tp,0,X+2,Y,R);
Figure(Fig_Tp,Col,X,Y,R);
end else X:=X+2;
end else
If Ch=#80 then
begin
Y:=Y+2;
If b then
begin
Figure(Fig_Tp,0,X,Y-2,R);
Figure(Fig_Tp,Col,X,Y,R);
end else Y:=Y-2;
end else
If Ch=#77 then
begin
X:=X+2;
If b then
begin
Figure(Fig_Tp,0,X-2,Y,R);
Figure(Fig_Tp,Col,X,Y,R);
end else X:=X-2;
end else
If (Ch='T') or (Ch='t') then
begin
Tp_Old:=Fig_Tp;
Figure(Fig_Tp,0,X,Y,R);
If Fig_Tp=0 then Fig_Tp:=1 else Fig_Tp:=0;
If b then
Figure(Fig_Tp,Col,X,Y,R)
else
begin
Fig_Tp:=Tp_Old;
Figure(Fig_Tp,Col,X,Y,R)
end;
end else
If (Ch='C') or (Ch='c') then
begin
Figure(Fig_Tp,0,X,Y,R);
Col:=Random(15)+1;
Figure(Fig_Tp,Col,X,Y,R);
end else
If Ch='+' then
begin
R:=R+2;
If b then
begin
Figure(Fig_Tp,0,X,Y,R-2);
Figure(Fig_Tp,Col,X,Y,R);
end else R:=R-2;
end else
If Ch='-' then
begin
R:=R-2;
If R>=2 then
begin
Figure(Fig_Tp,0,X,Y,R+2);
Figure(Fig_Tp,Col,X,Y,R);
end else R:=R+2;
end else
If Ch=#27 then
begin
CloseGraph;
HALT(0);
end;
Until 0=1;
END.
|