HOW TO MAKE SIMPLE PUZZLE GAME USING JAVA APPLETS

SIMPLE PUZZLE GAME CODE

OBJECTIVE OF THE PROJECT


“9 BOX PUZZLE GAME USING JAVA APPLETS” IS
A PROJECT  TO INTENDED CREATE A GAME WHERE A USER CAN PLAY WITH NUMBERS ARRANGED IN SOME RANDOM ORDER TO ARRANGE IT IN A PRIORITY ORDER (ASCENDING ORDER)

THERE ARE 9 BOXES CREATED WITH APPLETS
OF WHICH 8 BOXES HAVE NUMBERS FROM 1 TO 8 AND 1 BOX IS LEFT EMPTY.

THE PROGRAM ONCE EXECUTED ASKS THE USER TO ENTER HIS NAME AND THEN THE USER IS REQUIRED TO ARRANGE THE NUMBERS IN THE BOXES IN THE PROPER ORDER. THE PROGRAM KEEPS TRACK OF THE NUMBER OF ATTEMPTS MADE BY THE USER AND WHEN THE USER IS DONE WITH ARRANGEMENT THE PROGRAM DISPLAYS THE TOTAL ATTEMPTS MADE BY THE USER IN SUCCESSFULLY ARRANGING THE NUMBERS


CONTENTS USED IN THIS SIMPLE PUZZLE GAME

1.   Hardware and Software Requirements
2.   Introduction About
i.)              JAVA
ii.)             I/O
iii.)            Java Lang
iv.)            Java AWT
v.)             Java Applet
vi.)           Java AWT Graphics
vii.)          Java AWT Event
viii.)         Java Lang String
ix.)           Java Swing
x.)            Eclipse IDE
3.   Objective of Project
4.   E-R Diagram
5.   Code Of 9 Box Puzzle Game
6.   Snapshot of 9 Box Puzzle Game

HARDWARE AND SOFTWARE REQUIREMENTS

HARDWARE:-

CPU->PENTIUM BASED
RAM->128 MB(MINIMUM)
HARD DISK->16 GB(MINIMUM)
MONITOR->14’’

SOFTWARE:-

OPERATING SYSTEM-> WINDOWS 7
DEVELOPING LANGUAGE->J2EE
SDK -> ECLIPSE

Logic Code For Project 9 BOX PUZZLE GAME :-






public class g_p extends JApplet implements ActionListener, KeyListener
{
private mbutton[] button;
private Label label111,label02,label333,label4;
private TextField textfld1,textfld2;
private String[] StringB=
{
"5","3","6","4","8","1","2","7"," ","Start","Restart","Finished" 
}
private String[] StringB1=
{
"1","2","3","4","5","6","7","8"," "
}
private int click_count; 
GridBagLayout grid = new GridBagLayout();
grbcnst grbc1 = new grbcnst();
JPanel pan1,pan2;
String str1="";

public void init()
{
label111 = new Label("Puzzle"); 
label111.setFont(new Font("Ahano" , Font.BOLD,20));
label111.setForeground(Color.blue);
label02=new Label("Name of the Player");
label02.setFont(new Font("Ahano" ,Font.BOLD,15));
label02.setForeground(Color.blue);
label333=new Label("Number of the Clicks");
label333.setFont(new Font("Ahano",Font.BOLD,15));
label333.setForeground(Color.blue);
label4=new Label ( "                                     ");
button =new mbutton[12];
for(int i=0;i<12;i++)
{
button[i]= new mbutton ( StringB[i],Color.black);
button[i].addActionListener(this);
}
textfld1=new TextField(20);
textfld2=new TextField(20);
textfld1.setFont(new Font("Ahano",Font.BOLD,12));
textfld2.setFont(new Font("Ahano",Font.BOLD,12));
textfld1.setText("");
textfld1.addKeyListener(this);
textfld2.setText("");
click_count=0;
dspa();


class mbutton extends JButton
{
public mbutton(String name, Color aaa) 
{
this.setLabel(name);
this.setForeground(aaa);
}

class MouseCalcButtonAdapter extends MouseAdapter
{
public void moen(MouseEvent me){}

public void mouseExited(MouseEvent me){}
}
}
public void keyTyped(KeyEvent e)
  {
char ch;
ch=e.getKeyChar();
str1 = str1 + char;

}
public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}

public void actionPerformed(ActionEvent ae)
{
int ind=8,i;
String str,temp,count;
boolean check;

for(i=0;i<9;i++)

if(button[i].getLabel()==" ")
ind=i; 
}
if(am.GeSc()==button[9])
{
for(int j=0;j<=8;j++)
button[j].setEnabled(true);
button[9].setEnabled(false);
}


if(am.GeSc()==button[10])

{
for(i=0;i<9;i++)
{
button[i].setEnabled(true);
btn[a].sl(StringB[i]);
}
click_count=0;
textfld2.setText("0");
}

if((am.GeSc() != button[9]) || (am.GeSc() != button[10]) )
{
check=checkStatus();


if(check==false)
{
if (am.GeSc() == button[0])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==1||ind==3)
{
str=button[0].getLabel();
button[0].setLabel(" ");
button[ind].slabel (string);
}
}
if (am.GeSc()== button[1])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==0|| ind==4 ||ind==2)
{
str=button[1].getLabel();
button[1].setLabel (" ");
button[ind]. setLabel(str);
}
}
if (am.GeSc()== button[2])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==1||ind==5)
{
str=button[2]. getLabel();
button[2].setLabel(" ");
button[ind]. setLabel(str);
}
}
if (am.GeSc()== button[3])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==0||ind==4 ||ind==6)
{
str=button[3].getLabel();
button[3].setLabel(" ");
button[ind].setLabel(str);
}
}
if (am.GeSc()==button[4])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==1||ind==3 ||ind==5||ind==7)
{
str=button[4]. getLabel();
button[4].setLabel(" ");
button[ind].setLabel(str);
}
}
if (am.GeSc()==button[5])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==2||ind==4 ||ind==8)
{
str=button[5]. getLabel();
button[5].setLabel(" ");
button[ind].setLabel(str);
}
}
if (am.GeSc()==button[6])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==3||ind==7)
{
str=button[6].getLabel();
button[6].setLabel(" ");
button[ind].setLabel(str);
}
}
if (am.GeSc()==button[7])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==6||ind==4 ||ind==8)
{
str=button[7]. getLabel();
button[7].setLabel(" ");
button[ind].setLabel(str);
}
}
if (am.GeSc()==button[8])
{
count=Integer.toString(countClicks());
textfld2.setText(count);
if (ind==5||ind==7)
{
str=button[8]. getLabel();
button[8].setLabel(" ");
button[ind]. setLabel(str);
}
}
if(am.GeSc()==button[10])
//Restart button.
{
for(i=0;i<9;i++)
{
button[i].setEnabled(true);
btn[a].sl(StringB[i]);
}
click_count=0;
textfld2.setText("0");
}
if (am.GeSc()==button[11])
{
for(a=0;a<=8;a++)
{
btn[a].sl (StringB1[i]);
}
click_count=0;
textfld2.setText("0");
button[11].setEnabled(false);
button[10].setEnabled(false);
}
}
else
{

String st = str1 + ", you have won the game.";
for (int j=0;j<=8;j++)
  button[j].setEnabled(false);
  JOptionPane.showMessageDialog(null,st);
 
}
}
}

void dspa()
{
JPanel pa4 = new JPanel(); 
pan1 = new JPanel(); 
pan1.setLayout(grid);
grbc1.weightx = 100;    
grbc1.weighty = 100;   
grbc1.ipady = 0;
grbc1.ipadx = 0; 
    grbc1.gridwidth =1;  
      grbc1.gridheight=1;
      grbc1.gridx = 0;
      grbc1.gridy = 0;        
      grid.setConstraints(label111, grbc1);
pan1.add(label111);
grbc1.weightx=100;
grbc1.weighty = 100;  
grbc1.ipady = 5;
grbc1.ipadx = 5; 
      grbc1.gridwidth =1;    
      grbc1.gridheight=1;
      grbc1.gridx = 1;        
      grbc1.gridy = 0;        
      grid.setConstraints(button[9], grbc1);
pan1.add(button[9]);

grbc1.weightx=100;
grbc1.weighty = 100;
grbc1.ipady = 0; 
grbc1.ipadx = 0;  
    grbc1.gridwidth =1;    
grbc1.gridheight=2;
grbc1.gridx = 0;        
grbc1.gridy = 2;        
grid.setConstraints(label02, grbc1);
pan1.add(label02);

grbc1.weightx=100;
grbc1.weighty = 100;  
grbc1.ipady = 0;      
grbc1.ipadx = 0;  
grbc1.gridwidth =1;    
grbc1.gridheight=2;
grbc1.gridx = 1;        
  grbc1.gridy = 2;        

grid.setConstraints(textfld1, grbc1);
pan1.add(textfld1);
grbc1.weightx = 100;    
grbc1.weighty = 100;   
grbc1.ipady = 0;      
grbc1.ipadx = 0;      
        grbc1.gridwidth =1 ;  
        grbc1.gridheight=2;
        grbc1.gridx = 0;        
  grbc1.gridy = 4;      
pa4.setLayout(new GridLayout(3,3,5,5));
  for(int i=0;i<9;i++)
{
pa4.add(button[i]); 
button[i].setEnabled(false);
  }
  grid.setConstraints(pa4, grbc1);
  pan1.add(pa4);

  grbc1.weightx=100;
  grbc1.weighty=100;    
  grbc1.ipady = 0;        
  grbc1.ipadx = 0;  
  grbc1.gridwidth =1;
  grbc1.gridheight=1;
  grbc1.gridx = 0;   
  grbc1.gridy = 6;   

grid.setConstraints(label333, grbc1);
pan1.add(label333);
grbc1.ipady = 0;      
grbc1.ipadx = 0;      
   
grbc1.weightx = 100;
    grbc1.weighty = 100;  
      grbc1.gridwidth =1 ;
      grbc1.gridheight=1;  
grbc1.gridx = 1;      
      grbc1.gridy = 6;      
    grid.setConstraints(textfld2, grbc1);
pan1.add(textfld2);
       
grbc1.ipady = 5;      
grbc1.ipadx = 5;      
    grbc1.weighty = 100;
    grbc1.weightx = 100;  
    grbc1.gridwidth =1;
grbc1.gridheight=1;  
grbc1.gridx = 0;      
grbc1.gridy = 7;      
grid.setConstraints(button[10], grbc1);
      pan1.add(button[10]);
grbc1.ipady = 5;      
grbc1.ipadx = 5;      
grbc1.weighty = 100;
grbc1.weightx = 100;  
grbc1.gridwidth =1;
grbc1.gridheight=1;  
grbc1.gridx = 1;      
grbc1.gridy = 7;      
grid.setConstraints(button[11], grbc1);
pan1.add(button[11]);
grbc1.ipady = 0;      
grbc1.ipadx = 0;      
grbc1.weighty = 100;
grbc1.weightx = 100;  
grbc1.gridwidth =1;    
grbc1.gridheight=1;  
grbc1.gridx = 0;      
grbc1.gridy = 8;      
grid.setConstraints(label4, grbc1);
pan1.add(label4);
grbc1.ipady = 5;      
grbc1.ipadx = 5;      


getContentPane().add(pan1);
}
public int countClicks()
{

return(++click_count);
}

public boolean checkStatus()
{
int i;
if 
 (button[0].getLabel() == "1" && 
button[1].getLabel() == "2"&&
button[2].getLabel() == "3" && 
button[3].getLabel() == "4"&&
button[4].getLabel() == "5" && 
button[5].getLabel() == "6"&&
button[6].getLabel() == "7" && 
button[7].getLabel() == "8"&&
button[8].getLabel() == " ")
{
return(true);
}
else
return(false);         
}







 Snapshot Of Game

First Page Appear

THIS GAME WHERE A USER CAN PLAY WITH NUMBERS ARRANGED IN SOME RANDOM ORDER TO ARRANGE IT IN A PRIORITY ORDER (ASCENDING ORDER). GAME WHERE A USER CAN PLAY WITH NUMBERS ARRANGED IN SOME RANDOM ORDER TO ARRANGE IT IN A PRIORITY ORDER (ASCENDING ORDER).

AFTER ARRANGE THE NUMBER:-


       Final after finished the game :-


                                                         Thanks For Your Timehttp://basicpuzzle.blogspot.in/

Comments

Popular posts from this blog

Dr. Dinesh Arora - Yashoda Hospital Ghaziabad

BEST IVF CENTRE DELHI : Seeds Of Innocence