Download Brick Breaker 240x320 Jar

PermalinkDownload brick breaker 240x320 jar game

Download Brick Breaker 240x320 Jar Game

To download Brick Breaker Revolution 2 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 Brick Breaker Revolution 2 - free download', then select one of the ways you want to get the file. Download 3D Brick Breaker (240x320) Mobile Game to your mobile for free, in jar, uploaded by Aesculapiuz05 in Puzzle & Board. 3D Brick Breaker (240x320).jar download and free Mobile Games downloads like 3D Brick Breaker (240x320) & send to your mobile.

Join 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
/*
* 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());
}
}
}
}
  • Copy lines
  • Copy permalink

Version 1.2 (Last Updated: 9/6/2014)

Music used with permission of owner.

What's New

  • Cleaned up unneeded folders and files
  • Removed all console logging
  • Fixed music bug on Linux
  • Changed look and feel to emulate the OS it's running on
  • Various bug fixes

Description

This game is a clone of 'Breakout', a game in which the player controls a paddle that is used to bounce a ballthat breaks blocks. Items are occasionally dropped from the blocks. The game tracks the player's name, lives,level, and score as well. If the player scores high enough, they are placed on the high score board, which isdisplayed at the end of every game. There are an unlimited amount of levels, and the user can also select tohave background music played throughout the game. Catch the green items to make your paddle larger, and avoidthe red ones!

Screenshot

Controls

  • Spacebar: starts game, pauses/resumes during game
  • Left arrow: moves paddle left
  • Right arrow: moves paddle right

Download Brick Breaker 240x320 Jar Games

It is recommended to click and release the keys each time you wish to move, rather than hold them down, due tothe delay built into most operating systems. You will be far more precise if you click and release for each movement.

How to Download

  • Go to this URL: https://github.com/tylucaskelley/BrickBreaker
  • Click the 'Download ZIP' button near the bottom-right side
  • Unzip the folder once it downloads.

Download Brick Breaker 240x320 Jars

How to Run

Download Brick Breaker

  • Double-click the BrickBreaker.jar file, located in dist.
  • On Linux, you may have to run from terminal:
  • Enter your name.
  • Select an option for audio playback.
  • Enjoy!

Download Brick Breaker 240x320 Jar

Contributing

Download Brick Breaker 240x320 Jar Free

  1. Refine relationship between ball and brick: sometimes there is odd behavior when ball hits corner of abrick (technically hits 2 sides at same time).
  2. Potential sounds: when ball hits something, new level, life loss, game over, etc.
  3. Fix error where two clicks of spacebar are needed occasionally. May be a concurrency problem.
  4. Compose original soundtrack for game