该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
} else {
k = 2;
}
}
}
if (x0 < i) {
for (j = x0 + 1; j <= i; j++) {
if (grid[j][y0] != 0) {
k = 0;
break;
} else {
k = 2;
}
}
}
} public Boolean remove(Boolean typeFlag) {
Boolean successFlag=false;
if(typeFlag){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation = false;
k = 0;
grid[x0][y0] = 0;
grid[x][y] = 0;
}
else
{
firstButton.setBackground(Color.red);
secondButton.setBackground(Color.red);
successFlag=true;
}
return successFlag;
} public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(newlyButton)) {
String level = llk.globeGameLevel;
changeGameLevel(level);
}
if (e.getSource().equals(exitButton))
System.exit(0);
if (e.getSource().equals(resetButton)) {
reLoadFlag = true;
reload();
} if (e.getSource().equals(changeButton)) {
if ("img2/".equals(cardPackage)) {
cardPackage = "img/";// 图片的目录
cardType = ".jpg";// 图片的格式
} else {
cardPackage = "img2/";// 图片的目录
cardType = ".gif";// 图片的格式
} reLoadFlag = true;
reload();
}
if (e.getSource().equals(helpButton)) {
Boolean successFlag = false;
for (int i = 0; i < globeCols; i++) {
for (int j = 0; j < globeRows; j++) {
if (grid[i + 1][j + 1] != 0 && diamondsButton[i][j].isVisible() ) {
e.setSource(diamondsButton[i][j]);
for (int cols = 0; cols < globeCols; cols++) {
for (int rows = 0; rows < globeRows; rows++) {
if (diamondsButton[cols][rows].isVisible()&&e.getSource() == diamondsButton[cols][rows]&& grid[cols + 1][rows + 1] != 0) {
successFlag = estimateEven(cols + 1,
rows + 1,
diamondsButton[cols][rows], false);
if (successFlag) {
break;
}
}
}
if (successFlag) {
break;
}
}
}
if (successFlag) {
break;
}
} if (successFlag) {
break;
}
}
} if (e.getSource().equals(resetButton)) {
reLoadFlag = true; reload();
}
// 判断游戏的级别
if (e.getSource().equals(easyButton)) {
changeGameLevel("easy");
}
if (e.getSource().equals(midButton)) {
changeGameLevel("mid");
}
if (e.getSource().equals(hardButton)) {
changeGameLevel("hard");
}
for (int cols = 0; cols < globeCols; cols++) {
for (int rows = 0; rows < globeRows; rows++) {
if (e.getSource() == diamondsButton[cols][rows])
estimateEven(cols + 1, rows + 1, diamondsButton[cols][rows],true);
}
}
}
/**
* 初始化游戏级别
* @param cols 列数
* @param rows 行数
* @param pictNum 图片数
* @param maxGameTime 最大用时
*/
private void initGameLevel(int cols,int rows, int pictNum,int maxGameTime)
{
globeCols = cols;
globeRows = rows;
diamondsButton = new JButton[globeCols][globeRows];
grid = new int[globeCols + 2][globeRows + 2];
pictCount = pictNum;
maxTime = maxGameTime;
fractionLable = new JLabel("0");
randomBuild();
}
/**
* 改变游戏级别
*/
private void changeGameLevel(String gameLevel)
{
st.stopthread();
changeButton.setEnabled(true);
resetButton.setEnabled(true);
helpButton.setEnabled(true);
llk = new lianliankan();
mainFrame.setVisible(false);
pressInformation = false; // 这里一定要将按钮点击信息归为初始
// 默认游戏的级别为简单
llk.init(gameLevel);
st = new MainClass(llk);
st.start();
}
public static void main(String[] args) { llk.init("easy"); st.start();
}
}