I have a problem, I get a "Dead Code" warning in Eclipse, and I really don't know why. The code from my Connect Four project, more precisely, from a class that checks to see if anyone has won. This method checks all the possibilities of horizontal gain for red. The code is as follows:
/** * Method to check the horizontal winning possibilities for red * @return true if red won or false if not */ public boolean checkHorRed(){ for(int line = 0; line < 6; line++) { for(int column = 0; column < 4; column++) { //column++ is underlined and causes the "dead Code" warning if(gw.buttons[line][column].getIcon().equals(gw.red)); if(gw.buttons[line][column+1].getIcon().equals(gw.red)); if(gw.buttons[line][column+2].getIcon().equals(gw.red)); if(gw.buttons[line][column+3].getIcon().equals(gw.red)); return true; } } return false; }
The game is even caused by the fact that it was immediately won because of this method. What is strange is that all the other methods in the class that look almost the same do not pose any problems. Here's a method that tests the vertical win opportunities for yellow, have a comparison:
public boolean checkVertYel(){ for(int line = 3; line < 6; line++) { for(int column = 0; column < 7; column++) { if(gw.buttons[line][column].getIcon().equals(gw.yellow)) if(gw.buttons[line-1][column].getIcon().equals(gw.yellow)) if(gw.buttons[line-2][column].getIcon().equals(gw.yellow)) if(gw.buttons[line-3][column].getIcon().equals(gw.yellow)) return true; } } return false; }
This does not cause any problems. Can someone tell me where the warning comes from? If you need more information, please let me know.
source share