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(yStart //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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started