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.
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.