//생략
block.isHidden = true;
//스코어 점수
if(block.color==0) {
score += 10;
}else if(block.color==1) {
score += 20;
}else if(block.color==2) {
score += 30;
}else if(block.color==3) {
score += 40;
}else if(block.color==4) {
score += 50;
}
public void checkCollision() {
//생략...
else if (dir == 1) { // Down-Right
// 벽에 충돌됐을때
if (ball.y > CANVAS_HEIGHT - BALL_HEIGHT - BALL_HEIGHT) { // wall bottom
dir = 0;
//게임리셋
dir = 0;
ball.x = CANVAS_WIDTH/2- BALL_WIDTH/2;
ball.y = CANVAS_HEIGHT/2 - BALL_HEIGHT/2;
score = 0; //스코어 0으로 다시 설정
}
if (ball.x > CANVAS_WIDTH - BALL_WIDTH) { // wall
dir = 3; // 방향이 꺾이도록
}
// Bar에 충돌 될 때
if (ball.getBottomCenter().y >= bar.y) {
if (duplRect(new Rectangle(ball.x, ball.y, ball.width, ball.height),
new Rectangle(bar.x, bar.y, bar.width, bar.height))) {
dir = 0;
}
}
}
//생략....
else if (dir == 3) { // Down-Left
// wall
if (ball.y > CANVAS_HEIGHT - BALL_HEIGHT - BALL_HEIGHT) { // wall bottom
dir = 2;
//게임리셋
dir = 0;
//처음 초기에 설정해준 값을 넣어준다.
int x = CANVAS_WIDTH/2- BALL_WIDTH/2;
int y = CANVAS_HEIGHT/2 - BALL_HEIGHT/2;
score = 0; //스코어 0으로 다시 설정
}
}
// variable(변수지정)
static boolean isGameFinish = false; //추가
public void startTimer() {
// 생략...
//게임 끝
isGameFinish();
}
// draw score
g2d.setColor(Color.WHITE);
g2d.setFont(new Font("TimeRoman", Font.BOLD, 20));
g2d.drawString("score : " + score , CANVAS_WIDTH / 2 - 30, 20);
if(isGameFinish) {
g2d.setColor(Color.RED);
g2d.drawString(" Game Finished", CANVAS_WIDTH / 2 - 55, 50);
}
public void isGameFinish() {
//Game Success !
int count = 0;
for(int i =0; i< BLOCK_ROWS; i++) {
for(int j=0; j<BLOCK_COLUMNS; j++) {
Block block = blocks[i][j];
if(block.isHidden) {
count++;
}
}
if(count == BLOCK_ROWS * BLOCK_COLUMNS) {
isGameFinish=true;
}
}
}
게임 끝 ! !