• 大小: 39KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: Java
  • 标签: java  

资源简介

java拼图游戏可自定义图片及块数

资源截图

代码片段和文件信息

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.length;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 < buttons.length;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 < buttons.length;i++) {
            try {
                buttons[i].setIcon(null);
                buttons[i].setVisible(false);
                buttons[i] = null;
            }catch(NullPointerException e) {
                JOptionPane.showMessageDialog(null “发生错误!!“);
            }
        }
    }
    
    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\Gameframe.java

............此处省略23个文件信息

评论

共有 条评论