資源簡介
java拼圖游戲可自定義圖片及塊數(shù)

代碼片段和文件信息
package?com.rookie.dao;
import?java.awt.Point;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.ImageIcon;
import?javax.swing.JButton;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?com.rookie.view.GamerView;
public?class?GameDao?implements?ActionListener{
????//按鈕組
????private?JButton?[]buttons?=?new?JButton[9];
????//按鈕初始化組表
????private?final?int?x?=?30;
????private?final?int?y?=?55;
????//按鈕大小
????private?final?int?width?=?73;
????private?final?int?height?=?107;
????private?boolean?beFlag?=?true;
????private?JButton?beButton?=?null;
????private?int?[]randomNum?=?new?int[9];
????private?Point?p[]?=?new?Point[9];
????private?Point?ps;
????public?GameDao()?{
????????super();
????????//?TODO?Auto-generated?constructor?stub
????}
????
????public?void?initButton(JPanel?panel)?{
????????panel.setLayout(null);
????????int?wNum?=?0;
????????int?hNum?=?0;
????????for(int?i=0;i????????????buttons[i]?=?new?JButton();
????????????buttons[i].setVisible(true);
????????????p[i]?=?new?Point(?y+width*wNum++x+height*hNum);
????????????buttons[i].setBounds(p[i].x?p[i].y?width?height);
????????????if((i+1)%3==0)?{
????????????????hNum++;
????????????????wNum=0;
????????????}
????????????buttons[i].addActionListener(this);
????????????panel.add(buttons[i]);????????
????????}????????
????}
????
????public?void?randomLoadPic(int?picId)?{
????????int?rNum?=?0;
????????randomNum?=?new?int[9];
????????for(int?i=0;i?????????????try?{
????????????????rNum?=?(int)(Math.random()*9);
????????????????while(buttons[rNum].getIcon()?!=?null)?{
????????????????????rNum?=?(int)(Math.random()*9)%9;
????????????????}
????????????????randomNum[i]?=?rNum;
????????????????StringBuffer?str?=?new?StringBuffer(
????????????????????????“/LoadImage/image_“?+?picId?+?“/simple/image_“?+?picId?+?“_0“?+?(i+1)?+?“.png“);
????????????????buttons[rNum].setIcon(new?ImageIcon(GamerView.class.getResource(str.toString())));????
????????????????buttons[rNum].setActionCommand(““+rNum);
????????????????randomNum[i]?=?rNum;
????????????}catch(Exception?e)?{
????????????????JOptionPane.showMessageDialog(null?“異常錯誤,即將退出“);
????????????????System.exit(0);
????????????}
????????????
????????}
????}
????
????public?void?resetButton()?{
????????for(int?i=0;i?????????????try?{
????????????????buttons[i].setIcon(null);
????????????????buttons[i].setVisible(false);
????????????????buttons[i]?=?null;
????????????}catch(NullPointerException?e)?{
????????????????JOptionPane.showMessageDialog(null?“發(fā)生錯誤!!“);
????????????}
????????}
????}
????
????public?void?actionPerformed(ActionEvent?e)?{
????????if(beFlag?==?true)?{????????//第一次點擊
?????????????beButton?=?(JButton)e.getSource();
?????????????beFlag?=?false;
????????}else?{
????????????JButton?nowButton?=?(JButton)e.getSource();
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????397??2019-03-20?15:43??puzzle\.classpath
?????文件????????382??2019-03-20?15:40??puzzle\.project
?????文件????????598??2019-03-20?15:43??puzzle\.settings\org.eclipse.jdt.core.prefs
?????文件???????4217??2019-03-20?15:59??puzzle\bin\com\rookie\dao\GameDao.class
?????文件???????1397??2019-03-20?15:58??puzzle\bin\com\rookie\dao\PicloadDao.class
?????文件????????752??2019-03-20?15:59??puzzle\bin\com\rookie\view\GamerView$1.class
?????文件????????758??2019-03-20?15:59??puzzle\bin\com\rookie\view\GamerView$2.class
?????文件????????760??2019-03-20?15:59??puzzle\bin\com\rookie\view\GamerView$3.class
?????文件???????1079??2019-03-20?15:59??puzzle\bin\com\rookie\view\GamerView$MyTase.class
?????文件???????9611??2019-03-20?15:59??puzzle\bin\com\rookie\view\GamerView.class
?????文件????????770??2019-03-20?16:07??puzzle\bin\puzzle_game\Audio.class
?????文件???????1779??2019-03-20?16:03??puzzle\bin\puzzle_game\Cell.class
?????文件???????1070??2019-03-20?16:02??puzzle\bin\puzzle_game\Direction.class
?????文件???????3591??2019-03-20?16:09??puzzle\bin\puzzle_game\PaintGame$ClickMove.class
?????文件???????1247??2019-03-20?16:09??puzzle\bin\puzzle_game\PaintGame$DistructPicture.class
?????文件???????2390??2019-03-20?16:09??puzzle\bin\puzzle_game\PaintGame$ToNextPicture.class
?????文件???????5146??2019-03-20?16:09??puzzle\bin\puzzle_game\PaintGame.class
?????文件????????768??2019-03-20?16:06??puzzle\bin\puzzle_game\Time.class
?????文件???????1058??2019-03-20?16:07??puzzle\bin\puzzle_game\Win$1.class
?????文件???????1246??2019-03-20?16:07??puzzle\bin\puzzle_game\Win$2.class
?????文件???????1166??2019-03-20?16:07??puzzle\bin\puzzle_game\Win$3.class
?????文件???????7565??2019-03-20?16:07??puzzle\bin\puzzle_game\Win.class
?????文件????????863??2019-03-20?16:06??puzzle\bin\puzzle_game\Yard.class
?????文件???????3970??2019-03-20?15:59??puzzle\src\com\rookie\dao\GameDao.java
?????文件????????687??2019-03-20?15:58??puzzle\src\com\rookie\dao\PicloadDao.java
?????文件??????12650??2019-03-20?15:59??puzzle\src\com\rookie\view\GamerView.java
?????文件????????296??2019-03-20?16:07??puzzle\src\puzzle_game\Audio.java
?????文件???????1459??2019-03-20?16:03??puzzle\src\puzzle_game\Cell.java
?????文件?????????91??2019-03-20?16:02??puzzle\src\puzzle_game\Direction.java
?????文件?????????22??2019-03-20?16:02??puzzle\src\puzzle_game\Gamefr
............此處省略23個文件信息
評論
共有 條評論