《游戏学习》Java版仿windows扫雷小游戏源码
Posted 洛阳泰山
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了《游戏学习》Java版仿windows扫雷小游戏源码相关的知识,希望对你有一定的参考价值。
项目代码目录结构
启动类 StartFrame 代码展示
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.UIManager;
import com.sf.minesweeper.menu.MineMenu;
import com.sf.minesweeper.panel.MineField;
import com.sf.minesweeper.panel.MineState;
import com.sf.minesweeper.timer.Timers;
import com.sf.minesweeper.tools.Tools;
public class StartFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = -1585043387266273492L;
/**
* @param args
*/
private MineState mineState; // 记雷数
private MineField mineField; // 布置labble和雷数
private MineMenu mineMenu;
private Timer timer;
private Timers timers;
/**
* 游戏是否开始
*/
private boolean isStart;
JLabel jLabel_start = new JLabel(); // 开始图片
public StartFrame() {
//改变系统默认字体
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
this.setTitle("扫雷");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
setIconImage(Tools.iicon); // 利用tools来做的作法
this.setResizable(false); // 这样让窗口不会可放大
// ..................状态栏.....................
mineState = new MineState(this);
this.add(mineState, BorderLayout.NORTH);
// ...................雷区......................
mineField = new MineField(this);
this.add(mineField, BorderLayout.CENTER);
jLabel_start.setIcon(Tools.start);
this.add(jLabel_start, BorderLayout.CENTER);
// ....................菜单栏................
mineMenu = new MineMenu(this);
this.setJMenuBar(mineMenu);
// .....................时间................
Tools.time = 0;
timers = new Timers(mineState);
timer = new Timer(1000, timers);
pack();
this.setVisible(true);
}
// 重新布局
public void restart() {
this.remove(mineState);
this.remove(mineField);
this.remove(jLabel_start);
// ..................状态栏.....................
mineState = new MineState(this);
this.add(mineState, BorderLayout.NORTH);
// ...................雷区......................
mineField = new MineField(this);
this.add(mineField, BorderLayout.CENTER);
// .....................时间................
Tools.time = 0;
Timers timers = new Timers(mineState);
timer = new Timer(1000, timers);
pack();
validate();//刷新窗体
}
public MineState getMineState() {
return mineState;
}
public MineField getMineField() {
return mineField;
}
public MineMenu getMineMenu() {
return mineMenu;
}
public Timer getTimer() {
return timer;
}
public Timers getTimers() {
return timers;
}
public boolean isStart() {
return isStart;
}
public void setStart(boolean isStart) {
this.isStart = isStart;
}
public static void main(String[] args) {
new StartFrame();
}
}
游戏截图
完整源码下载地址
以上是关于《游戏学习》Java版仿windows扫雷小游戏源码的主要内容,如果未能解决你的问题,请参考以下文章