Does anyone see the mistake in this code ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yves de Munck
    New Member
    • Mar 2011
    • 4

    Does anyone see the mistake in this code ?

    Hello there !

    I'm writing four in a row in csharp.
    It's almost done, the only problem is the control for when there actually is four in a row.

    I have vertical and horizontal working perfectly fine, diagonal from down-left to right up should work to.
    Only if i put in the code i found for left-up to downright, sometimes i get a random message that a player won.
    Does anyone see the mistake ?

    (the array is multidimensiona l --> arrCoins[7,6])

    Code:
            public int ControleOpEindeSpel(int Spelernummer)
            {
                //controle 4 op een rij
               int Teller = 0;
               int VierOpEenRij=0;
               x = 0;
               y = 0;
    
                //Verticaal
               for (x = 0; x <= 6; x++)
               {
                   for (y = 0; y <= 5; y++)
                   {
                       if (arrMunten[x, y] == Spelernummer)
                       {
                           Teller++;
                           if (Teller == 4)
                           { VierOpEenRij = 1; }
                       }
                       else { Teller = 0; }
                   }
               }
    
               Teller = 0;
               x = 0;
               y = 0;
    
               //horizontaal
    
               for (y = 0; y <= 5; y++)
               {
                   for (x = 0; x <= 6; x++)
                   {
                       if (arrMunten[x, y] == Spelernummer)
                       {
                           Teller++;
                           if (Teller == 4)
                           { VierOpEenRij = 1; }
                       }
                       else { Teller = 0; }
                   }
               }
               //diagonaal links onder naar rechts boven
    
               int xTellerlr = 0;
               int yTellerlr = 0;
               Teller = 0;
                
               for (xTellerlr = 0; xTellerlr <= 6; xTellerlr++)
               { for (yTellerlr = 0; yTellerlr <= 5; yTellerlr++)
                   { for (x = xTellerlr; x <= 6; x++)
                       { for (y = yTellerlr; y <= 5; y++)
                           { if (arrMunten[x, y] == Spelernummer)
                               {  Teller++;
                                   if (Teller == 4)
                                   { VierOpEenRij = 1; }
                               }
                               else { Teller = 0; }
                               if (x < 6)
                               {
                                   x++;
                               }
                           }
                       }
                   }
               }
    
               ////Diagonaal links boven naar rechts onder
    
               //xTellerlr = 0;
               //yTellerlr = 0;
               //Teller = 0;
    
               //for (xTellerlr = 6; xTellerlr > 2 ; xTellerlr--)
               //{
               //    for (x = xTellerlr; x > 2; x--)
               //    {
               //    for (yTellerlr = 0; yTellerlr < 3; yTellerlr++)
               //    {
    
               //            for (y = yTellerlr; y <= 5; y++)
               //            {
               //                if (arrMunten[x, y] == Spelernummer)
               //                {
               //                    Teller++;
               //                    if (Teller == 4)
               //                    { VierOpEenRij = 1; }
               //                }
               //                else { Teller = 0; }
               //                if (x > 0)
               //                {
               //                    x--;
               //                }
               //            }
    
               //        }
               //    }
               //}
    (the part that doesn't work is left out with '//')

    I'm searching for this problem over 5 hours. I really hope somebody can help me.

    Thanks
Working...