diff --git a/src/pushbox/GamePannel.java b/src/pushbox/GamePannel.java
index fed53e4..92079a3 100644
--- a/src/pushbox/GamePannel.java
+++ b/src/pushbox/GamePannel.java
@@ -1,713 +1,731 @@
package pushbox;
import java.awt.Color;
+import java.awt.Font;
import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
+
+import javax.swing.GroupLayout;
+import javax.swing.ImageIcon;
import javax.swing.JButton;
+import javax.swing.JLabel;
import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+public class GamePannel extends JPanel {
+
+ /*
+ * new -1 ==null 0==greenball 1== red ball 2==blue ball,3==blackBall,4=pink
+ * ball 22==gray 23==green 24==brown 25==yellow
+ */
+
+ JButton[][] box;
+ int[][] boxvalue;
+ int ball;
+ int temp, temp1, temp2, temp3, temp4, temp5;
+ int prevb1i, prevb2i, prevb3i, prevb4i, prevb5i;
+ int prevb1j, prevb2j, prevb3j, prevb4j, prevb5j;
+ int n, leveli, levelj, levelno;
+ KeyAdapter hello;
+
+ public GamePannel() {
+ initComponents();
+ myinit();
+ showInfo();
+ }
+
+ public void myinit() {
+ setSize(820, 620);// our standard game pannel size
+ setOpaque(false);// to make buttons transparent
+
+ hello = new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ keyInput(e);
+ }
+ };
+
+ levelno = 1;
+
+ controlPannel.setBounds(10, 70, 700, 480);
+ if (levelno == 1)
+ level1();
+ if (levelno == 2)
+ level2();
+ controlPannel.setFocusable(true);
+ controlPannel.setOpaque(false);
+ controlPannel.setFocusTraversalKeysEnabled(false);
+ createBox();// creates boxes
+ }// my init
+
+ public void level1() {
+ ball = 0;
+ temp = temp1 = temp2 = temp3 = temp4 = temp5 = 0;
+ prevb1i = prevb2i = prevb3i = prevb4i = prevb5i = 0;
+ prevb1j = prevb2j = prevb3j = prevb4j = prevb5j = 0;
+
+ levelno = 1;
+ n = 3;
+
+ leveli = 11;
+ levelj = 16;
+ box = new JButton[leveli][levelj];
+ boxvalue = new int[leveli + 1][levelj + 1];
+
+ for (int i = 1; i < leveli; i++) {
+ for (int j = 1; j < levelj; j++) {
+ boxvalue[i][j] = (i == 1 || i == 10 || j == 1 || j == 15 || j == 5 || (j == 10 && i != 3)
+ || ((i == 6 && j != 2) && (i == 6 && j != 7) && (i == 6 && j != 12))) ? 22 : -1;
+ }
+ }
+
+ boxvalue[9][2] = 0;
+ boxvalue[2][9] = 1;
+ boxvalue[9][13] = 2;
+ boxvalue[2][2] = 23;
+ boxvalue[5][6] = 25;
+ boxvalue[5][9] = 25;
+ boxvalue[9][4] = 25;
+ boxvalue[9][9] = 25;
+ boxvalue[6][2] = 24;
+ boxvalue[6][7] = 24;
+ boxvalue[6][12] = 24;
+ boxvalue[3][10] = 24;
+ updateBall();
+ }
+
+ public void level2() {
+ ball = 0;
+ temp = temp1 = temp2 = temp3 = temp4 = temp5 = 0;
+ prevb1i = prevb2i = prevb3i = prevb4i = prevb5i = 0;
+ prevb1j = prevb2j = prevb3j = prevb4j = prevb5j = 0;
+
+ levelno = 2;
+ n = 5;
+
+ leveli = 11;
+ levelj = 21;
+ box = new JButton[leveli][levelj];
+ boxvalue = new int[leveli + 1][levelj + 1];
+
+ for (int i = 1; i < leveli; i++) {
+ for (int j = 1; j < levelj; j++) {
+ boxvalue[i][j] = (i == 1 || i == 10 || j == 1 || j == 20 || j == 7 || (i == 6 && j < 7)
+ || (i < 7 && j == 16) || (i == 7 && j > 7) || (i == 4 && (j > 7 && j < 16))) ? 22 : -1;
+ }
+ }
+
+ boxvalue[8][6] = 0;
+ boxvalue[5][4] = 1;
+ boxvalue[2][12] = 2;
+ boxvalue[5][12] = 3;
+ boxvalue[8][19] = 4;
+ boxvalue[9][2] = 25;
+ boxvalue[7][2] = 25;
+ boxvalue[2][2] = 25;
+ boxvalue[2][19] = 23;
+ boxvalue[3][15] = 25;
+ boxvalue[6][8] = 25;
+ boxvalue[8][9] = 24;
+ boxvalue[9][15] = 25;
+ boxvalue[2][16] = 24;
+ boxvalue[2][7] = 24;
+ boxvalue[8][7] = 24;
+ boxvalue[7][11] = 24;
+ boxvalue[5][2] = 25;
+ boxvalue[5][7] = 24;
+ boxvalue[3][8] = 25;
+ boxvalue[5][15] = 25;
+ boxvalue[8][8] = 24;
+ updateBall();
+ }
+
+ public void createBox() {
+ controlPannel.setLayout(new GridLayout(10, 15, 0, 0));
+ for (int i = 1; i < leveli; i++) {
+ for (int j = 1; j < levelj; j++) {
+ box[i][j] = new JButton();
+ box[i][j].setSize(45, 45);
+ box[i][j].setBackground(Color.white);
+ box[i][j].setFocusable(false);
+ controlPannel.add(box[i][j]);
+ }
+ }
+ controlPannel.grabFocus();
+ /*
+ * controlPannel.addKeyListener(new KeyAdapter(){ public void
+ * keyTyped(KeyEvent e){ keyInput(e); } });
+ */
+ controlPannel.addKeyListener(hello);
+
+ drawbox();
+ }
+
+ public void drawbox() {
+ // JOptionPane.showMessageDialog(null,"");
+ for (int i = 1; i < leveli; i++) {
+ for (int j = 1; j < levelj; j++) {
+ switch (boxvalue[i][j]) {
+ case 0:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("greenball.png")));
+ break;
+ case 1:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("redball.png")));
+ break;
+ case 2:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("blueball.png")));
+ break;
+ case 3:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("blackball.png")));
+ break;
+ case 4:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("pinkball.png")));
+ break;
+ case 22:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("graybox.png")));
+ break;
+ case 23:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("greenbox.png")));
+ break;
+ case 24:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("brownbox.png")));
+ break;
+ case 25:
+ box[i][j].setIcon(new ImageIcon(getClass().getResource("yellowbox.png")));
+ break;
+ default:
+ box[i][j].setIcon(null);
+ }
+ }
+ }
+ }
+
+ public void keyInput(KeyEvent e) {
+ char input = e.getKeyChar();
+
+ if (input == 'a' || input == 'A') {
+
+ level1: for (int i = 1; i < leveli; i++)
+ for (int j = 1; j < levelj; j++) {
+ if (boxvalue[i][j - 1] != 0 && boxvalue[i][j - 1] != 1 && boxvalue[i][j - 1] != 2
+ && boxvalue[i][j - 1] != 3 && boxvalue[i][j - 1] != 4) {
+ if (boxvalue[i][j] == ball && j > 1 && boxvalue[i][j - 1] != 22 && boxvalue[i][j - 1] != 24) {
+ temp = 111;
+ int re = wincheck(i, j - 1);
+ if (re == 1)
+ return;
+ if (boxvalue[i][j - 1] == 25) {
+ if (ball == 0) {
+ temp1++;
+ prevb1i = i;
+ prevb1j = j - 1;
+ }
+ if (ball == 1) {
+ temp2++;
+ prevb2i = i;
+ prevb2j = j - 1;
+ }
+ if (ball == 2) {
+ temp3++;
+ prevb3i = i;
+ prevb3j = j - 1;
+ }
+ if (ball == 3) {
+ temp4++;
+ prevb4i = i;
+ prevb4j = j - 1;
+ }
+ if (ball == 4) {
+ temp5++;
+ prevb5i = i;
+ prevb5j = j - 1;
+ }
+
+ }
+ boxvalue[i][j] = -1;
+ boxvalue[i][j - 1] = ball;
+ if (levelno == 1)
+ level1open(i, j - 1);
+ if (levelno == 2)
+ level2open(i, j - 1);
+ break level1;
+ }
+ }
+
+ }
+ if (temp1 == 0 && ball == 0 && temp == 111)
+ prev(prevb1i, prevb1j);
+ if (temp2 == 0 && ball == 1 && temp == 111)
+ prev(prevb2i, prevb2j);
+ if (temp3 == 0 && ball == 2 && temp == 111)
+ prev(prevb3i, prevb3j);
+ if (temp4 == 0 && ball == 3 && temp == 111)
+ prev(prevb4i, prevb4j);
+ if (temp5 == 0 && ball == 4 && temp == 111)
+ prev(prevb5i, prevb5j);
+ drawbox();
+ if (ball == 0 && temp == 111)
+ temp1 = 0;
+ if (ball == 1 && temp == 111)
+ temp2 = 0;
+ if (ball == 2 && temp == 111)
+ temp3 = 0;
+ if (ball == 3 && temp == 111)
+ temp4 = 0;
+ if (ball == 4 && temp == 111)
+ temp5 = 0;
+ temp = 0;
+
+ }
+ if (input == 'w' || input == 'W') {
+
+ level1: for (int i = 1; i < leveli; i++)
+ for (int j = 1; j < levelj; j++) {
+ if (boxvalue[i - 1][j] != 0 && boxvalue[i - 1][j] != 1 && boxvalue[i - 1][j] != 2
+ && boxvalue[i - 1][j] != 3 && boxvalue[i - 1][j] != 4) {
+ if (boxvalue[i][j] == ball && i > 1 && boxvalue[i - 1][j] != 22 && boxvalue[i - 1][j] != 24) {
+ temp = 222;
+ int re = wincheck(i - 1, j);
+ if (re == 1)
+ return;
+ if (boxvalue[i - 1][j] == 25) {
+ if (ball == 0) {
+ temp1++;
+ prevb1i = i - 1;
+ prevb1j = j;
+ }
+ if (ball == 1) {
+ temp2++;
+ prevb2i = i - 1;
+ prevb2j = j;
+ }
+ if (ball == 2) {
+ temp3++;
+ prevb3i = i - 1;
+ prevb3j = j;
+ }
+ if (ball == 3) {
+ temp4++;
+ prevb4i = i - 1;
+ prevb4j = j;
+ }
+ if (ball == 4) {
+ temp5++;
+ prevb5i = i - 1;
+ prevb5j = j;
+ }
+
+ }
+
+ boxvalue[i][j] = -1;
+ boxvalue[i - 1][j] = ball;
+ if (levelno == 1)
+ level1open(i - 1, j);
+ if (levelno == 2)
+ level2open(i - 1, j);
+ break level1;
+ }
+ }
+
+ }
+ if (temp1 == 0 && ball == 0 && temp == 222)
+ prev(prevb1i, prevb1j);
+ if (temp2 == 0 && ball == 1 && temp == 222)
+ prev(prevb2i, prevb2j);
+ if (temp3 == 0 && ball == 2 && temp == 222)
+ prev(prevb3i, prevb3j);
+ if (temp4 == 0 && ball == 3 && temp == 222)
+ prev(prevb4i, prevb4j);
+ if (temp5 == 0 && ball == 4 && temp == 222)
+ prev(prevb5i, prevb5j);
+ drawbox();
+ if (ball == 0 && temp == 222)
+ temp1 = 0;
+ if (ball == 1 && temp == 222)
+ temp2 = 0;
+ if (ball == 2 && temp == 222)
+ temp3 = 0;
+ if (ball == 3 && temp == 222)
+ temp4 = 0;
+ if (ball == 4 && temp == 222)
+ temp5 = 0;
+ temp = 0;
+
+ }
+ if (input == 's' || input == 'S') {
+
+ level1: for (int i = 0; i < leveli; i++)
+ for (int j = 1; j < levelj; j++) {
+ if (boxvalue[i + 1][j] != 0 && boxvalue[i + 1][j] != 1 && boxvalue[i + 1][j] != 2
+ && boxvalue[i + 1][j] != 3 && boxvalue[i + 1][j] != 4) {
+ if (boxvalue[i][j] == ball && i < 10 && boxvalue[i + 1][j] != 22 && boxvalue[i + 1][j] != 24) {
+ temp = 333;
+ int re = wincheck(i + 1, j);
+ if (re == 1)
+ return;
+ if (boxvalue[i + 1][j] == 25) {
+ if (ball == 0) {
+ temp1++;
+ prevb1i = i + 1;
+ prevb1j = j;
+ }
+ if (ball == 1) {
+ temp2++;
+ prevb2i = i + 1;
+ prevb2j = j;
+ }
+ if (ball == 2) {
+ temp3++;
+ prevb3i = i + 1;
+ prevb3j = j;
+ }
+ if (ball == 3) {
+ temp4++;
+ prevb4i = i + 1;
+ prevb4j = j;
+ }
+ if (ball == 4) {
+ temp5++;
+ prevb5i = i + 1;
+ prevb5j = j;
+ }
+
+ }
+
+ boxvalue[i][j] = -1;
+ boxvalue[i + 1][j] = ball;
+ if (levelno == 1)
+ level1open(i + 1, j);
+ if (levelno == 2)
+ level2open(i + 1, j);
+ break level1;
+ }
+ }
+
+ }
+
+ if (temp1 == 0 && ball == 0 && temp == 333)
+ prev(prevb1i, prevb1j);
+ if (temp2 == 0 && ball == 1 && temp == 333)
+ prev(prevb2i, prevb2j);
+ if (temp3 == 0 && ball == 2 && temp == 333)
+ prev(prevb3i, prevb3j);
+ if (temp4 == 0 && ball == 3 && temp == 333)
+ prev(prevb4i, prevb4j);
+ if (temp5 == 0 && ball == 4 && temp == 333)
+ prev(prevb5i, prevb5j);
+ drawbox();
+ if (ball == 0 && temp == 333)
+ temp1 = 0;
+ if (ball == 1 && temp == 333)
+ temp2 = 0;
+ if (ball == 2 && temp == 333)
+ temp3 = 0;
+ if (ball == 3 && temp == 333)
+ temp4 = 0;
+ if (ball == 4 && temp == 333)
+ temp5 = 0;
+ temp = 0;
+ }
+ if (input == 'd' || input == 'D') {
+ level1: for (int i = 1; i < leveli; i++)
+ for (int j = 1; j < levelj; j++) {
+ if (boxvalue[i][j + 1] != 0 && boxvalue[i][j + 1] != 1 && boxvalue[i][j + 1] != 2
+ && boxvalue[i][j + 1] != 3 && boxvalue[i][j + 1] != 4) {
+ if (boxvalue[i][j] == ball && j < levelj - 1 && boxvalue[i][j + 1] != 22
+ && boxvalue[i][j + 1] != 24) {
+ temp = 444;
+ int re = wincheck(i, j + 1);
+ if (re == 1)
+ return;
+ if (boxvalue[i][j + 1] == 25) {
+ if (ball == 0) {
+ temp1++;
+ prevb1i = i;
+ prevb1j = j + 1;
+ }
+ if (ball == 1) {
+ temp2++;
+ prevb2i = i;
+ prevb2j = j + 1;
+ }
+ if (ball == 2) {
+ temp3++;
+ prevb3i = i;
+ prevb3j = j + 1;
+ }
+ if (ball == 3) {
+ temp4++;
+ prevb4i = i;
+ prevb4j = j + 1;
+ }
+ if (ball == 4) {
+ temp5++;
+ prevb5i = i;
+ prevb5j = j + 1;
+ }
+
+ }
+
+ boxvalue[i][j] = -1;
+ boxvalue[i][j + 1] = ball;
+ if (levelno == 1)
+ level1open(i, j + 1);
+ if (levelno == 2)
+ level2open(i, j + 1);
+ break level1;
+ }
+ }
+ }
+ if (temp1 == 0 && ball == 0 && temp == 444)
+ prev(prevb1i, prevb1j);
+ if (temp2 == 0 && ball == 1 && temp == 444)
+ prev(prevb2i, prevb2j);
+ if (temp3 == 0 && ball == 2 && temp == 444)
+ prev(prevb3i, prevb3j);
+ if (temp4 == 0 && ball == 3 && temp == 444)
+ prev(prevb4i, prevb4j);
+ if (temp5 == 0 && ball == 4 && temp == 444)
+ prev(prevb5i, prevb5j);
+ drawbox();
+ if (ball == 0 && temp == 444)
+ temp1 = 0;
+ if (ball == 1 && temp == 444)
+ temp2 = 0;
+ if (ball == 2 && temp == 444)
+ temp3 = 0;
+ if (ball == 3 && temp == 444)
+ temp4 = 0;
+ if (ball == 4 && temp == 444)
+ temp5 = 0;
+ temp = 0;
+
+ }
+ if (input == KeyEvent.VK_SPACE) {
+ ball = (ball + 1) % n;
+ updateBall();
+ }
+
+ }
+
+ public void prev(int i, int j) {
+ if (boxvalue[i][j] != 0 && boxvalue[i][j] != 1 && boxvalue[i][j] != 2 && boxvalue[i][j] != 3
+ && boxvalue[i][j] != 4)
+ boxvalue[i][j] = 25;
+
+ }
+
+ public void level1open(int i, int j) {
+ if (ball == 0 && i == 9 && j == 4)
+ boxvalue[6][12] = -1;
+ if (ball == 0 && (i != 9 || j != 4))
+ boxvalue[6][12] = 24;
+ if (ball == 1 && i == 5 && j == 9)
+ boxvalue[3][10] = -1;
+ if (ball == 1 && (i != 5 || j != 9))
+ boxvalue[3][10] = 24;
+ if (ball == 2 && i == 5 && j == 6)
+ boxvalue[6][7] = -1;
+ if (ball == 2 && (i != 5 || j != 6))
+ boxvalue[6][7] = 24;
+ if (ball == 1 && i == 9 && j == 9)
+ boxvalue[6][2] = -1;
+ if (ball == 1 && (i != 9 || j != 9))
+ boxvalue[6][2] = 24;
+ }
+
+ public void level2open(int i, int j) {
+ if (ball == 2 && i == 3 && j == 15)
+ boxvalue[2][16] = -1;
+ if (ball == 2 && (i != 3 || j != 15))
+ boxvalue[2][16] = 24;
+ if (ball == 1 && i == 2 && j == 2)
+ boxvalue[2][7] = -1;
+ if (ball == 1 && (i != 2 || j != 2))
+ boxvalue[2][7] = 24;
+ if (ball == 3 && (i == 6 && j == 8))
+ boxvalue[5][7] = -1;
+ if (ball == 3 && (i != 6 || j != 8))
+ boxvalue[5][7] = 24;
+ if (ball == 1 && i == 5 && j == 2)
+ boxvalue[8][7] = -1;
+ if (ball == 1 && (i != 5 || j != 2))
+ boxvalue[8][7] = 24;
+ if (ball == 2 && i == 3 && j == 8)
+ boxvalue[8][9] = -1;
+ if (ball == 2 && (i != 3 || j != 8))
+ boxvalue[8][9] = 24;
+ if (ball == 4 && i == 9 && j == 15)
+ boxvalue[7][11] = -1;
+ if (ball == 4 && (i != 9 || j != 15))
+ boxvalue[7][11] = 24;
+ if (ball == 3 && i == 5 && j == 15)
+ boxvalue[8][8] = -1;
+ if (ball == 3 && (i != 5 || j != 15))
+ boxvalue[8][8] = 24;
+ if (ball == 0 && i == 9 && j == 2)
+ boxvalue[8][8] = -1;
+ if (ball == 0 && (i != 9 || j != 2) && boxvalue[5][15] != 3)
+ boxvalue[8][8] = 24;
+ if (ball == 0 && i == 7 && j == 2)
+ boxvalue[8][9] = -1;
+ if (ball == 0 && (i != 7 || j != 2) && boxvalue[3][8] != 2)
+ boxvalue[8][9] = 24;
+ }
+
+ public int wincheck(int i, int j) {
+ if (boxvalue[i][j] == 23) {
+
+ if (levelno == 1) {
+ JOptionPane.showMessageDialog(null, "Yeah level 1 cleared, Go to next level");
+ levelno = 2;
+ controlPannel.removeAll();
+ controlPannel.repaint();
+ controlPannel.removeKeyListener(hello);
+ level2();
+ createBox();
+ return 1;
+ }
+ if (levelno == 2) {
+ JOptionPane.showMessageDialog(null, "Yeah you win this game go and play other games");
+ }
+ }
+ return 0;
+ }
+
+ public void updateBall() {
+ String str = "";
+ switch (ball) {
+ case 0: {
+ str = "SkyBlue";
+ break;
+ }
+ case 1: {
+ str = "Red";
+ break;
+ }
+ case 2: {
+ str = "Blue";
+ break;
+ }
+ case 3: {
+ str = "Black";
+ break;
+ }
+ case 4: {
+ str = "Pink";
+ break;
+ }
+ }
+ BallLabel.setText("Current Ball is :- " + str);
+ }
+
+ public void showInfo() {
+ String str = "1) Use W to move ball up\n" + "2) Use A to move ball left\n" + "3) Use S to move ball down\n"
+ + "4) Use D to move ball right\n" + "5) Use SPACE to move to other ball\n"
+ + "6) To win make AnyColor Ball to reach green box\n"
+ + "7) Put specific ball on specific Yellow box that will open a specific Brown box\n"
+ + "8) Current ball shows the current ball in movement\n" + "9) RESET button to reset the game\n"
+ + "10) RULES Button to show instruction\n";
+ JOptionPane.showMessageDialog(null, str, "INSTRUCTIONS", HEIGHT);
+ }
+
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+ setLayout(null);
+
+ // set layout
+ controlPannel = new JPanel();
+ GroupLayout controlPannelLayout = new GroupLayout(controlPannel);
+ controlPannel.setLayout(controlPannelLayout);
+ controlPannelLayout.setHorizontalGroup(
+ controlPannelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
+ controlPannelLayout.setVerticalGroup(
+ controlPannelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
+
+ add(controlPannel);
+ controlPannel.setBounds(20, 60, 560, 440);
+ controlPannel.getAccessibleContext().setAccessibleName("");
+
+ // set Reset button
+ jButton1 = new JButton("Reset");
+ jButton1.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+ add(jButton1);
+ jButton1.setBounds(720, 200, 90, 32);
+
+ // set Rules button
+ jButton2 = new JButton("Rules");
+ jButton2.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ jButton2ActionPerformed(evt);
+ }
+ });
+ add(jButton2);
+ jButton2.setBounds(720, 270, 90, 32);
+
+ // set current ball label
+ BallLabel = new JLabel("Current Ball is :- ");
+ BallLabel.setFont(new Font("Cantarell", 0, 18)); // NOI18N
+ BallLabel.setForeground(Color.white);
+ add(BallLabel);
+ BallLabel.setBounds(260, 560, 220, 20);
+
+ // set label
+ jLabel1 = new JLabel(" Ball And Bridge");
+ jLabel1.setBackground(Color.white);
+ jLabel1.setFont(new Font("DejaVu Sans Condensed", 1, 24)); // NOI18N
+ jLabel1.setForeground(Color.white);
+ add(jLabel1);
+ jLabel1.setBounds(120, 20, 420, 29);
+
+ // set background image
+ background_Image = new JLabel();
+ background_Image.setFocusable(false);
+ background_Image.setIcon(new ImageIcon(getClass().getResource("/pushbox/try1.jpg"))); // NOI18N
+ add(background_Image);
+ background_Image.setBounds(0, 0, 820, 620);
+ }// //GEN-END:initComponents
+
+ private void jButton1ActionPerformed(ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
+
+ if (levelno == 1) {
+ levelno = 1;
+ controlPannel.removeAll();
+ controlPannel.repaint();
+ controlPannel.removeKeyListener(hello);
+ level1();
+ createBox();
+ }
+ if (levelno == 2) {
+ levelno = 2;
+ controlPannel.removeAll();
+ controlPannel.repaint();
+ controlPannel.removeKeyListener(hello);
+ level2();
+ createBox();
+ }
+ controlPannel.grabFocus();
+ // TODO add your handling code here:
+ }// GEN-LAST:event_jButton1ActionPerformed
+
+ private void jButton2ActionPerformed(ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed
+ showInfo();
+ controlPannel.grabFocus();// TODO add your handling code here:
+ }// GEN-LAST:event_jButton2ActionPerformed
-public class GamePannel extends javax.swing.JPanel {
-
- /* new
- -1 ==null 0==greenball 1== red ball 2==blue ball,3==blackBall,4=pink ball 22==gray 23==green 24==brown 25==yellow
- */
-
-
- JButton[][] box ;
- int[][] boxvalue;
- int ball=0;
- int oldball=0;
- int temp1=0,temp2=0,temp3=0,temp4=0,temp5=0,prevb1i=0,prevb1j=0,prevb2i=0,prevb2j=0,prevb3i=0,prevb3j=0,temp=0,one,two,prevb4i=0,prevb4j=0,prevb5i=0,prevb5j=0;
- int n=0,leveli,levelj,levelno=1;
- KeyAdapter hello=new KeyAdapter(){
- public void keyTyped(KeyEvent e){
- keyInput(e);
- }
- };
- int click=1;
- public GamePannel() {
-
- initComponents();
- myinit();
-
- }
-
- public final void myinit(){
- setSize(820, 620);//our standard game pannel size
- setOpaque(false);//to make buttons transparent
- controlPannel.setBounds(10,70,700,480);
- if(levelno==1) level1();
- if(levelno==2) level2();
- controlPannel.setFocusable(true);
- controlPannel.setOpaque(false);
- controlPannel.setFocusTraversalKeysEnabled(false);
- createBox();//creates boxes
- }//my init
-
- public void level1()
- {
- if(click==1)
- showInfo();
- updateBall();
- box=new JButton[11][16];
- leveli=11;
- levelj=16;
- levelno=1;
- boxvalue=new int[12][17];
- n=3;
- for(int i=1;i7) || (i==4 && (j>7 && j<16)))
-
- {
- boxvalue[i][j]=22;
- }
- else
- boxvalue[i][j]=-1;
- }
- boxvalue[8][6]=0;
- boxvalue[5][4]=1;
- boxvalue[2][12]=2;
- boxvalue[5][12]=3;
- boxvalue[8][19]=4;
- boxvalue[9][2]=25;
- boxvalue[7][2]=25;
- boxvalue[2][2]=25;
- boxvalue[2][19]=23;
- boxvalue[3][15]=25;
- boxvalue[6][8]=25;
- boxvalue[8][9]=24;
- boxvalue[9][15]=25;
- boxvalue[2][16]=24;
- boxvalue[2][7]=24;
- boxvalue[8][7]=24;
- boxvalue[7][11]=24;
- boxvalue[5][2]=25;
- boxvalue[5][7]=24;
- boxvalue[3][8]=25;
- boxvalue[5][15]=25;
- boxvalue[8][8]=24;
- updateBall();
- n=5;
- }
-
- public void createBox(){
- controlPannel.setLayout(new GridLayout(10,15,0,0));
- for(int i=1;i1 && boxvalue[i][j-1]!=22 && boxvalue[i][j-1]!=24 )
- {
- temp=111;
- int re= wincheck(i,j-1);
- if(re==1) return;
- if(boxvalue[i][j-1]==25)
- {
- if(ball==0)
- {
- temp1++;
- prevb1i=i;
- prevb1j=j-1;
- }
- if(ball==1)
- {
- temp2++;
- prevb2i=i;
- prevb2j=j-1;
- }
- if(ball==2)
- {
- temp3++;
- prevb3i=i;
- prevb3j=j-1;
- }
- if(ball==3)
- {
- temp4++;
- prevb4i=i;
- prevb4j=j-1;
- }
- if(ball==4)
- {
- temp5++;
- prevb5i=i;
- prevb5j=j-1;
- }
-
- }
- boxvalue[i][j]=-1;
- boxvalue[i][j-1]=ball;
- if(levelno==1) level1open(i,j-1);
- if(levelno==2) level2open(i,j-1);
- break level1;
- }
- }
-
-
- }
- if(temp1==0 && ball ==0 && temp==111 ) prev(prevb1i,prevb1j);
- if(temp2==0 && ball ==1 && temp==111 ) prev(prevb2i,prevb2j);
- if(temp3==0 && ball ==2 && temp==111 ) prev(prevb3i,prevb3j);
- if(temp4==0 && ball ==3 && temp==111 ) prev(prevb4i,prevb4j);
- if(temp5==0 && ball ==4 && temp==111 ) prev(prevb5i,prevb5j);
- drawbox();
- if(ball==0 && temp==111) temp1=0;
- if(ball==1 && temp==111) temp2=0;
- if(ball==2 && temp==111) temp3=0;
- if(ball==3 && temp==111) temp4=0;
- if(ball==4 && temp==111) temp5=0;
- temp=0;
-
-
- }
- if(input=='w' || input=='W')
- {
-
- level1:
- for(int i=1;i1 && boxvalue[i-1][j]!=22 && boxvalue[i-1][j]!=24)
- {
- temp=222;
- int re= wincheck(i-1,j);
- if(re==1) return;
- if(boxvalue[i-1][j]==25)
- {
- if(ball==0)
- {
- temp1++;
- prevb1i=i-1;
- prevb1j=j;
- }
- if(ball==1)
- {
- temp2++;
- prevb2i=i-1;
- prevb2j=j;
- }
- if(ball==2)
- {
- temp3++;
- prevb3i=i-1;
- prevb3j=j;
- }
- if(ball==3)
- {
- temp4++;
- prevb4i=i-1;
- prevb4j=j;
- }
- if(ball==4)
- {
- temp5++;
- prevb5i=i-1;
- prevb5j=j;
- }
-
-
- }
-
- boxvalue[i][j]=-1;
- boxvalue[i-1][j]=ball;
- if(levelno==1) level1open(i-1,j);
- if(levelno==2) level2open(i-1,j);
- break level1;
- }}
-
- }
- if(temp1==0 && ball ==0 && temp==222 ) prev(prevb1i,prevb1j);
- if(temp2==0 && ball ==1 && temp==222 ) prev(prevb2i,prevb2j);
- if(temp3==0 && ball ==2 && temp==222 ) prev(prevb3i,prevb3j);
- if(temp4==0 && ball ==3 && temp==222 ) prev(prevb4i,prevb4j);
- if(temp5==0 && ball ==4 && temp==222 ) prev(prevb5i,prevb5j);
- drawbox();
- if(ball==0 && temp==222) temp1=0;
- if(ball==1 && temp==222) temp2=0;
- if(ball==2 && temp==222) temp3=0;
- if(ball==3 && temp==222) temp4=0;
- if(ball==4 && temp==222) temp5=0;
- temp=0;
-
- }
- if(input=='s' || input=='S')
- {
-
- level1:
- for(int i=0;i//GEN-BEGIN:initComponents
- private void initComponents() {
-
- controlPannel = new javax.swing.JPanel();
- jButton1 = new javax.swing.JButton();
- BallLabel = new javax.swing.JLabel();
- jLabel1 = new javax.swing.JLabel();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- background_Image = new javax.swing.JLabel();
-
- setLayout(null);
-
- controlPannel.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- controlPannelMouseClicked(evt);
- }
- public void mouseEntered(java.awt.event.MouseEvent evt) {
- controlPannelMouseEntered(evt);
- }
- });
-
- javax.swing.GroupLayout controlPannelLayout = new javax.swing.GroupLayout(controlPannel);
- controlPannel.setLayout(controlPannelLayout);
- controlPannelLayout.setHorizontalGroup(
- controlPannelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 0, Short.MAX_VALUE)
- );
- controlPannelLayout.setVerticalGroup(
- controlPannelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 0, Short.MAX_VALUE)
- );
-
- add(controlPannel);
- controlPannel.setBounds(20, 60, 560, 440);
- controlPannel.getAccessibleContext().setAccessibleName("");
-
- jButton1.setText("Reset");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- add(jButton1);
- jButton1.setBounds(720, 200, 90, 32);
-
- BallLabel.setFont(new java.awt.Font("Cantarell", 0, 18)); // NOI18N
- BallLabel.setForeground(java.awt.Color.white);
- BallLabel.setText("Current Ball is :- ");
- add(BallLabel);
- BallLabel.setBounds(260, 560, 220, 20);
-
- jLabel1.setBackground(java.awt.Color.white);
- jLabel1.setFont(new java.awt.Font("DejaVu Sans Condensed", 1, 24)); // NOI18N
- jLabel1.setForeground(java.awt.Color.white);
- jLabel1.setText(" Ball And Bridge");
- add(jLabel1);
- jLabel1.setBounds(120, 20, 420, 29);
-
- jButton2.setText("Rules");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- add(jButton2);
- jButton2.setBounds(720, 270, 90, 32);
-
- jButton3.setText("Focus");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- add(jButton3);
- jButton3.setBounds(730, 510, 80, 32);
-
- background_Image.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pushbox/try1.jpg"))); // NOI18N
- add(background_Image);
- background_Image.setBounds(0, 0, 820, 620);
- }// //GEN-END:initComponents
-
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
-
- if(levelno==1)
- {
- levelno=1;
- controlPannel.removeAll();
- controlPannel.repaint();
- controlPannel.removeKeyListener(hello);
- level1();
- createBox();
-
-
- }
- if(levelno==2)
- {
- levelno=2;
- controlPannel.removeAll();
- controlPannel.repaint();
- controlPannel.removeKeyListener(hello);
- level2();
- createBox();
- }
- controlPannel.grabFocus();
-// TODO add your handling code here:
- }//GEN-LAST:event_jButton1ActionPerformed
-
- private void controlPannelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlPannelMouseEntered
- controlPannel.grabFocus(); // TODO add your handling code here:
- }//GEN-LAST:event_controlPannelMouseEntered
-
- private void controlPannelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlPannelMouseClicked
- controlPannel.grabFocus();
- // TODO add your handling code here:
- }//GEN-LAST:event_controlPannelMouseClicked
-
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- showInfo();
- controlPannel.grabFocus();// TODO add your handling code here:
- }//GEN-LAST:event_jButton2ActionPerformed
-
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
- controlPannel.grabFocus(); // TODO add your handling code here:
- }//GEN-LAST:event_jButton3ActionPerformed
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JLabel BallLabel;
- private javax.swing.JLabel background_Image;
- private javax.swing.JPanel controlPannel;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel1;
- // End of variables declaration//GEN-END:variables
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private JLabel BallLabel;
+ private JLabel background_Image;
+ private JPanel controlPannel;
+ private JButton jButton1;
+ private JButton jButton2;
+ private JLabel jLabel1;
+ // End of variables declaration//GEN-END:variables
}
diff --git a/src/pushbox/MainFrame.java b/src/pushbox/MainFrame.java
index c91f18f..08ee2ff 100644
--- a/src/pushbox/MainFrame.java
+++ b/src/pushbox/MainFrame.java
@@ -1,63 +1,75 @@
package pushbox;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.imageio.ImageIO;
+import javax.swing.JFrame;
+import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.WindowConstants;
+
/**
*
* @author srb
*/
-public class MainFrame extends javax.swing.JFrame {
-
- public MainFrame() {
- initComponents();
- myinit();
- }
-
- public final void myinit(){
- setSize(820,620);
- setResizable(false);
- gamePannel = new GamePannel();
-
- add(gamePannel);
- }
-
- @SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
- private void initComponents() {
-
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(null);
-
- pack();
- }// //GEN-END:initComponents
-
- public static void main(String args[]) {
-
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
-
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new MainFrame().setVisible(true);
- }
- });
- new MainFrame().setIconImage(new imageIcon(getClass().getClassLoader().getResource("mainicon.jpg")));
- }
-
- //my variables
- GamePannel gamePannel;
- // Variables declaration - do not modify//GEN-BEGIN:variables
- // End of variables declaration//GEN-END:variables
+public class MainFrame extends JFrame {
+
+ public MainFrame() {
+ initComponents();
+ myinit();
+ }
+
+ public void myinit() {
+ setSize(820, 620);
+ setResizable(false);
+ gamePannel = new GamePannel();
+
+ add(gamePannel);
+
+ try {
+ setIconImage(ImageIO.read(MainFrame.class.getResource("mainicon.jpg")));
+ } catch (IOException e) {
+ Logger.getLogger(MainFrame.class.getName()).log(Level.WARNING, null, e);
+ }
+ setVisible(true);
+ }
+
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ getContentPane().setLayout(null);
+
+ pack();
+ }// //GEN-END:initComponents
+
+ public static void main(String args[]) {
+
+ try {
+ for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
+ | UnsupportedLookAndFeelException ex) {
+ Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new MainFrame();
+ }
+ });
+ }
+
+ // my variables
+ private GamePannel gamePannel;
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
}
diff --git a/src/pushbox/PushBox.java b/src/pushbox/PushBox.java
index d3bf2f5..6e3d35f 100644
--- a/src/pushbox/PushBox.java
+++ b/src/pushbox/PushBox.java
@@ -6,9 +6,8 @@
*/
public class PushBox {
- public static void main(String[] args) {
- MainFrame mainframe = new MainFrame();
- mainframe.setVisible(true);
- }
-
+ public static void main(String[] args) {
+ MainFrame mainframe = new MainFrame();
+ }
+
}