📄 bricks.java
字号:
import objectdraw.*;import java.awt.*;// Class to draw a brick wallpublic class Bricks extends WindowController { // position and dimensions of the wall private static final double WALL_X = 20; private static final double WALL_Y = 250; private static final int WALL_HEIGHT = 7; private static final int WALL_WIDTH = 10; // dimensions of a brick private static final double BRICK_HEIGHT = 15 ; private static final double BRICK_WIDTH = 45; public void begin() { // initial x and y positions for drawing a brick double brickX = WALL_X; double brickY = WALL_Y; int level = 0; // number of levels drawn so far int bricksInLevel = 0; // number of bricks drawn in the current level while ( level < WALL_HEIGHT) { bricksInLevel = 0; brickX = WALL_X; // draw one row of bricks while (bricksInLevel < WALL_WIDTH) { new FilledRect(brickX, brickY, BRICK_WIDTH, BRICK_HEIGHT, canvas); new FramedRect(brickX, brickY, BRICK_WIDTH, BRICK_HEIGHT, canvas).setColor(Color.yellow); brickX = brickX + BRICK_WIDTH; bricksInLevel++; } brickY = brickY - BRICK_HEIGHT; level++; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -