?? ball.java
字號:
/**
* Add a comment
*/
import java.awt.*;
public class Ball {
//You may find some of these constants helpful
public static final int MAX_CHANGE_AMOUNT = 7;
public static final int MIN_CHANGE_AMOUNT = 2;
public static final int REBOUND_EAST_WALL = 0;
public static final int REBOUND_WEST_WALL = 1;
public static final int REBOUND_NORTH_WALL = 2;
public static final int REBOUND_SOUTH_WALL = 3;
public static final int REBOUND_PADDLE = 4;
public static final int BALL_SIZE = BreakOutConstants.BALL_SIZE;
public Rectangle ball;
private int[] xValues = {-7 , -6, -5, -4, -3, -2, 2, 3, 4, 5, 6, 7};
private int[] yValues = { -2, -3, -4, -5, -6, -7};
private int changeInX, changeInY;
public Ball(){
ball = new Rectangle(BreakOutConstants.BALL_START_RECT.x , BreakOutConstants.BALL_START_RECT.y , BALL_SIZE , BALL_SIZE);
}
private int getRandomXValue(){
int XValue = (int)(Math.random()*12-1);
changeInX = xValues[XValue];
return XValue;
}
private int getRandomYValue(){
int YValue = (int)(Math.random()*6-1);
changeInY = yValues[YValue];
return YValue;
}
public void move(){
ball.x = ball.x + changeInX;
ball.y = ball.y + changeInY;
}
public void drawBall(Graphics g) {
int x, y, width, height;
g.setColor(Color.RED);
x = ball.x;
y = ball.y;
width = ball.width;
height = ball.height;
g.fillOval( x, y, width, height );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -