Java Puzzle Game Programming
In this Example, we can make a Puzzle Game using Java Programming, I've have provided this code for any visitor or member or follower's to my blog, this code is better understand you to how java is work. I have spend a 3 month to making this Game Project. So, anyone like or use this code so click on the every advertisement, available on this page. Because this is motivate me for making some Game or a very useful stuff.
Now, I'll show the PUZZLE Game Example Code :
"ballu.java"
import java.awt.*;
import java.awt.event.*;
class ballu extends Frame implements ActionListener,Runnable
{
Dialog d;
Button b[] = new Button[15];
Button bb,start,exit;
Label l1,l2,l3,l4;
Thread t;
int a, c;
String one[] = {"5","7","10","4","6","1","12","15","2","9","3","8","11","14","13"};
int y = 10, y1 = 300;
String check = "0";
int k1,k2;
int aa,ba = 0;
ballu()
{
setLayout(null);
setSize(600,500);
setTitle("Balwant Singh Chandel");
setBackground(Color.red);
t = new Thread(this);
this.but();
start = new Button("Agian Start");
start.setBounds(200,360,70,35);
start.addActionListener(this);
exit = new Button("Exit");
exit.setBounds(300,360,70,35);
exit.addActionListener(this);
add(start);
add(exit);
l1 = new Label("MINUTE");
l1.setBounds(200,50,70,30);
l2 = new Label("SECOND");
l2.setBounds(300,50,70,30);
l3 = new Label(""+ba);
l3.setBounds(200,90,70,30);
l4 = new Label();
l4.setBounds(300,90,70,30);
add(l1);
add(l2);
add(l4);
show();
}
public static void main(String args[])
{
ballu pp = new ballu();
}
public void run()
{
for(;;)
{
try
{
if(Thread.currentThread()==t)
{
for(aa=0; aa<60; aa++)
{
l4.setText("" + aa);
try
{
t.sleep(1000);
}
catch(Exception ex){}
if(aa==59)
{
aa=0;
ba=ba+1;
l3.setText(""+ba);
if(ba == 59)
{
ba = 0;
}
}
}
}
}
catch(Exception s){}
}
}
public void actionPerformed(ActionEvent ae)
{
add(l3);
try
{
t.start();
}
catch(Exception e){}
bb=(Button)ae.getSource();
for(int r = 0; r<15; r++)
{
if(ae.getSource()==b[r])
{
this.call();
}
}
if(ae.getSource()==exit)
{
System.exit(0);
}
if(ae.getSource()==start)
{
d.dispose();
ba = 0;
aa = 0;
this.but();
}
}
public void call()
{
k1 = bb.getX();
k2 = bb.getY();
if((k1==(a-40))&&(k2==c)||(k1==a)&&(k2==(c-40))||(k1==(a+40))&&(k2==c)||(k1==a)&&(k2==(c+40)))
{
bb.setBounds(a,c,40,40);
a = k1;
c = k2;
}
}
public void but()
{
d = new Dialog(this,"Love");
d.setLayout(null);
d.setBounds(200,150,170,190);
a = 5;
c = 30;
for(int k = 0; k<15; k++)
{
b[k] = new Button(one[k]);
b[k].addActionListener(this);
b[k].setBounds(a,c,40,40);
d.add(b[k]);
c = c + 40;
if((k==3)||(k==7)||(k==11))
{
a = a+40;
c = 30;
}
}
d.show();
}
}
compile : javac ballu.java
Run : java ballu
If this information is important to you , and you want to , I will continue writing some more details of Android Programming Language, so click on the advertising, available on this page. This is motivate me for writing some more useful stuff. Thank's
Comments
Post a Comment