-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrickBreaker.java
More file actions
executable file
·55 lines (44 loc) · 1.44 KB
/
BrickBreaker.java
File metadata and controls
executable file
·55 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Random;
public class BrickBreaker{
static JFrame frame = new JFrame();
static Brick bricks[][];
static Brick board;
static Brick ball;
static int score = 0;
public static void main(String[] args) {
bricks=new Brick[4][8];
frame.setLayout(null);
frame.setSize(1000, 650);
addBricks();
board = new Brick(425, 580, 150, 20);
board.setBackground(Color.WHITE);
ball = new Brick(425, 500, 20, 20);
ball.setBackground(Color.WHITE);
frame.add(board);
frame.add(ball);
new MoveBall();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
new MoveBoard(e.getKeyCode());
}
});
frame.getContentPane().setBackground(Color.BLACK);
frame.setVisible(true);
}
static void addBricks(){
for(int i=0; i<bricks.length; i++) {
for(int j=0; j<bricks[0].length; j++){
bricks[i][j] = new Brick(j*120 + 20, 25*i + 20, 100, 20);
frame.add(bricks[i][j]);
}
}
}
}