Minggu, 25 Desember 2011

Java GUI Programming Tips: Create your own WORD SEARCH PUZZLE GAME!!!

A really good puzzle, everybody knows it, now you can use this piece of puzzle coding and add it into your java game! Try it ! It is really worth it!

This coding is 100 percent made by me! :D
Here is only one class available named "mains" class...
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

import sun.audio.*;
public class mains extends JFrame{

static boolean unclickable[]=new boolean[300];
static Font font=new Font("Arial",Font.ITALIC,15);
static Font font2=new Font("Arial",Font.PLAIN,20);
static JPanel wordpanel,solutionpanel;
static JLabel solutionlabel[]=new JLabel[40];
static JButton button[]=new JButton[300];
static String solution[]={"a","DOG","MOUSE","PIG","BOAR","ROOSTER","MONKEY","RATS","GIRRAFE","ELEPHANT"};
static String trysolution="",trysolutiondummy;
static boolean hasfirstclick=false;
static int getclicked,tempfirstclick;
static int b,c,d;
static String strings=
"aWZRIBBIMBWFUPUGPZZLKUDYOKHZHBDSJADFNLSAUOYSMPPOYRQMJZR" +
"LSIQVZXYMHDHNUOAOEXLETJXKKTQIECNIZGOVNWQJDZNSFKBCICSAICQYDTC" +
"EANRPOZOHLEABENRZRAZUUTVKWIQRZOZLRHSKONHEVTHQOBDFIEAOGQYLGRFSCHEQGMDHIBNERATSCGOUQOYGCSOXMEDFIGHDGFFELTPNRFNPGH";
int a;
public mains(){
super("Words Search by Yapriady");
Container content=getContentPane();
InputStream stream=null;


char chars[]=strings.toCharArray();
wordpanel=new JPanel();solutionpanel=new JPanel();solutionpanel.setLayout(new GridLayout(16,1));
wordpanel.setLayout(new GridLayout(15,15));
handler handlerob=new handler();
for(a=1;a<=225;a++){ button[a]=new JButton(); button[a].setFont(font2); unclickable[a]=false; wordpanel.add(button[a]); button[a].setBackground(Color.RED); button[a].setForeground(Color.WHITE); button[a].setText(Character.toString(chars[a])); button[a].setActionCommand(Integer.toString(a)); button[a].addActionListener(handlerob); } for(a=1;a<=8;a++){ solutionlabel[a]=new JLabel(); solutionlabel[a].setText(solution[a]); solutionpanel.add(solutionlabel[a]); } content.add("Center",wordpanel); content.add("East",solutionpanel); } public static class handler implements ActionListener{ public synchronized void actionPerformed(ActionEvent e) { getclicked=Integer.parseInt(e.getActionCommand()); while(!unclickable[getclicked]){ if(!hasfirstclick){ button[getclicked].setBackground(Color.BLACK); button[getclicked].setForeground(Color.WHITE); hasfirstclick=true;tempfirstclick=getclicked;break; } if(hasfirstclick){ trysolution=""; if(Math.abs((getclicked-tempfirstclick))%16==0){ if(getclicked>tempfirstclick){
for(b=tempfirstclick;b<=getclicked;b+=16){ button[b].setBackground(Color.BLACK); button[b].setForeground(Color.WHITE); trysolution=trysolution+button[b].getText(); } for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=16){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=16){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } if(getclicked=getclicked;b-=16){
button[b].setBackground(Color.BLACK);
button[b].setForeground(Color.WHITE);
trysolution=trysolution+button[b].getText();

}
for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=16){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=16){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } hasfirstclick=false; break; } else if(Math.abs((getclicked-tempfirstclick))%14==0){ if(getclicked>tempfirstclick){
for(b=tempfirstclick;b<=getclicked;b+=14){ button[b].setBackground(Color.BLACK); button[b].setForeground(Color.WHITE); trysolution=trysolution+button[b].getText(); } for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=14){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=14){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } else if(getclicked=getclicked;b-=14){
button[b].setBackground(Color.BLACK);
button[b].setForeground(Color.WHITE);
trysolution=trysolution+button[b].getText();
}
for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=14){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=14){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } hasfirstclick=false; break; } else if(Math.abs((getclicked-tempfirstclick))%15==0){ if(getclicked>tempfirstclick){
for(b=tempfirstclick;b<=getclicked;b+=15){ button[b].setBackground(Color.BLACK); button[b].setForeground(Color.WHITE); trysolution=trysolution+button[b].getText(); } for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=15){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d+=15){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } if(getclicked=getclicked;b-=15){
button[b].setBackground(Color.BLACK);
button[b].setForeground(Color.WHITE);
trysolution=trysolution+button[b].getText();
}
for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=15){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d+=15){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } hasfirstclick=false; break; } else if(Math.abs((getclicked-tempfirstclick))<14){ if(getclicked>tempfirstclick){
for(b=tempfirstclick;b<=getclicked;b++){ button[b].setBackground(Color.BLACK); button[b].setForeground(Color.WHITE); trysolution=trysolution+button[b].getText(); } for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d++){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=tempfirstclick;d<=getclicked;d++){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } if(getclicked=getclicked;b--){
button[b].setBackground(Color.BLACK);
button[b].setForeground(Color.WHITE);
trysolution=trysolution+button[b].getText();
}
for(c=1;c<=8;c++){ if(trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d++){ unclickable[d]=true; button[d].setBackground(Color.BLACK); button[d].setForeground(Color.WHITE); } solutionlabel[c].setFont(font); break; } else if(!trysolution.equals(solution[c])){ for(d=getclicked;d<=tempfirstclick;d++){ if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} } } } } hasfirstclick=false; break; } for(d=1;d<=225;d++){ Boolean.toString(unclickable[d]); if(!unclickable[d]){ button[d].setBackground(Color.RED); button[d].setForeground(Color.WHITE); } else{} }hasfirstclick=false; break; }//endifhasfirstclick } } } public static void main(String []args){ mains ob=new mains(); ob.setResizable(true); ob.setSize(900,700); ob.setVisible(true); ob.setLocationRelativeTo(null); ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

Tidak ada komentar:

Posting Komentar