1
0
Fork 0

Breakout Aufgabe 1.5

This commit is contained in:
rxbn 2019-11-19 14:38:12 +01:00
parent f0c323beef
commit 82987f4710
1 changed files with 20 additions and 1 deletions

View File

@ -96,7 +96,10 @@ public class Field extends JPanel {
g2.setColor(new Color(200, 200, 200));
// Calls the method for drawing the ball
drawBall(g2);
drawBall(g2);
// Calls the method for drawing the grid
drawGrid(g2);
}
@ -111,4 +114,20 @@ public class Field extends JPanel {
Constants.BALL_DIAMETER);
}
/**
* Draws the grid
* @param g2 The graphics object
*/
private void drawGrid(Graphics2D g2) {
// vertical lines
for(int i = 1 ; i < Math.round(Constants.SCREEN_WIDTH/Constants.SQUARES_X); i++) {
g2.drawLine(i*Constants.SQUARES_X, 0, i*Constants.SQUARES_X, Constants.SCREEN_HEIGHT);
}
// horizontal lines
for(int i = 1 ; i < Math.round(Constants.SCREEN_HEIGHT/Constants.SQUARES_Y); i++) {
g2.drawLine(0, i*Constants.SQUARES_Y, Constants.SCREEN_WIDTH, i*Constants.SQUARES_Y);
}
}
}