Ejemplo que genera burbujas y se van reproduciendo segun condiciones
pascal:
program ejemplo2;
uses crt,graph;
{$R+}
type
sentido = (arr,aba,izq,der);
burbuja = object
private
color,fil,col:integer;
tam:word;
public
procedure ponColor(deQueColor:integer);virtual;
function tenColor:integer;virtual;
procedure moverxy(x,y:integer);virtual;
procedure mover(haciaDonde:sentido);virtual;
procedure moverConPendiente(factorX,factorY,PixRecorridos:integer;signo:boolean);virtual;
constructor creaBurbuja(coleur,filx,coly,size:integer);
destructor limpiaBurbuja(size,filx,coly:integer);
end;
ptrBurbuja = ^burbuja;
{**************************************}
var
B1,B2,B3,B4 : ptrBurbuja;
fondo,gd,gm,i,j:integer;
{******************************************************************}
constructor burbuja.creaBurbuja(coleur,filx,coly,size:integer);
begin
color:=coleur;
setColor(color);
fil:=filx;
col:=coly;
tam:=size;
circle(fil,col,tam);
end;
destructor burbuja.limpiaBurbuja;
begin
setColor(fondo);
circle(fil,col,tam);
end;
procedure burbuja.ponColor(deQueColor:integer);
begin
color:=deQueColor
end;
function burbuja.tenColor:integer;
begin
tenColor:=color
end;
procedure burbuja.moverxy(x,y:integer);
begin
SetColor(fondo);
circle(fil,col,tam);
fil := x;
col := y;
SetColor(color);
circle(fil,col,tam);
end;
procedure burbuja.moverConPendiente(factorX,factorY,PixRecorridos:integer;signo:boolean);
var i:integer;
begin
for i:=1 to pixRecorridos do
begin
setColor(fondo);
circle(fil,col,tam);
setColor(color);
if(signo) then
begin
fil := fil + factorX;
col := col + factorY;
circle(fil,col,tam);
end
else
begin
fil := fil - factorX;
col := col - factorY;
circle(fil,col,tam)
end;
delay(50);
end;
end;
procedure burbuja.mover(haciaDonde:sentido);
var a:String[10];
begin
SetColor(fondo);
str(fil,a);
circle(fil,col,tam);
if(haciaDonde=der) then
fil := fil+1;
if(haciaDonde=izq) then
fil := fil-10;
if(haciaDonde=aba) then
col := col+10;
if(haciaDonde=arr) then
col := col-10;
SetColor(color);
str(fil,a);
circle(fil,col,tam);
end;
PROCEDURE MAPA;
begin
SetColor(green);
end;
BEGIN
gd:=Detect;
InitGraph(gd,gm,'C:\lengua\BGI');
if GraphResult <> GrOk then halt(1);
fondo:=white;
setBKcolor(fondo);
mapa;
new(B1,creaBurbuja(yellow,200,100,50));
{B1.creaBurbuja(yellow,200,100,50);}
readkey;
B1^.mover(aba);
readkey;
new(B2,creaBurbuja(red,200,200,50));
{B2.creaBurbuja(red,200,200,50);}
readkey;
for i := 1 to 200 do
BEGIN
DELAY(15);
B2^.mover(der)
END;
B2^.moverConPendiente(3,4,200,false);
readkey;
dispose(B1);
dispose(B2);
END.
uses crt,graph;
{$R+}
type
sentido = (arr,aba,izq,der);
burbuja = object
private
color,fil,col:integer;
tam:word;
public
procedure ponColor(deQueColor:integer);virtual;
function tenColor:integer;virtual;
procedure moverxy(x,y:integer);virtual;
procedure mover(haciaDonde:sentido);virtual;
procedure moverConPendiente(factorX,factorY,PixRecorridos:integer;signo:boolean);virtual;
constructor creaBurbuja(coleur,filx,coly,size:integer);
destructor limpiaBurbuja(size,filx,coly:integer);
end;
ptrBurbuja = ^burbuja;
{**************************************}
var
B1,B2,B3,B4 : ptrBurbuja;
fondo,gd,gm,i,j:integer;
{******************************************************************}
constructor burbuja.creaBurbuja(coleur,filx,coly,size:integer);
begin
color:=coleur;
setColor(color);
fil:=filx;
col:=coly;
tam:=size;
circle(fil,col,tam);
end;
destructor burbuja.limpiaBurbuja;
begin
setColor(fondo);
circle(fil,col,tam);
end;
procedure burbuja.ponColor(deQueColor:integer);
begin
color:=deQueColor
end;
function burbuja.tenColor:integer;
begin
tenColor:=color
end;
procedure burbuja.moverxy(x,y:integer);
begin
SetColor(fondo);
circle(fil,col,tam);
fil := x;
col := y;
SetColor(color);
circle(fil,col,tam);
end;
procedure burbuja.moverConPendiente(factorX,factorY,PixRecorridos:integer;signo:boolean);
var i:integer;
begin
for i:=1 to pixRecorridos do
begin
setColor(fondo);
circle(fil,col,tam);
setColor(color);
if(signo) then
begin
fil := fil + factorX;
col := col + factorY;
circle(fil,col,tam);
end
else
begin
fil := fil - factorX;
col := col - factorY;
circle(fil,col,tam)
end;
delay(50);
end;
end;
procedure burbuja.mover(haciaDonde:sentido);
var a:String[10];
begin
SetColor(fondo);
str(fil,a);
circle(fil,col,tam);
if(haciaDonde=der) then
fil := fil+1;
if(haciaDonde=izq) then
fil := fil-10;
if(haciaDonde=aba) then
col := col+10;
if(haciaDonde=arr) then
col := col-10;
SetColor(color);
str(fil,a);
circle(fil,col,tam);
end;
PROCEDURE MAPA;
begin
SetColor(green);
end;
BEGIN
gd:=Detect;
InitGraph(gd,gm,'C:\lengua\BGI');
if GraphResult <> GrOk then halt(1);
fondo:=white;
setBKcolor(fondo);
mapa;
new(B1,creaBurbuja(yellow,200,100,50));
{B1.creaBurbuja(yellow,200,100,50);}
readkey;
B1^.mover(aba);
readkey;
new(B2,creaBurbuja(red,200,200,50));
{B2.creaBurbuja(red,200,200,50);}
readkey;
for i := 1 to 200 do
BEGIN
DELAY(15);
B2^.mover(der)
END;
B2^.moverConPendiente(3,4,200,false);
readkey;
dispose(B1);
dispose(B2);
END.