title: Connect four - finding the winning Processing (Java)
body: <p>I'm building a connect 4 game using Processing (Java) and have come to a holt when trying to find the winner. I've posted the code could anyway tell me why this isn't working? or how I would remedy it.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks</p>
  
  <pre><code>  if (whooseWon() == true) {
      text = loadFont("Tahoma-Bold-50.vlw");
      textFont(text, 50);
      fill(255, 0, 0);
      game = false;
      if (whoWon == 1) {
        text("Red Wins!", width/4, height/4);
        text("Click to play again", 110, height/2);
      } else if (whoWon == 2) {
        fill(255, 255, 0);
        text("yellow Wins!", width/4, height/4);
        text("Click to play again", 110, height/2);
      } else if (whoWon == 3) {
        fill(255, 255, 0);
        text("It's a Tie", width/4, height/4);
        text("Click to play again", 110, height/2);
        }
        }
        }
        // click to play again functionality
        void mousePressed() {
        if (game == false) {
        game = true;
        setup();
         } 
        }
  
       // 21 vertical possibilities, 24 horizontal and 12 diagonally that's a       total of 69 possibilities
  // cols = j
  // rows = i
       boolean whooseWon() {
    // horizontal
       for (int i = 0; i &lt; rows-3; i++) {
       for (int j = 0; j &lt; cols; j++) {
        //red player
        if (piece[i+1][j].getColour() == color(counter1)  &amp;&amp; piece[i+1].    [j].getColour() == color(counter1) &amp;&amp; 
          piece[i+2][j].getColour() == color(counter1) &amp;&amp; piece[i+3][j].getColour() == color(counter1))
        {
          whoWon = 1;
          return true;
        }
        if (piece[i][j].getColour() == color(counter2)  &amp;&amp; piece[i+1][j].getColour() == color(counter2) &amp;&amp; 
          piece[i+2][j].getColour() == color(counter2) &amp;&amp; piece[i+3][j].getColour() == color(counter2))
        {
          whoWon = 2;
          return true;
        }
      }
    }
    // vertical
  
    for (int i = 0; i &lt; rows; i++) {
      for (int j = 0; j &lt; cols-3; j++) {
  
        //red player
        if (piece[i][j].getColour() == color(counter1)  &amp;&amp; piece[i][j+1].getColour() == color(counter1) &amp;&amp; 
          piece[i][j+2].getColour() == color(counter1) &amp;&amp; piece[i][j+3].getColour() == color(counter1))
        {
          whoWon = 1;
          return true;
        }
        if (piece[i][j].getColour() == color(counter2)  &amp;&amp; piece[i][j+1].getColour() == color(counter2) &amp;&amp; 
          piece[i][j+2].getColour() == color(counter2) &amp;&amp; piece[i][j+3].getColour() == color(counter2))
        {
          whoWon = 2;
          return true;
        }
      }
    }
    //diagonal
    for (int i = 0; i &lt; rows-3; i++) {
      for (int j = 0; j &lt; cols-3; j++) {
        //red player
        if (piece[i][j].getColour() == color(counter1)  &amp;&amp; piece[i+1][j+1].getColour() == color(counter1) &amp;&amp; 
          piece[i+2][j+2].getColour() == color(counter1) &amp;&amp; piece[i+3][j+3].getColour() == color(counter1))
        {
          whoWon = 1;
          return true;
        }
        if (piece[i][j].getColour() == color(counter2)  &amp;&amp; piece[i+1][j+1].getColour() == color(counter2) &amp;&amp; 
          piece[i+2][j+2].getColour() == color(counter2) &amp;&amp; piece[i+3][j+3].getColour() == color(counter2))
        {
          whoWon = 2;
          return true;
        }
      }
    }
    //diagonal
    for (int i = 0; i &lt; rows-3; i++) {
      for (int j = 0; j &lt; cols; j++) {
        //red player
        if (piece[i][j].getColour() == color(counter2)  &amp;&amp; piece[i+1]
  [j-1].getColour() == color(counter2) &amp;&amp; 
          piece[i+2][j-2].getColour() == color(counter2) &amp;&amp; piece[i+3]
  [j-3].getColour() == color(counter2))
        {
          whoWon = 1;
          return true;
        }
        if (piece[i][j].getColour() == color(counter2)  &amp;&amp; piece[i+1].   [j+1].getColour() == color(counter2) &amp;&amp; 
          piece[i+2][j-2].getColour() == color(counter2) &amp;&amp; piece[i+3]
  [j-3].getColour() == color(counter2))
            {
              whoWon = 2;
              return true;
            }
          }
        }
       return false;
      }
  
  
  `
  </code></pre>