Just helping out by fixing the formatting a bit...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Arkanoid extends JFrame
implements MouseListener,
WindowListener,
MouseMotionListener,
Runnable
{
private final int GAME_STATE_TITLE_SCREEN = 1;
private final int GAME_STATE_GAME = 2;
private final int GAME_STATE_GAME_OVER = 3;
private int gameState;
private int racketXPos;
private int racketYPos;
private int ballXPos;
private int ballYPos;
private int remainingBalls;
private int currentXPos;
private int currentYPos;
private int oldX;
private int oldY;
private int ballXIncrement;
private int ballYIncrement;
private int[][] xBlockArray = new int[6][16];
private int[][] yBlockArray = new int[6][16];
private Thread ballThread = new Thread(this);
private int sleepTime = 4;
private boolean drawWithBall;
private boolean firstRun; //no start command sent during later runs
private String currentLevel = "Level One";
Color[][] colorBlockArray = new Color[6][16];
public Arkanoid()
{
this.addMouseListener(this);
this.addWindowListener(this);
this.addMouseMotionListener(this);
gameState = GAME_STATE_TITLE_SCREEN;
drawWithBall = true;
firstRun = true;
ballXPos = 310;
ballYPos = 505;
remainingBalls = 4;
ballXIncrement = 1;
ballYIncrement = -1;
racketXPos = 280;
racketYPos = 540;
this.setSize(600, 600);
this.setBackground(Color.white);
this.show();
}
public void fillColorArray()
{
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= 15; y++)
{
int red = (int)(Math.random() * 256);
int green = (int)(Math.random() * 256);
int blue = (int)(Math.random() * 256);
Color randomColor = new Color (red, green, blue);
colorBlockArray[x][y] = randomColor;
}
}
}
public void fillBlockArrays()
{
currentXPos = 30;
currentYPos = 150;
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= 15; y++)
{
xBlockArray[x][y] = currentXPos;
yBlockArray[x][y] = currentYPos;
currentXPos += 36;
}
currentXPos = 30;
currentYPos += 20;
}
}
public void drawBlocks()
{
Graphics gfx = this.getGraphics();
int sumOfEmptyBlocks = 0;
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= 15; y++)
{
if (xBlockArray[x][y] == 0 && yBlockArray[x][y] == 0)
{
gfx.setColor(Color.white);
gfx.fillRect(oldX, oldY, 36, 20);
sumOfEmptyBlocks++;
if (sumOfEmptyBlocks >= 75)
{
ballThread = null;
drawWithBall = true;
firstRun = true;
ballXIncrement *= -1;
ballYIncrement *= -1;
if (currentLevel.equals("Level One") == true)
{
currentLevel = "Level Two";
sleepTime--;
}
else if (currentLevel.equals("Level Two") == true)
{
currentLevel = "Level Three";
sleepTime--;
}
else if (currentLevel.equals("Level Three") == true)
{
currentLevel = "Level Four";
sleepTime--;
}
else
{
gameState = GAME_STATE_GAME_OVER;
}
this.repaint();
}
}
else
{
Color blockColor = colorBlockArray[x][y];
gfx.setColor(blockColor);
gfx.fill3DRect(xBlockArray[x][y], yBlockArray[x][y], 36, 20, true);
}
}
}
}
public void start()
{
ballThread.start();
}
public void stop()
{
ballThread = null;
}
public void destroy()
{
}
public void run()
{
Graphics gfx = this.getGraphics();
if (gameState == GAME_STATE_GAME)
{
while (ballThread != null)
{
//BOUNCE AND BREAK IN RESPONCE TO HITTING BLOCKS
if (ballYPos >= 130 && ballYPos <= 250)
{
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= 15; y++)
{
if (xBlockArray[x][y] == 0 && yBlockArray[x][y] == 0)
;
else
{
///TTTOOOPPPPP
if (ballYPos + 12 == yBlockArray[x][y] &&
ballXPos + 12 >= xBlockArray[x][y] &&
ballXPos <= xBlockArray[x][y] + 36)
{
ballYIncrement *= -1;
oldX = xBlockArray[x][y];
xBlockArray[x][y] = 0;
oldY = yBlockArray[x][y];
yBlockArray[x][y] = 0;
this.drawBlocks();
break;
}
//bbbboooottttooommmm
else if
(ballYPos == yBlockArray[x][y] + 20 &&
ballXPos + 12 >= xBlockArray[x][y] &&
ballXPos <= xBlockArray[x][y] + 36)
{
ballYIncrement *= -1;
oldX = xBlockArray[x][y];
xBlockArray[x][y] = 0;
oldY = yBlockArray[x][y];
yBlockArray[x][y] = 0;
this.drawBlocks();
break;
}
///RRRIIGGGGHHHHTTTT
else if
(ballYPos + 12 >= yBlockArray[x][y] &&
ballYPos <= yBlockArray[x][y] + 20 &&
ballXPos + 12 == xBlockArray[x][y])
{
ballXIncrement *= -1;
oldX = xBlockArray[x][y];
xBlockArray[x][y] = 0;
oldY = yBlockArray[x][y];
yBlockArray[x][y] = 0;
this.drawBlocks();
break;
}
//lllleeeeffffttttt
else if
(ballYPos + 12 >= yBlockArray[x][y] &&
ballYPos <= yBlockArray[x][y] + 20 &&
ballXPos == xBlockArray[x][y] + 36)
{
ballXIncrement *= -1;
oldX = xBlockArray[x][y];
xBlockArray[x][y] = 0;
oldY = yBlockArray[x][y];
yBlockArray[x][y] = 0;
this.drawBlocks();
break;
}
}
}
}
}
this.drawBlocks();
//BOUNCE FROM WALLS AND RACKET
if (ballXPos >= 556)
{
ballXIncrement *= -1;
}
if (ballXPos <= 32)
{
ballXIncrement *= -1;
}
if (ballYPos <= 58)
{
ballYIncrement *= -1;
}
if (ballYPos >= 526)
{
if (ballXPos >= racketXPos + 5 && ballXPos <= racketXPos + 55)
{
ballYIncrement *= -1;
}
if (ballXPos >= racketXPos && ballXPos <= racketXPos + 5)
{
ballYIncrement *= -1;
ballXIncrement *= -1;
}
if (ballXPos >= racketXPos + 55 && ballXPos <= racketXPos + 60)
{
ballYIncrement *= -1;
ballXIncrement *= -1;
}
if (ballYPos >= racketYPos && ballYPos <= racketYPos + 10)
{
if (ballXPos == racketXPos)
ballXIncrement *= -1;
if (ballXPos == racketXPos + 60)
ballXIncrement *= -1;
}
}
//IF A BALL IS LOST
if (ballYPos >= 537)
{
stop();
remainingBalls--;
if (remainingBalls <= 0)
{
gameState = GAME_STATE_GAME_OVER;
this.repaint();
}
drawWithBall = true;
firstRun = true;
ballXIncrement *= -1;
ballYIncrement *= -1;
}
try
{
Thread.sleep(sleepTime);
}
catch(InterruptedException ex)
{
}
gfx.setColor(Color.white);
gfx.fillArc(ballXPos, ballYPos, 12, 12, 0, 360);
gfx.fillArc(ballXPos - ballXIncrement, ballYPos - ballYIncrement, 12, 12, 0, 360);
gfx.fillArc(ballXPos - 2 * ballXIncrement, ballYPos - 2 * ballYIncrement, 12, 12, 0, 360);
ballYPos += ballYIncrement;
ballXPos += ballXIncrement;
gfx.setColor(Color.black);
gfx.fillArc(ballXPos, ballYPos, 12, 12, 0, 360);
}
}
}
public static void main(String [] args)
{
Arkanoid gameWindow = new Arkanoid();
}
public void drawTitleScreen()
{
Container workArea = this.getContentPane();
int height = workArea.getHeight();
int width = workArea.getWidth();
Graphics gfx = workArea.getGraphics();
gfx.setColor(Color.black);
gfx.fillRect(0, 0, width, height);
gfx.setColor(Color.green);
gfx.drawString("ARKANOID", 265, 240);
gfx.drawString("By Saman Mirkazemi", 238, 455);
gfx.setColor(Color.gray);
gfx.drawString("click mouse to continue", 230, 480);
}
private void game()
{
if (firstRun == true)
{
this.fillColorArray();
this.fillBlockArrays();
this.drawBlocks();
}
Container workArea = this.getContentPane();
Graphics gfx = workArea.getGraphics();
int height = workArea.getHeight();
int width = workArea.getWidth();
gfx.setColor(Color.white);
gfx.fillRect(0, 0, width, height);
gfx.setColor(Color.black);
gfx.drawRect(25, 25, 541, 525);
}
public void gameOver()
{
Container workArea = this.getContentPane();
this.setBackground(Color.black);
Graphics gfx = workArea.getGraphics();
gfx.setColor(Color.black);
gfx.fillRect(0, 0, workArea.getWidth(), workArea.getHeight());
gfx.setColor(Color.green);
gfx.drawString("GAME OVER", 260, 240);
gfx.setColor(Color.gray);
gfx.drawString("REPLAY", 274, 465);
gfx.drawString("EXIT", 283, 480);
}
public void paint(Graphics gfx)
{
if (gameState == GAME_STATE_TITLE_SCREEN)
{
this.drawTitleScreen();
}
if (gameState == GAME_STATE_GAME)
{
this.game();
}
if (gameState == GAME_STATE_GAME_OVER)
{
this.gameOver();
}
}
public void update(Graphics gfx)
{
paint(gfx);
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e)
{
gameState += 1; ////////////////////////////////////////////////
repaint(); ////////////////////////////////////////////////
}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e)
{
Graphics gfx = this.getGraphics();
if (e.getX() >= racketXPos && e.getX() <= racketXPos + 60
&& e.getY() >= racketYPos && e.getY() <= racketYPos + 30)
{
drawWithBall = false;
}
if (gameState == GAME_STATE_TITLE_SCREEN)
{
gameState = GAME_STATE_GAME;
this.repaint();
}
if (gameState == GAME_STATE_GAME_OVER)
{
this.dispose();
}
}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e)
{
Graphics gfx = this.getGraphics();
if (gameState == GAME_STATE_GAME)
{
if (e.getX() <= 59 || e.getX() >= 541)
;
else
{
gfx.clearRect(racketXPos, racketYPos, 60, 10);
racketXPos = e.getX() - 30;
if (drawWithBall == true)
{
gfx.setColor(Color.white);
gfx.fillArc(ballXPos, ballYPos, 12, 12, 0, 360);
ballXPos = racketXPos + 25;
ballYPos = racketYPos - 15;
gfx.setColor(Color.blue);
gfx.drawString("CLICK RACKET TO START", 230, 400);
gfx.drawString(currentLevel, 275, 415);
this.drawBlocks();
}
gfx.setColor(Color.black);
gfx.fillRect(racketXPos, racketYPos, 60, 10);
gfx.fillArc(ballXPos, ballYPos, 12, 12, 0, 360);
if (drawWithBall == false && firstRun == true)
{
gfx.setColor(Color.white);
gfx.drawString("CLICK RACKET TO START", 230, 400);
gfx.drawString(currentLevel, 275, 415);
firstRun = false;
if (ballThread == null)
ballThread = new Thread(this);
ballThread.start();
//DRAW REMAINING BALLS ON THE BOTTOM OF SCREEN
int x = 30;
int y = 555;
int tempX = 30;
for (int z = 1; z <= remainingBalls - 1; z++)
{
for (int h = 1; h <= 3; h++)
{
gfx.setColor(Color.white);
gfx.fillArc(tempX, y, 12, 12, 0, 360);
tempX += 15;
}
gfx.setColor(Color.red);
gfx.fillArc(x, y, 12, 12, 0, 360);
x += 15;
}
if (remainingBalls <= 1)
{
gfx.setColor(Color.white);
gfx.fillArc(30, 555, 12, 12, 0, 360);
}
}
}
}
if (gameState = GAME_STATE_GAMEOVER)
{
if (e.getX() <= 274 || e.getX() >= 541)
{
gfx.setColor(Color.yellow);
gfx.drawString("REPLAY", 274, 465);
}
if (e.getX() <= 59 || e.getX() >= 541)
{
gfx.setColor(Color.yellow);
gfx.drawString("EXIT", 283, 480);
}
}
}
public void windowActivated(WindowEvent e)
{
//DRAW REMAINING BALLS ON THE BOTTOM OF SCREEN
Graphics gfx = this.getGraphics();
int x = 30;
int y = 555;
int tempX = 30;
for (int z = 1; z <= remainingBalls - 1; z++)
{
for (int h = 1; h <= 3; h++)
{
gfx.setColor(Color.white);
gfx.fillArc(tempX, y, 12, 12, 0, 360);
tempX += 15;
}
gfx.setColor(Color.red);
gfx.fillArc(x, y, 12, 12, 0, 360);
x += 15;
}
if (remainingBalls <= 1)
{
gfx.setColor(Color.white);
gfx.fillArc(30, 555, 12, 12, 0, 360);
}
}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e)
{
ballThread = null;
this.dispose();
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}