📄 jigsawframe.java
字号:
package com.sato.accp.game.jigsaw;
import java.awt.BorderLayout;
import javax.swing.Icon;
public class JigsawFrame extends GameFrame {
BorderLayout borderLayout1 = new BorderLayout();
public JigsawFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
this.setTitle("拼图游戏"); //设置窗体的标题
this.addPanelJigsaw(); //增加panelJigsaw区域
this.addPanelModel(); //增加panelModel区域
this.addListener();
}
public void moveImage(int sourceX, int sourceY, int targetX, int targetY) {
Icon temp = null;
temp = buttons[sourceX][sourceY].getIcon();
buttons[sourceX][sourceY].setIcon(buttons[targetX][targetY].getIcon());
buttons[targetX][targetY].setIcon(temp);
flags[sourceX][sourceY] = true;
flags[targetX][targetY] = false;
if (gameOver()) {
Sound.playSuccess();
return;
}
Sound.playMove();
}
public void operator(int sourceX, int sourceY) {
int targetX = 0;
int targetY = 0;
if (sourceX + 1 <= 5) {
if (flags[sourceX + 1][sourceY]) {
targetX = sourceX + 1;
targetY = sourceY;
moveImage(sourceX, sourceY, targetX, targetY);
return;
}
}
super.operator(sourceX, sourceY);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -