换了个老师,这个老师让人有点小无语
直接给全部代码给你,最基本的实现思路都不说
我只好一个一个函数去找度娘了,之后写了些注释。
相比之前,现在加的功能有:游戏开始时有登录框,要求输入用户名和密码;有进度条,并在消除的同时加时间;重置按钮等
把之前的GameData.java 文件中的各功能分成模块,再进行调用
/**
* 显示
* @author miemie
*
*/
public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private static final int height = 400;
private static final int width = 400;
JButton button1 = null;
JButton button2 = null;
GameFile gameFile= new GameFile();
final GameData gameData = new GameData();
JButton[] buttons = new JButton[GameData.rows * GameData.cols];
//分数
JLabel lblScroe = new JLabel();
int score=gameFile.readScore();
//时间
final int timeLimit = 20;
int timeLeft = timeLimit;
public MainFrame() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//this.resize(width + 17, height + 38);//过时
this.setBounds(1, 1, width + 17, height + 38);
this.setLocation((screenSize.width - width) / 2,
(screenSize.height - height) / 2);
this.setTitle("连连看");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// this.setLayout(null);
initButtons();//
showImage();
initPane();
initTimePane();
}
以下为同个页面中的其他模块
/**
* 面板,显示在窗口上方
*/
private void initPane() {
JPanel scorePane = new JPanel(new FlowLayout());
scorePane.add(new JLabel("玩家:"+UserEmpty.username));
scorePane.add(new JLabel(" "));
scorePane.add(new JLabel("得分:"));
lblScroe.setText("" + score);
JButton btnResort = new JButton("重排");
btnResort.addActionListener(new ActionListener() {
//因为没有实现ActionListener接口,重写方法
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成的方法存根
gameData.shuffle(); //打乱数据
showImage(); //再次显示所有图片(重置data中的数字)
timeLeft=timeLeft-10;
}
});
scorePane.add(lblScroe);
scor