Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

7. Interrupt others when they are speaking?

Answered: 1 week ago