3D Brick Breaker Revolution (240x320) Java Game Explore the revolution of breakout games! Heal our land by jamie rivera mp3. Superb 3D graphics and various bonuses await you in the many challenges that holds this game: levels infinis, boss battles, bonus levels and more. To download Doodle brick breaker free java game, we recommend you to select your phone model, and then our system will choose the most suitable game files. Downloading is very simple: select the desired file and click 'Java Doodle brick breaker - free download', then select one of the ways you want to get the file.
PermalinkJoin GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up Find file Copy path
tylucaskelleydid some cleanup of files and console loggingf1b19feSep 6, 2014
1 contributor
Download Brick Breaker 240x320 Jar Download
/* |
* Brick Breaker, Version 1.2 |
* By Ty-Lucas Kelley |
* |
* **LICENSE** |
* |
* This file is a part of Brick Breaker. |
* |
* Brick Breaker is free software: you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation, either version 3 of the License, or |
* (at your option) any later version. |
* |
* Brick Breaker is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Brick Breaker. If not, see <http://www.gnu.org/licenses/>. |
*/ |
//This 'Board' class handles all game logic and displays items on the screen. |
//Imports |
importjava.awt.*; |
importjavax.swing.*; |
importjava.util.Random; |
importjava.lang.Thread; |
importjavax.sound.sampled.*; |
importjava.io.*; |
importjava.awt.event.*; |
importjava.util.ArrayList; |
importjava.util.concurrent.atomic.AtomicBoolean; |
importjava.util.TreeMap; |
importjava.awt.Toolkit.*; |
//Class definition |
publicclassBoardextendsJPanelimplementsRunnable, Constants { |
//Items on-screen |
privatePaddle paddle; |
privateBall ball; |
privateBrick[][] brick =newBrick[10][5]; |
//Initial Values for some important variables |
privateint score =0, lives =MAX_LIVES, bricksLeft =MAX_BRICKS, waitTime =3, xSpeed, withSound, level =1; |
//Player's name |
privateString playerName; |
//The game |
privateThread game; |
//Songs for background music |
privateString songOne ='wav/One.wav'; |
privateString songTwo ='wav/Two.wav'; |
privateString songThree ='wav/Three.wav'; |
privateString songFour ='wav/Four.wav'; |
privateString songFive ='wav/Five.wav'; |
privateString songSix ='wav/Six.wav'; |
privateString songSeven ='wav/Seven.wav'; |
privateString songEight ='wav/Eight.wav'; |
privateString songNine ='wav/Nine.wav'; |
privateString songTen ='wav/Ten.wav'; |
privateString[] trackList = {songOne, songTwo, songThree, songFour, songFive, songSix, songSeven, songEight, songNine, songTen}; |
privateAudioInputStream audio; |
privateClip clip; |
//Data structures to handle high scores |
privateArrayList<Item> items =newArrayList<Item>(); |
privateAtomicBoolean isPaused =newAtomicBoolean(true); |
//Colors for the bricks |
privateColor[] blueColors = {BLUE_BRICK_ONE, BLUE_BRICK_TWO, BLUE_BRICK_THREE, Color.BLACK}; |
privateColor[] redColors = {RED_BRICK_ONE, RED_BRICK_TWO, RED_BRICK_THREE, Color.BLACK}; |
privateColor[] purpleColors = {PURPLE_BRICK_ONE, PURPLE_BRICK_TWO, PURPLE_BRICK_THREE, Color.BLACK}; |
privateColor[] yellowColors = {YELLOW_BRICK_ONE, YELLOW_BRICK_TWO, YELLOW_BRICK_THREE, Color.BLACK}; |
privateColor[] pinkColors = {PINK_BRICK_ONE, PINK_BRICK_TWO, PINK_BRICK_THREE, Color.BLACK}; |
privateColor[] grayColors = {GRAY_BRICK_ONE, GRAY_BRICK_TWO, GRAY_BRICK_THREE, Color.BLACK}; |
privateColor[] greenColors = {GREEN_BRICK_ONE, GREEN_BRICK_TWO, GREEN_BRICK_THREE, Color.BLACK}; |
privateColor[][] colors = {blueColors, redColors, purpleColors, yellowColors, pinkColors, grayColors, greenColors}; |
//Constructor |
publicBoard(intwidth, intheight) { |
super.setSize(width, height); |
addKeyListener(newBoardListener()); |
setFocusable(true); |
makeBricks(); |
paddle =newPaddle(PADDLE_X_START, PADDLE_Y_START, PADDLE_WIDTH, PADDLE_HEIGHT, Color.BLACK); |
ball =newBall(BALL_X_START, BALL_Y_START, BALL_WIDTH, BALL_HEIGHT, Color.BLACK); |
//Get the player's name |
playerName =JOptionPane.showInputDialog(null, 'Please enter your name:', 'Brick Breaker, Version 1.2', JOptionPane.QUESTION_MESSAGE); |
if (playerName null) { |
System.exit(0); |
} |
if (playerName.toUpperCase().equals('TY') playerName.toUpperCase().equals('TYKELLEY') playerName.toUpperCase().equals('TYLUCAS') playerName.toUpperCase().equals('TYLUCASKELLEY') playerName.toUpperCase().equals('TY-LUCAS') playerName.toUpperCase().equals('TY-LUCAS KELLEY') playerName.toUpperCase().equals('TY KELLEY')) { |
score +=1000; |
JOptionPane.showMessageDialog(null, 'You unlocked the secret 1,000 point bonus! Nice name choice by the way.', '1,000 Points', JOptionPane.INFORMATION_MESSAGE); |
} |
//Start Screen that displays information and asks if the user wants music or not, stores that choice |
String[] options = {'Yes', 'No'}; |
withSound =JOptionPane.showOptionDialog(null, 'Brick Breaker, Version 1.2nTy-Lucas KelleynVisit www.tylucaskelley.com for more projects.nnControlsn Spacebar: Start game, Pause/Resume while in game.n Left/Right arrow keys: Move paddlenItemsn Green Item: Expand paddlen Red Item: Shrink paddlenScoringn Block: 50 pointsn Level-up: 100 pointsn Life Loss: -100 pointsnnn Do you want background music?', 'About the Game', JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); |
playMusic(trackList, withSound, level); |
game =newThread(this); |
game.start(); |
stop(); |
isPaused.set(true); |
} |
//fills the array of bricks |
publicvoidmakeBricks() { |
for(int i =0; i <10; i++) { |
for(int j =0; j <5; j++) { |
Random rand =newRandom(); |
int itemType = rand.nextInt(3) +1; |
int numLives =3; |
Color color = colors[rand.nextInt(7)][0]; |
brick[i][j] =newBrick((i *BRICK_WIDTH), ((j *BRICK_HEIGHT) + (BRICK_HEIGHT/2)), BRICK_WIDTH-5, BRICK_HEIGHT-5, color, numLives, itemType); |
} |
} |
} |
//starts the thread |
publicvoidstart() { |
game.resume(); |
isPaused.set(false); |
} |
//stops the thread |
publicvoidstop() { |
game.suspend(); |
} |
//ends the thread |
publicvoiddestroy() { |
game.resume(); |
isPaused.set(false); |
game.stop(); |
isPaused.set(true); |
} |
//runs the game |
publicvoidrun() { |
xSpeed =1; |
while(true) { |
int x1 = ball.getX(); |
int y1 = ball.getY(); |
//Makes sure speed doesnt get too fast/slow |
if (Math.abs(xSpeed) >1) { |
if (xSpeed >1) { |
xSpeed--; |
} |
if (xSpeed <1) { |
xSpeed++; |
} |
} |
checkPaddle(x1, y1); |
checkWall(x1, y1); |
checkBricks(x1, y1); |
checkLives(); |
checkIfOut(y1); |
ball.move(); |
dropItems(); |
checkItemList(); |
repaint(); |
try { |
game.sleep(waitTime); |
} catch (InterruptedException ie) { |
ie.printStackTrace(); |
} |
} |
} |
publicvoidaddItem(Itemi) { |
items.add(i); |
} |
publicvoiddropItems() { |
for (int i =0; i < items.size(); i++) { |
Item tempItem = items.get(i); |
tempItem.drop(); |
items.set(i, tempItem); |
} |
} |
publicvoidcheckItemList() { |
for (int i =0; i < items.size(); i++) { |
Item tempItem = items.get(i); |
if (paddle.caughtItem(tempItem)) { |
items.remove(i); |
} |
elseif (tempItem.getY() >WINDOW_HEIGHT) { |
items.remove(i); |
} |
} |
} |
publicvoidcheckLives() { |
if (bricksLeft NO_BRICKS) { |
try { |
clip.stop(); |
clip.close(); |
audio.close(); |
} catch (Exception e) { |
e.printStackTrace(); |
} |
ball.reset(); |
bricksLeft =MAX_BRICKS; |
makeBricks(); |
lives++; |
level++; |
score +=100; |
playMusic(trackList, withSound, level); |
repaint(); |
stop(); |
isPaused.set(true); |
} |
if (lives MIN_LIVES) { |
repaint(); |
stop(); |
isPaused.set(true); |
} |
} |
publicvoidcheckPaddle(intx1, inty1) { |
if (paddle.hitPaddle(x1, y1) && ball.getXDir() <0) { |
ball.setYDir(-1); |
xSpeed =-1; |
ball.setXDir(xSpeed); |
} |
if (paddle.hitPaddle(x1, y1) && ball.getXDir() >0) { |
ball.setYDir(-1); |
xSpeed =1; |
ball.setXDir(xSpeed); |
} |
if (paddle.getX() <=0) { |
paddle.setX(0); |
} |
if (paddle.getX() + paddle.getWidth() >= getWidth()) { |
paddle.setX(getWidth() - paddle.getWidth()); |
} |
} |
publicvoidcheckWall(intx1, inty1) { |
if (x1 >= getWidth() - ball.getWidth()) { |
xSpeed =-Math.abs(xSpeed); |
ball.setXDir(xSpeed); |
} |
if (x1 <=0) { |
xSpeed =Math.abs(xSpeed); |
ball.setXDir(xSpeed); |
} |
if (y1 <=0) { |
ball.setYDir(1); |
} |
if (y1 >= getHeight()) { |
ball.setYDir(-1); |
} |
} |
publicvoidcheckBricks(intx1, inty1) { |
for (int i =0; i <10; i++) { |
for (int j =0; j <5; j++) { |
if (brick[i][j].hitBottom(x1, y1)) { |
ball.setYDir(1); |
if (brick[i][j].isDestroyed()) { |
bricksLeft--; |
score +=50; |
addItem(brick[i][j].item); |
} |
} |
if (brick[i][j].hitLeft(x1, y1)) { |
xSpeed =-xSpeed; |
ball.setXDir(xSpeed); |
if (brick[i][j].isDestroyed()) { |
bricksLeft--; |
score +=50; |
addItem(brick[i][j].item); |
} |
} |
if (brick[i][j].hitRight(x1, y1)) { |
xSpeed =-xSpeed; |
ball.setXDir(xSpeed); |
if (brick[i][j].isDestroyed()) { |
bricksLeft--; |
score +=50; |
addItem(brick[i][j].item); |
} |
} |
if (brick[i][j].hitTop(x1, y1)) { |
ball.setYDir(-1); |
if (brick[i][j].isDestroyed()) { |
bricksLeft--; |
score +=50; |
addItem(brick[i][j].item); |
} |
} |
} |
} |
} |
publicvoidcheckIfOut(inty1) { |
if (y1 >PADDLE_Y_START+10) { |
lives--; |
score -=100; |
ball.reset(); |
repaint(); |
stop(); |
isPaused.set(true); |
} |
} |
//plays different music throughout game if user wants to |
publicvoidplayMusic(String[] songs, intyesNo, intlevel) { |
if (yesNo 1) { |
return; |
} |
elseif (yesNo -1) { |
System.exit(0); |
} |
if (level 10) { |
level =1; |
} |
try { |
audio =AudioSystem.getAudioInputStream(newFile(songs[level-1]).getAbsoluteFile()); |
clip =AudioSystem.getClip(); |
clip.open(audio); |
clip.loop(Clip.LOOP_CONTINUOUSLY); |
} catch (Exception e) { |
e.printStackTrace(); |
} |
} |
//fills the board |
@Override |
publicvoidpaintComponent(Graphicsg) { |
Toolkit.getDefaultToolkit().sync(); |
super.paintComponent(g); |
paddle.draw(g); |
ball.draw(g); |
for (int i =0; i <10; i++) { |
for (int j =0; j <5; j++) { |
brick[i][j].draw(g); |
} |
} |
g.setColor(Color.BLACK); |
g.drawString('Lives: '+ lives, 10, getHeight() - (getHeight()/10)); |
g.drawString('Score: '+ score, 10, getHeight() - (2*(getHeight()/10)) +25); |
g.drawString('Level: '+ level, 10, getHeight() - (3*(getHeight()/10)) +50); |
g.drawString('Player: '+ playerName, 10, getHeight() - (4*(getHeight()/10)) +75); |
for (Item i: items) { |
i.draw(g); |
} |
if (lives MIN_LIVES) { |
g.setColor(Color.BLACK); |
g.fillRect(0,0,getWidth(),getHeight()); |
g.setColor(Color.WHITE); |
g.drawString('Name: '+ playerName +', Score: '+ score +', Level: '+ level, getWidth()/5, 20); |
g.drawString('Game Over! Did you make it onto the high score table?', getWidth()/5, 50); |
try { |
printScores(g); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
g.drawString('Press the Spacebar twice to play again.', getWidth()/5, getHeight()-20); |
} |
} |
//Makes sure the HighScores.txt file exists |
publicvoidmakeTable() throwsIOException { |
String filename ='HighScores'; |
File f =newFile(filename +'.txt'); |
if (f.createNewFile()) { |
try { |
writeFakeScores(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
} |
else { |
//do nothing |
} |
} |
//if there was no previous high score table, this one inputs 10 fake players and scores to fill it |
publicvoidwriteFakeScores() throwsIOException { |
Random rand =newRandom(); |
int numLines =10; |
File f =newFile('HighScores.txt'); |
BufferedWriter bw =newBufferedWriter(newFileWriter(f.getAbsoluteFile())); |
for (int i =1; i <= numLines; i++) { |
int score = rand.nextInt(2000); |
if (numLines - i >=1) { |
bw.write('Name: '+'Player'+ i +', '+'Score: '+ score +'n'); |
} |
else { |
bw.write('Name: '+'Player'+ i +', '+'Score: '+ score); |
} |
} |
bw.close(); |
try { |
sortTable(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
} |
//Returns the player's name and score formatted correctly |
publicStringplayerInfo() { |
return'Name: '+ playerName +', Score: '+ score; |
} |
//returns the number of lines in the high score file |
publicintlinesInFile(Filef) throwsIOException { |
BufferedReader br =newBufferedReader(newFileReader(f.getAbsoluteFile())); |
int lines =0; |
while (br.readLine() !=null) { |
lines++; |
} |
br.close(); |
return lines; |
} |
//Add game to high score file by appending it and getting line number from previous method |
publicvoidsaveGame() throwsIOException { |
File f =newFile('HighScores.txt'); |
FileWriter fw =newFileWriter(f.getAbsoluteFile(), true); |
BufferedWriter bw =newBufferedWriter(fw); |
bw.append('n'+ playerInfo()); |
bw.close(); |
} |
//sorts the high score table high to low using maps and other fun things |
publicvoidsortTable() throwsIOException { |
File f =newFile('HighScores.txt'); |
File temp =newFile('temp.txt'); |
TreeMap<Integer, ArrayList<String>> topTen =newTreeMap<Integer, ArrayList<String>>(); |
BufferedReader br =newBufferedReader(newFileReader(f.getAbsoluteFile())); |
BufferedWriter bw =newBufferedWriter(newFileWriter(temp.getAbsoluteFile())); |
String line =null; |
while ((line = br.readLine()) !=null) { |
if (line.isEmpty()) { |
continue; |
} |
String[] scores = line.split('Score: '); |
Integer score =Integer.valueOf(scores[1]); |
ArrayList<String> players =null; |
//make sure two players with same score are dealt with |
if ((players = topTen.get(score)) null) { |
players =newArrayList<String>(1); |
players.add(scores[0]); |
topTen.put(Integer.valueOf(scores[1]), players); |
} |
else { |
players.add(scores[0]); |
} |
} |
for (Integer score : topTen.descendingKeySet()) { |
for (String player : topTen.get(score)) { |
try { |
bw.append(player +'Score: '+ score +'n'); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
} |
} |
br.close(); |
bw.close(); |
try { |
makeNewScoreTable(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
} |
//save the sorted table to the high score file |
publicvoidmakeNewScoreTable() throwsIOException { |
File f =newFile('HighScores.txt'); |
File g =newFile('temp.txt'); |
f.delete(); |
g.renameTo(f); |
} |
//Print the top 10 scores, but first excecutes all other file-related methods |
publicvoidprintScores(Graphicsg) throwsIOException { |
try { |
makeTable(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
try { |
saveGame(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
try { |
sortTable(); |
} catch (IOException ioe) { |
ioe.printStackTrace(); |
} |
int h =100; |
File fileToRead =newFile('HighScores.txt'); |
LineNumberReader lnr =newLineNumberReader(newFileReader(fileToRead)); |
String line = lnr.readLine(); |
while (line !=null&& lnr.getLineNumber() <=10) { |
int rank = lnr.getLineNumber(); |
g.drawString(rank +'. '+ line, getWidth()/5, h); |
h +=15; |
line = lnr.readLine(); |
} |
lnr.close(); |
} |
//Private class that handles gameplay and controls |
privateclassBoardListenerextendsKeyAdapter { |
@Override |
publicvoidkeyPressed(KeyEventke) { |
int key = ke.getKeyCode(); |
if (key KeyEvent.VK_SPACE) { |
if (lives >MIN_LIVES) { |
if (isPaused.get() false) { |
stop(); |
isPaused.set(true); |
} |
else { |
start(); |
} |
} |
else { |
paddle.setWidth(getWidth()/7); |
lives =MAX_LIVES; |
score =0; |
bricksLeft =MAX_BRICKS; |
level =1; |
makeBricks(); |
isPaused.set(true); |
for (int i =0; i <10; i++) { |
for (int j =0; j <5; j++) { |
brick[i][j].setDestroyed(false); |
} |
} |
} |
} |
if (key KeyEvent.VK_LEFT) { |
paddle.setX(paddle.getX() -50); |
} |
if (key KeyEvent.VK_RIGHT) { |
paddle.setX(paddle.getX() +50); |
} |
} |
@Override |
publicvoidkeyReleased(KeyEventke) { |
int key = ke.getKeyCode(); |
if (key KeyEvent.VK_LEFT) { |
paddle.setX(paddle.getX()); |
} |
if (key KeyEvent.VK_RIGHT) { |
paddle.setX(paddle.getX()); |
} |
} |
} |
} |
Download Brick Breaker 240x320 Jar Free
Copy lines Copy permalink