日期:2014-05-20  浏览次数:20737 次

做了个小游戏,有bug,半天也没找到
本帖最后由 huijiaba99 于 2012-11-01 15:37:05 编辑
是个数字记忆游戏,现在的问题出在,第一关过关后,自动跳到第二关,却不能正确显示数字了。
初接触JAVA,找了很久还是没有搞定,希望大神能帮忙检查一下…

因为代码略长,我分成了2层楼。(整个代码是一个文件)

代码如下:
import java.awt.*;
import java.awt.event.*;
import java.util.*; // for Random and ArrayList
import javax.swing.*; // obviously a lot of swing
import javax.swing.event.MouseInputListener;

// 游戏玩法:点击开始游戏后,会出现若干个圈子,每个圈子内显示一个1-N的数字,
// 记住这些数字,因为在若干秒后,数字会消失,你需要做的,就是按从小到大的顺序,
// 依次点击这些圈子,如果顺序正确,恭喜你,过关了~~
class GameConfig extends JDialog implements ActionListener
{
private JLabel lblSetTime = new JLabel("设置时间(单位秒):");
private JLabel lblSetLim = new JLabel("设置数字范围:1 - ");
private JTextField txtTime=new JTextField(Double.toString(GuessWhereAreTheNumbers.remtime));
private JTextField txtLim=new JTextField(Integer.toString(GuessWhereAreTheNumbers.lim));
private JButton btnCon = new JButton("确定");
private JButton btnReset = new JButton("重置");
GameConfig()
{
//super("配置游戏");
JPanel panel = new JPanel(new GridLayout(3, 2)); // grid布局用玉显示各种label
panel.setBackground(Color.WHITE);
panel.add(lblSetTime);
panel.add(txtTime);
panel.add(lblSetLim);
panel.add(txtLim);
panel.add(btnCon);
panel.add(btnReset);
add(panel,BorderLayout.CENTER);
setModal(true);
btnCon.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// 保存设置

GuessWhereAreTheNumbers.remtime=Double.parseDouble(txtTime.getText());
GuessWhereAreTheNumbers.lim=Integer.parseInt(txtLim.getText());
dispose();
}
});
}

@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub

}

}


public class GuessWhereAreTheNumbers extends JFrame implements Runnable,
ActionListener
{
private static final int NB_ROWS = 5, NB_COLS = 7; // 共有几行几列
static double remtime = 1.5; // 记忆时间
static int lim = 9; // 范围9-99
static int score = 0; // 得分,初始为0
static int cirnum = 4;

private CircleLabel[][] label = new CircleLabel[NB_ROWS][NB_COLS]; // 这个标签代表圈(带有数字的或者不带数字的)
private Random random = new Random(); // 随机显示数字和数字的位置
private BottomPanel bottomPanel; // Panel1,用于放多选按钮和开始按钮
private JButton btnStart = new JButton("开始游戏"); // 开始按钮
private JButton btnConf = new JButton("配置游戏");
private JButton btnRank = new JButton("排行榜");
private JButton btnHelp = new JButton("游戏帮助"); // 帮助
private JButton btnExit = new JButton("退出游戏"); // 退出按钮
private JLabel statusLabel = new JLabel("\n"); // 显示成功、失败的标签
// the array of the labels in the game (the ones that hold a number from 0
// to 9)
private CircleLabel[] cl; // 显示数字的标签