-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.java
66 lines (57 loc) · 2.1 KB
/
Board.java
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
56
57
58
59
60
61
62
63
64
65
66
public class Board {
private int width;
private int height;
private String[][] board;
public static Board instance = null;
private Board(int width, int height) {
this.width = width;
this.height = height;
//run();
}
public static Board getObject(int width, int height) {
if (instance == null) {
instance = new Board(width, height);
}
return instance;
}
public void run(Ball[] ball,int BallNumber,int BallCounter){
//initlize the board
board = new String[100][100];
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
if(i==0 || i==height-1 || j==0 || j==width-1){
board[i][j] = "-";
}else{
board[i][j] = " ";
}
if(i==0 && j==0){
board[i][j] = "+";
}
if(i==0 && j==width-1){
board[i][j] = "+";
}
if(i==height-1 && j==0){
board[i][j] = "+";
}
if(i==height-1 && j==width-1){
board[i][j] = "+";
}
}
}
// print the ball
for(int i=0;i<BallCounter;i++){
if(ball[i].getActive()==true){
//ball[i].collision(); int width,int heightBal
BallCounter = newBall.getCount();
ball[i].collision(ball,BallNumber,i,BallCounter);
ball[i].move();
BallCounter = newBall.getCount();
board[Math.abs(ball[i].getX())][Math.abs(ball[i].getY())] = "o";
//System.out.println(ball[i].getX()+" "+ball[i].getY()+" "+ball[i].getXDirection()+" "+ball[i].getYDirection()+" "+newBall.getCount());
}
}
//print the board
Print print = new Print(board,width,height);
print.printBoard(board,width,height);
}
}