使用javaGUI做一个MC版俄罗斯方块(二)

使用开源代码做开源游戏,真香!

喜欢玩俄罗斯方块和MC的玩家都沉默了

源码给大家展示一下

资源免费下载

目录

  • src
    • bean
      • Cell.java
      • GLocale.java
      • ImageMap.java
      • ImagesMap.java
      • JSONConfig.java
      • JSONsConfig.java
      • LastSave.java
      • mLocale.java
      • Music.java
      • MusicJButton.java
      • State.java
      • TeXiaoMusic.java
      • Version.java
    • config
      • Config.java
      • imageConfig.java
      • MusicConfig.java
    • Main
      • ConfigJPanel.java
      • Main.java
      • ModsJPanel.java
      • NewGameJPanel.java
    • service
      • AllImage.java
      • GameJPanelService.java
      • JSONService.java
      • LastSaveService.java
      • SaveService.java
    • xingzhuang
      • I.java
      • J.java
      • L.java
      • O.java
      • S.java
      • T.java
      • Z.java
    • log
      • WinLog.java
    • MyThread
      • BackFontTH.java
      • BackgroundMusic.java
      • BooTH.java
      • DestroyLineTH.java
      • DownOverTH.java
      • HeChengTH.java
      • QianZou.java
      • StartGameTH.java
      • StopGameTH.java
      • ZiHuiTh.java
      • ZIPThread.java
        界面图
        效果图

ModsJPanel 加载模组界面

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JCheckBox;

import log.WinLog;

import static cn.zhshipu.config.Config.*;
import static cn.zhshipu.config.imageConfig.mods;

public class ModsJPanel {
	
	private static ModsJPanel instance = null;
	private List<Map<String, Boolean>> list_map = null;
	private Map<Integer, String> map_name = null;
	private WinLog log = new WinLog("ModsJPanel");
	
	public static ModsJPanel getInstance() {
		if(instance == null) {
			instance = new ModsJPanel();
		}
		return instance;
	}
	
	ModsJPanel(){
		
		list_map = new ArrayList<Map<String,Boolean>>();
		map_name = new HashMap<Integer, String>();
		int m=0;
		for(String s : mods) {
			Map<String,Boolean> map_config = new HashMap<String, Boolean>();
			map_config.put(s, false);
			map_name.put(m, s);
			list_map.add(map_config);
			m++;
		}
		
		log.info("mods = "+list_map);
	}
	
	public Map<Integer, String> getMapName(){
		return map_name;
	}
	
	public void setMapName(Map<Integer, String> map_name) {
		this.map_name = map_name;
	}
	
	public List<Map<String, Boolean>> getListMap(){
		return list_map;
	}
	
	private void setListMap(List<Map<String, Boolean>> list_map) {
		this.list_map = list_map;
	}

	public void showMods(Frame main) {
		main.setEnabled(false);
		Frame f = new Frame("模组");
		f.setLayout(null);
		f.setBounds(0, 0, 600,500);
		f.setLocationRelativeTo(null);
		f.setResizable(false);
		f.setIconImage(logo.getImage());
		f.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				main.setEnabled(true);
				f.dispose();
			}
		});
		
		for(int i=0;i<list_map.size();i++) {
			Map<String, Boolean> map = list_map.get(i);
			
			String name = map.keySet()+"";
			JCheckBox jrb = new JCheckBox(name.substring(name.indexOf("[")+1, name.indexOf("]")));
			jrb.setFont(f25);
			jrb.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					log.info("数字 = " + jrb.getText().substring(0, 1));
					map.put(jrb.getText(), jrb.isSelected());
					log.info("map = "+map);
				}
			});
			if(i < 8) {
				jrb.setBounds(30, 30+i*50, 150, 50);
			}else if(i >= 8 && i<16) {
				jrb.setBounds(210, 30+(i-8)*50, 150, 50);
			}else {
				jrb.setBounds(390, 30+(i-16)*50, 150, 50);
			}
			f.add(jrb);
		}
		
		JButton jb_ok = new JButton("确定");
		jb_ok.setFont(f25);
		jb_ok.setBounds(f.getWidth()/2-50, 430, 100, 50);
		f.add(jb_ok);
		
		jb_ok.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				setListMap(list_map);
				main.setEnabled(true);
				f.dispose();
			}
		});
		
		f.setVisible(true);
	}
}

imageConfig 图片配置文件

import java.awt.Image;

import javax.swing.ImageIcon;

public class imageConfig {
	//必有
	public static Image jiyan = new ImageIcon("images\\jiyan.png").getImage();
	//音乐
	public static ImageIcon sys = new ImageIcon("mp3\\images\\sys.png");
	public static ImageIcon xys = new ImageIcon("mp3\\images\\xys.png");
	public static ImageIcon zt = new ImageIcon("mp3\\images\\zt.png");
	public static ImageIcon bf = new ImageIcon("mp3\\images\\bf.png");
	//原装
	public static String yuan = "images\\yuan";
	public static String yuan_g = "config\\yuan.json";
	//mods
	public static String[] mods = {"等价交换",
			"无尽贪婪",
			"幸运方块",
			"更多箱子",
			"拆解台",
			"暮色森林",
			"星系",
			"工业革命"};
	public static String[] paths = {"images\\dengjiajiaohuan",
			"images\\wujintanlan",
			"images\\xingyunfangkuai",
			"images\\gengduoxiangzi",
			"images\\chaijietai",
			"images\\musesenlin",
			"images\\xingxi",
			"images\\gongyegeming"};
	public static String[] configPaths = {"config\\dengjiajiaohuan.json",
			"config\\wujintanlan.json",
			"config\\xingyunfangkuai.json",
			"config\\gengduoxiangzi.json",
			"config\\chaijietai.json",
			"config\\musesenlin.json",
			"config\\xingxi.json",
			"config\\gongyegeming.json"};
}

ConfigJPanel 设置界面

import static cn.zhshipu.config.Config.f25;
import static cn.zhshipu.config.Config.logo;
import static cn.zhshipu.config.MusicConfig.peizhi;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JCheckBox;

import log.WinLog;

public class ConfigJPanel {
	private static ConfigJPanel instance = null;
	private List<Map<String,Boolean>> list_config;
	private WinLog log = new WinLog("ConfigJPanel");
	public static ConfigJPanel getInstance() {
		if(instance == null) {
			instance = new ConfigJPanel();
		}
		return instance;
	}
	private ConfigJPanel() {
		list_config = new ArrayList<Map<String,Boolean>>();
		for(String s : peizhi) {
			Map<String,Boolean> map_config = new HashMap<String, Boolean>();
			map_config.put(s, true);
			list_config.add(map_config);
		}
	}
	public void showConfigJPanel(Frame main) {
		
		main.setEnabled(false);
		Frame f = new Frame("设置");
		f.setLayout(null);
		f.setBounds(0, 0, 600,500);
		f.setLocationRelativeTo(null);
		f.setResizable(false);
		f.setIconImage(logo.getImage());
		f.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				main.setEnabled(true);
				f.dispose();
			}
		});
		
		for(int i=0;i<list_config.size();i++) {
			Map<String, Boolean> map = list_config.get(i);
			
			String name = map.keySet()+"";
			JCheckBox jrb = new JCheckBox(name.substring(name.indexOf("[")+1, name.indexOf("]")));
			
			jrb.setSelected(true);
			
			jrb.setFont(f25);
			jrb.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
//					System.out.println("数字 = " + jrb.getText().substring(0, 1));
					map.put(jrb.getText(), jrb.isSelected());
//					System.out.println("map = "+map);
				}
			});
			if(i < 8) {
				jrb.setBounds(30, 30+i*50, 150, 50);
			}else if(i >= 8 && i<16) {
				jrb.setBounds(210, 30+(i-8)*50, 150, 50);
			}else {
				jrb.setBounds(390, 30+(i-16)*50, 150, 50);
			}
			f.add(jrb);
		}
		
		JButton jb_ok = new JButton("确定");
		jb_ok.setFont(f25);
		jb_ok.setBounds(f.getWidth()/2-50, 430, 100, 50);
		f.add(jb_ok);
		
		jb_ok.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				log.info("config = "+list_config);
				setListMap(list_config);
				main.setEnabled(true);
				f.dispose();
			}
		});

		f.setVisible(true);
	}
	
	public List<Map<String,Boolean>> getListMap() {
		return list_config;
	}
	
	private void setListMap(List<Map<String,Boolean>> list_config) {
		this.list_config = list_config;
	}
}

AllImage 加载方块

import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;
import com.alibaba.fastjson.JSONArray;
import bean.Cell;
import bean.ImageMap;
import bean.State;
import cn.zhshipu.service.xingzhuang.I;
import cn.zhshipu.service.xingzhuang.J;
import cn.zhshipu.service.xingzhuang.L;
import cn.zhshipu.service.xingzhuang.O;
import cn.zhshipu.service.xingzhuang.S;
import cn.zhshipu.service.xingzhuang.T;
import cn.zhshipu.service.xingzhuang.Z;
import log.WinLog;

public class AllImage {
	private static WinLog log = new WinLog("AllImage");
	
	public Cell[] cells = new Cell[4];
	

    //旋转的状态
    protected State[] states;
    //声明旋转次数
    protected int count = 10000;
    
  //左移方法
    public void moveLeft() {
        for (Cell cell : cells) {
            cell.left();
        }
    }
 
    //右移方法
    public void moveRight() {
        for (Cell cell : cells) {
            cell.right();
        }
    }
 
    //单元格下落
    public void moveDrop() {
        for (Cell cell : cells) {
            cell.down();
        }
    }
    
    //切换图片
    public void HuanImg(ImageIcon img) {
    	for(Cell cell : cells) {
    		cell.setImg(img);
    	}
    }
    
    //存档使用
    public String toString() {
    	String s1 = "[";
    	String s2 = "]";
    	String s = "";
    	for(Cell cell : cells) {
    		s+= "{"+cell.toString()+"},";
    	}
    	log.info("存档 s = "+s);
    	return s1+s.substring(0, s.length()-1)+s2;
    }
    
  //编写随机生成四方格
    public static AllImage randomOne() {
    	int num = (int) (Math.random() * 7);
    	AllImage allImage = null;
    	Random rd = new Random();
		int m = rd.nextInt(ImageMap.getInstance().getImgMap().size())+1;
		ImageIcon img = ImageMap.getInstance().getImgMap().get(m);

		//测试
//		ImageIcon img = ImageMap.getInstance().getImgMap().get(64);
//		int math = (int)(Math.random()*2)==0?1:51;
//		ImageIcon img = ImageMap.getInstance().getImgMap().get(math);
		
//		log.WL("64 = "+ImageMap.getInstance().getImgMap().get(64));
		
		img.setImage(img.getImage().getScaledInstance(35,35,Image.SCALE_DEFAULT));
		
		JSONArray type = JSONService.getInstance().getJSONType(ImageMap.getInstance().getImgMapName().get(img));
		JSONArray tab = JSONService.getInstance().getJSONTab(ImageMap.getInstance().getImgMapName().get(img));
		String name = ImageMap.getInstance().getImgMapName().get(img);

		
    	switch(num) {
    	case 0:
    		allImage = new I(-1,-1,img,type,tab,name,num);
    		break;
    	case 1:
    		allImage = new J(-1,-1,img,type,tab,name,num);
    		break;
    	case 2:
    		allImage = new L(-1,-1,img,type,tab,name,num);
    		break;
    	case 3:
    		allImage = new O(-1,-1,img,type,tab,name,num);
    		break;
    	case 4:
    		allImage = new S(-1,-1,img,type,tab,name,num);
    		break;
    	case 5:
    		allImage = new T(-1,-1,img,type,tab,name,num);
    		break;
    	case 6:
    		allImage = new Z(-1,-1,img,type,tab,name,num);
    		break;
    	}
    	return allImage;
    }
    
    
  //顺时针旋转的方法
    public void rotateRight() {
        if (states.length == 0) {
            return;
        }
 
        //旋转次数+1
        count++;
        State s = states[count % states.length];
        Cell cell = cells[0];
        int row = cell.getRow();
        int col = cell.getCol();
        cells[1].setRow(row + s.row1);
        cells[1].setCol(col + s.col1);
        cells[2].setRow(row + s.row2);
        cells[2].setCol(col + s.col2);
        cells[3].setRow(row + s.row3);
        cells[3].setCol(col + s.col3);
    }
    
  //逆时针旋转的方法
    public void rotateLeft() {
        if (states.length == 0) {
            return;
        }
 
        //旋转次数+1
        count--;
        State s = states[count % states.length];
        Cell cell = cells[0];
        int row = cell.getRow();
        int col = cell.getCol();
        cells[1].setRow(row + s.row1);
        cells[1].setCol(col + s.col1);
        cells[2].setRow(row + s.row2);
        cells[2].setCol(col + s.col2);
        cells[3].setRow(row + s.row3);
        cells[3].setCol(col + s.col3);
    }
    
}

MusicJButton 音乐显示按钮

import javax.swing.ImageIcon;

public class MusicJButton {
	public int x;
	public ImageIcon img;
	public String music_name;
	public MusicJButton(int x, ImageIcon img, String music_name) {
		this.x = x;
		this.img = img;
		this.music_name = music_name;
	}
}

Cell 单独方块类

import javax.swing.ImageIcon;
import com.alibaba.fastjson.JSONArray;
import log.WinLog;

/**
 * 	方块类
 * 	row 行
 * 	col 列
 *  img 对应的图片
 *  type 属性
 * 	tab 合成
 * 
 * */

public class Cell {
	private String name;	//图片名称
	private int row;		//图片行
	private int col;		//图片列
	private ImageIcon img;	//图片
	private JSONArray type; //属性
	private JSONArray tab;	//合成
	private int index;		//形状
	public Cell() {
		
	}
	public Cell(String name,int row,int col,ImageIcon img,JSONArray type,JSONArray tab,int index) {
		this.name = name;
		this.row = row;
		this.col = col;
		this.img = img;
		this.type = type;
		this.tab = tab;
		this.index = index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public int getIndex() {
		return index;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public void setType(JSONArray type) {
		this.type = type;
	}
	public void setTab(JSONArray tab) {
		this.tab = tab;
	}
	public void setRow(int row) {
		this.row = row;
	}
	public void setImg(ImageIcon img) {
		this.img = img;
	}
	public void setCol(int col) {
		this.col = col;
	}
	public JSONArray getType() {
		return type;
	}
	public JSONArray getTab() {
		return tab;
	}
	public int getRow() {
		return row;
	}
	public ImageIcon getImg() {
		return img;
	}
	public int getCol() {
		return col;
	}
	
	WinLog log = new WinLog("Cell");
	
	@Override
	public String toString() {
		String sImg = img+"";
		if(sImg.indexOf("yuan") > 0) {
			sImg = "yuan";
		}
		
//		log.WL("sImg = "+sImg);
		
//		img = imahes\\yuan\\xxx.png
		
		return "\"cell\":{"+"\"name\":\""+name+"\","
				+ "\"row\":\""+row+"\","
				+ "\"col\":\""+col+"\","
						+ "\"img\":\""+sImg+"\","
								+ "\"type\":"+type+","
										+ "\"tab\":"+tab+","
												+ "\"index\":\""+index+"\"}";
	}
	
	//左移动一格
    public void left(){
        col--;
    }
 
    //右移动一格
    public void right(){
        col++;
    }
 
    //下移动一格
    public void down(){
        row++;
    }
    
}

GameJPanelService 游戏主服务

import java.awt.Color;
import java.awt.Frame;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import com.ccqq.getDPI.zhuoMianDPI;
import bean.Cell;
import bean.GLocale;
import bean.Version;
import cn.zhshipu.Main.ConfigJPanel;
import static cn.zhshipu.config.Config.*;


public abstract class GameJPanelService extends Frame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private GLocale gl = new GLocale(zhuoMianDPI.winWidth()/2-W/2, zhuoMianDPI.winHeight()/2-H/2);
	private JLabel jl_logo,jl_name,jl_close;
	private static JLabel jl_version;
	protected static JLabel jl_bgk;
	private JPanel jp_dh;
	private Border lineBorder= BorderFactory.createLineBorder(Color.gray,1);
	
	//需要保存的数据
	protected Cell[][] wall = new Cell[23][15];	//游戏主区域
	protected AllImage currentOne = AllImage.randomOne();		//正在下落的方块
	protected AllImage nextOne = AllImage.randomOne();	//下一个下落方块
	protected Double fenshu = 0.0;	//分数
	private static List<Map<String,Boolean>> mods = null;	//模组
	private static int x,y;
	private String v = Version.getInstance().getVersion();
	
	
	public GameJPanelService(){
		this.setLayout(null);
		this.setBounds(gl.getX(), gl.getY(), W, H);
		this.setUndecorated(true);
//		this.setBackground(new Color(0,0,0,0));		//去掉不然不显示画布
		this.setIconImage(logo.getImage());
		
		//背景图片
		jl_bgk = new JLabel(bgk);
		jl_bgk.setBounds(0,0,this.getWidth(),this.getHeight());
		this.add(jl_bgk);
		
		//标题栏
		jp_dh = new JPanel();
		jp_dh.setLayout(null);
		jp_dh.setBounds(0, 0, jl_bgk.getWidth(), 30);
		jp_dh.setBackground(Color.white);
		jp_dh.setBorder(lineBorder);
		jl_bgk.add(jp_dh);
		
		//logo
		jl_logo = new JLabel(logo);
		logo.setImage(logo.getImage().getScaledInstance(26,26,Image.SCALE_DEFAULT));
		jl_logo.setBounds(4, 2, 26, 26);
		jp_dh.add(jl_logo);
		
		//游戏名称
		jl_name = new JLabel("MC版俄罗斯方块");
		jl_name.setBounds(33, 2, 200, 26);
		jl_name.setFont(f25);
		jp_dh.add(jl_name);
		
		//版本号
		jl_version = new JLabel(v);
		jl_version.setBounds(10, 30, 200, 40);
		jl_version.setFont(f20);
		jl_bgk.add(jl_version);
		
		//关闭
		jl_close = new JLabel("关闭");
		jl_close.setBounds(jp_dh.getWidth()-60, 2, 80, 26);
		jl_close.setFont(f25);
		jl_close.setForeground(Color.black);
		jp_dh.add(jl_close);
		
		jp_dh.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				super.mousePressed(e);
				x=0;
				y=0;
				
				x = e.getX();
				y = e.getY();
			}
			@Override
			public void mouseReleased(MouseEvent e) {
				super.mouseReleased(e);
				int p = e.getX() - x;
				int q = e.getY() - y;
				gl.setX(gl.getX()+p);
				gl.setY(gl.getY()+q);
				GameJPanelService.this.setLocation(gl.getX(), gl.getY());
			}
		});
		
		jl_close.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				SaveService.getInstance().getSave();
				System.exit(0);
			}
			@Override
			public void mouseEntered(MouseEvent e) {
				super.mouseEntered(e);
				jl_close.setForeground(Color.red);
			}
			@Override
			public void mouseExited(MouseEvent e) {
				super.mouseExited(e);
				jl_close.setForeground(Color.black);
			}
		});
		
	}
	
	//异步回调更新是否有新版本
	public static void showVersion(String s) {
		jl_version.setText(s);
		jl_version.setForeground(Color.red);
		jl_bgk.add(jl_version);
	}
	
	public static List<Map<String,Boolean>> getMods(){
		if(mods == null) {
			mods = ConfigJPanel.getInstance().getListMap();
		}
		return mods;
	}
}

ImagesMap 加载模组图片到内存

import java.io.File;
import java.util.Map;
import javax.swing.ImageIcon;
import log.WinLog;
import static cn.zhshipu.config.imageConfig.*;

/**
 * 		加载模组图片
 * */
public class ImagesMap {

	private Map<Integer, ImageIcon> map = null;
	private Map<ImageIcon, String> map_name = null;
	private Map<String, ImageIcon> name_map = null;
	private WinLog log = new WinLog("ImagesMap");
	
	public ImagesMap(int index) {
		//初始化
		map = ImageMap.getInstance().getImgMap();
		map_name = ImageMap.getInstance().getImgMapName();
		name_map = ImageMap.getInstance().getStrToImg();
		int x = map.size()+1;
		
		File f = new File(paths[index]);
		if(f.exists()) {
			File[] list = f.listFiles();
			if(list != null) {
				for(int i=0;i<list.length;i++) {
					String fileName = list[i].getName();
					if(list[i].isFile()) {
						log.info("图片名称 = "+fileName+"  ,  文件路径 = "+list[i].getPath() +"  ,  x = "+x);	
						ImageIcon imgico = new ImageIcon(list[i].getPath());
						map.put(x, imgico);
						map_name.put(imgico, fileName.substring(0, fileName.indexOf(".")));
						name_map.put(fileName.substring(0, fileName.indexOf(".")), imgico);
						x++;
					}
				}
			}
		}
	}
	
	public void updatee() {
		ImageMap.getInstance().updateImgMap(map);
		ImageMap.getInstance().updateImgMapName(map_name);
		ImageMap.getInstance().updateStrToImg(name_map);
		
	}
	
}

JSONsConfig 加载模组方块和合成表到内存

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import log.WinLog;
import static cn.zhshipu.config.imageConfig.*;
/**	
 * 		获取模组方块属性和合成表
 * */
public class JSONsConfig {
	private Map<String, JSONArray> yuan_json_type = null;
	private Map<String, JSONArray> yuan_json_tab = null;
	private WinLog log = new WinLog("JSONsConfig");
	
	public JSONsConfig(int index) {
		//初始化
		yuan_json_type = JSONConfig.getInstance().getJSONType();
		yuan_json_tab = JSONConfig.getInstance().getJSONTab();
		
		File f = new File(configPaths[index]);
		log.info("打开文件 = "+configPaths[index]);
		if(f.exists()) {
			try {
				JSONObject jsonobj = (JSONObject)JSONObject.parse(new String(Files.readAllBytes(Paths.get(f.getPath()))));
				JSONArray arr = jsonobj.getJSONArray("data");
				log.info("arr = "+arr);
				for(int i=0;i<arr.size();i++) {
					JSONObject jsonarr = (JSONObject)JSONObject.parse(new String(arr.getString(i).getBytes()));
					String name = jsonarr.getString("name");
					JSONArray type = jsonarr.getJSONArray("type");
					JSONArray tab = jsonarr.getJSONArray("tab");
					if(type != null) {
						yuan_json_type.put(name, type);
					}else {
						yuan_json_type.put(name, null);
					}
					if(tab != null) {
						yuan_json_tab.put(name, tab);
					}else {
						yuan_json_tab.put(name, null);
					}
				}
			} catch (IOException e) {
				log.error("模组配置文件打开错误");
				log.error(e.getMessage());
			}
		}
	}
	
	public void update() {
		JSONConfig.getInstance().updateTypeJson(yuan_json_type);
		JSONConfig.getInstance().updateTabJson(yuan_json_tab);
	}
}

BackFontTH 动态音乐字体

import javax.swing.JLabel;

import bean.MusicJButton;

public class BackFontTH extends Thread{
		
	private boolean music_flag;
	private MusicJButton mjb;
	private JLabel jl_music_name;
	
	public BackFontTH(boolean music_flag,MusicJButton mjb,JLabel jl_music_name) {
		this.music_flag = music_flag;
		this.mjb = mjb;
		this.jl_music_name = jl_music_name;
	}
	
		@Override
		public void run() {
			while(music_flag) {
					if(mjb.x + mjb.music_name.length()*35 > 0) {
						mjb.x -- ;
					}else {
						mjb.x = 300;
					}
					jl_music_name.setLocation(mjb.x, 0);
				try {
					Thread.sleep(24);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
}

BackgroundMusic 背景音乐

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;

import javax.swing.JLabel;

import bean.Music;
import bean.MusicJButton;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import log.WinLog;

public class BackgroundMusic extends Thread{
		
	private WinLog log = new WinLog("BackgroundMusic");
	private MusicJButton mjb;
	private JLabel jl_music_name;
	private static List<Map<String, ByteArrayOutputStream>> list_music = Music.getInstance().getListByteArray();
	private Player player;
	
	public BackgroundMusic(MusicJButton mjb,JLabel jl_music_name) {
		this.mjb = mjb;
		this.jl_music_name = jl_music_name;
	}
	
		@Override
		public void run() {
			int i = 0;
			while(true) {
				Map<String, ByteArrayOutputStream> out_map = list_music.get(i);
				String s = out_map.keySet().toString();
				mjb.music_name = s.substring(1, s.length()-1);
				
				jl_music_name.setText(mjb.music_name);
				jl_music_name.setBounds(mjb.x, 0, mjb.music_name.length()*45, 40);
				
				try {
					player = new Player(new BufferedInputStream(new ByteArrayInputStream(out_map.get(mjb.music_name).toByteArray())));
					if(null != player)
					player.play();
				} catch (JavaLayerException e1) {
					log.error("背景音乐文件播放失败");
					log.error(e1.getMessage());
				}
				
				System.gc();
				
				i++;
				if(i >= list_music.size()) {
					i=0;
				}
			}
				
		}
}

没用的知识又增加了,哈哈哈哈哈哈哈哈哈哈!!!

有啥推荐的小游戏各位小伙伴推荐一下

使用javaGUI做一个MC版俄罗斯方块(一)
使用javaGUI做一个MC版俄罗斯方块(三)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荒·原

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值