• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Requesting help in Java

Status
Not open for further replies.
Right now, I'm doing an ongoing project to create a working checkers game (no AI though). Right now I'm drawing the board, and the checkers on them. I have these two methods.

private Point topLeft;
private Color shadedSquare;
private Checker[][] board;
private static final int SQUARE_SIZE = 40;
private static final int BOARD_SIZE = 8;

private void drawGrid (Graphics g)
{
for (int col = 0; col < BOARD_SIZE; col++){
for (int row = 0; row < BOARD_SIZE; row++){
if ((row +col)%2 != 0){
g.setColor (shadedSquare);
g.fillRect(topLeft.x+row*SQUARE_SIZE,topLeft.y+col*SQUARE_SIZE,SQUARE_SIZE,SQUARE_SIZE);
}
else {
g.setColor (Color.white);
g.fillRect(topLeft.x+row*SQUARE_SIZE,topLeft.y+col*SQUARE_SIZE,SQUARE_SIZE,SQUARE_SIZE);
}
}
}
}

public void draw (Graphics g){


}

In my draw method, when finished, it will ask the drawGrid method to run, and then it will check the board array, and whenever a square is not null, it will ask my checker class to draw a checker centered there. My question is, what is the statement so when I run the draw method, that the drawGrid method is also ran?

If need more information I can give it.
 

Pochacco

asking dangerous questions
My question is, what is the statement so when I run the draw method, that the drawGrid method is also ran?
I don't quite understand.
But if you want drawGrid() to be executed at the end of draw(), all you have to do is make a call to drawGrid() in the draw() method.

e.g.

public void draw (Graphics g)
{
// FILL-IN: draw the checker pieces

this.drawGrid(g); // draw the grid by coloring it
}
 
Status
Not open for further replies.
Top Bottom