Ver Mensaje Individual
  #7  
Antiguo 28-03-2013
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 922
Reputación: 23
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Te propongo este código...espero te sirva...

Código Delphi [-]
{
APos[Tag].X  =>Indice de la matriz
APos[Tag].Y  =>Indice de la matriz

Tag  Posicion Matriz
--------------------
1  =>matriz [1,1]
2  =>matriz [1,2]
3  =>matriz [1,3]
4  =>matriz [2,1]
5  =>matriz [2,2]
6  =>matriz [2,3]
7  =>matriz [3,1]
8  =>matriz [3,2]
9  =>matriz [3,3]

matriz [ APos[Tag].X, APos[Tag].Y ]
}

Const
    APos:Array[1..9] Of TPoint=((X:1; Y:1),(X:1;Y:2),(X:1;Y:3),(X:2;Y:1),(X:2;Y:2),(X:2;Y:3),(X:3;Y:1),(X:3;Y:2),(X:3;Y:3));
    {APos Vector con las coordenadas de x e y de la matriz...}
    Size_Matriz=3;
type
    TMatriz=array[1..Size_Matriz,1..Size_Matriz] of Integer;

var i, aux:Integer;
    matriz:TMatriz;
    no1, no2:Boolean;
    Key:Integer;

    function CheckHorizontal(Values:TMatriz; Key:Integer):Boolean;
    var
       i,j, Count:Integer;
    begin
         Result:=False;
         for i := 1 to Size_Matriz do
         begin
              Count:=0;
              for j:=1 to Size_Matriz do
              begin
                   If Values[i,j]=Key then
                      Inc(Count);
              end;

              Result:=Count=Size_Matriz;

              if Result then
                 Break;
         end;
    end;

    function CheckVertical(Values:TMatriz; Key:Integer):Boolean;
    var
       i,j, Count:Integer;
    begin
         Result:=False;
         for j := 1 to Size_Matriz do
         begin
              Count:=0;
              for i:=1 to Size_Matriz do
              begin
                   If Values[i,j]=Key then
                      Inc(Count);
              end;

              Result:=(Count=Size_Matriz);

              if Result then
                 Break;
         end;
    end;

    function CheckDiagonalPrincipal(Values:TMatriz; Key:Integer):Boolean;
    var
       i,j, Count:Integer;
    begin
         Result:=False;
         Count :=0;
         for i := 1 to Size_Matriz do
         begin
               { i,i coordenadas de la diagonal principal 1,1   2,2   3,3 }
               If Values[i,i]=Key then
                  Inc(Count);
         end;

         Result:=(Count=Size_Matriz);
    end;

    function CheckDiagonalSecundaria(Values:TMatriz; Key:Integer):Boolean;
    var
       i,j, Count:Integer;
    begin
         Result:=False;
         Count :=0;
         j:=1;
         for i := Size_Matriz downto 1 do
         begin
               { i,j coordenadas de la diagonal secundaria 3,1   2,2   1,3 }
               If Values[i,j]=Key then
                  Inc(Count);
               Inc(j);
         end;

         Result:=(Count=Size_Matriz);
    end;
begin
     aux:= aux+1;

     if (aux mod 2 <> 0) then
     begin
         (Sender as TImage).Picture:= Self.Image1.Picture;
         (Sender as TImage).Enabled:= False;

         Key:=1;
     end
     else
     begin
         (Sender as TImage).picture:= Self.Image2.Picture;
         (Sender as TImage).enabled:= False;

         Key:=2;
     end;

     //Asignas el valor 1 o 2 que esta en la Variable KEY (Integer)...
     Matriz[ APos[Tag].X, APos[Tag].Y]:= Key;

     For i := 248 downto 8 do
     begin
          sleep(1);
          refresh;
          shape1.Top:=i;
     end;

     //Check el valor de la matriz de acuerdo a el valor de Key
     if CheckHorizontal(matriz, Key) or
        CheckVertical(Matriz, Key) or
        CheckDiagonalPrincipal(Matriz, Key) Or
        CheckDiagonalSecundaria(Matriz, Key) then
     begin
           showmessage('Gana ' + label2.Caption);

           no1:=Key=1;
           no2:=Key=2;
     end;

Saludos cordiales
Responder Con Cita