yo no creas que soy muy experto pero mirandolo solo por encima lo minimo que puedes hacer es crear un procedimiento para las comprobaciones de quien gana, ya que poner esa parrafada 9 veces en el codigo.....puff
pones esto al principio despues de {$R *.dfm} y luego lo sustituyes la parrafada en todos lados por
quiengana;
Cita:
Procedure quiengana;
begin
if (j=1) or (j=3) or (j=5) or (j=7) or (j=9) then begin
lact.Caption:='Jugador 2' end
else
if (j=2) or (j=4) or (j=6) or (j=8) then begin
lact.Caption:='Jugador 1';
end
else
lact.Caption:='NINGUNO xD';
if (gato[1,1] AND (gato[2,1]) AND (gato[3,1]))=1 then begin
showmessage ('Ganan las 0'); juego:=false; end;
if (gato[1,2] AND gato[2,2] AND gato[3,2])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[1,3] AND gato[2,3] AND gato[3,3])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[1,1] AND gato[1,2] AND gato[1,3])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[2,1] AND gato[2,2] AND gato[2,3])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[3,1] AND gato[3,2] AND gato[3,3])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[1,1] AND gato[2,2] AND gato[3,3])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[1,3] AND gato[2,2] AND gato[3,1])=1 then begin
showmessage ('Ganan las 0'); juego:=false;end;
if (gato[1,1] AND gato[2,1] AND gato[3,1])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[1,2] AND gato[2,2] AND gato[3,2])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[1,3] AND gato[2,3] AND gato[3,3])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[1,1] AND gato[1,2] AND gato[1,3])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[2,1] AND gato[2,2] AND gato[2,3])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[3,1] AND gato[3,2] AND gato[3,3])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;;
if (gato[1,1] AND gato[2,2] AND gato[3,3])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
if (gato[1,3] AND gato[2,2] AND gato[3,1])=2 then begin
showmessage ('Ganan las x'); juego:=false;end;
end;
|
Con esto solo ya reduces el código a la mitad.
Lo mismo puedes hacer en todos sitios que veas que repites mucho codigo varias veces
Luego seguro se pueden hacer mas optimizaciones, pero....
Última edición por cocute fecha: 11-01-2010 a las 22:55:17.
|