Question: Can you please add comments with // to explain what the code is doing thank you. This is connect 4 and part of the code

Can you please add comments with // to explain what the code is doing thank you. This is connect 4 and part of the code

public int dropP(int cc) { int cr = grid.length-1; while(cr>=0){ if(grid[cr][cc].equals(Color.white)){ return cr; } cr--; } return -1;

} public void mouseReleased(MouseEvent e) {

} public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) { reset(); }

public void mouseClicked(MouseEvent e) {

} //Checking for winner public boolean checkForWinner(int cc,int cr, Color c){ //checking left and right int xStart = cc; int count = 1; //checking left xStart--; while(xStart>=0) { if(grid[cr][xStart].equals(c)) { count++; } else { break; } if(count==4) return true; xStart--; }

//checking right xStart = cc; xStart++; while(xStart

if(grid[cr][xStart].equals(c)) { count++; } else { break; } if(count==4) return true; xStart++; }

//checking up count = 1; int yStart = cr; yStart--; while(yStart>0) { if(grid[yStart][cc].equals(c)) { count++; } else { break; } if(count==4) return true; yStart--; }

yStart = cr; yStart++; while(yStart

if(grid[yStart][cc].equals(c)){

count++; }else{ break; } if(count==4) return true; yStart++; }

//checking diagonal count = 1; yStart = cr; xStart = cc; xStart--; yStart--; while(yStart>0 && xStart>0) { if(grid[yStart][xStart].equals(c)) { count++; } else { break; } if(count==4) return true; yStart--; xStart--; }

//checking diagonal yStart = cr; yStart++; xStart = cc; xStart++; while(yStart0) { if(grid[yStart][xStart].equals(c)) { count++; } else { break; } if(count==4) return true; yStart++; xStart--; }

//checking diagonal yStart = cr; yStart--; xStart = cc; xStart++; while(yStart>0 && xStart

return false; }

public void reset() { winner=false; turn=2; for (int row = 0; row < grid.length; row++) { for (int col = 0; col < grid[0].length; col++) { grid[row][col] = Color.white;

} } } } //Public bracket } //Public Class bracket

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!