//July/设计。
//我对有的老师,很无语。/06.04/。
//Puzzle.java
--------------------------------------------------------------------------
import java.awt.image.BufferedImage;
import
javax.swing.JButton; import javax.swing.ImageIcon;
import
javax.swing.JOptionPane; //弹出标准对话框
import javax.swing.JRadioButtonMenuItem; //一个单选按钮菜单项的实现
public class Puzzle extends
CardFrame //卡片布局框架
{
private boolean start;
private int fWidth = this.getWidth();
private int fHeight = this.getHeight();
private GameOver gOver;
private boolean index = true;
public Puzzle()
{
start = false;
ImageIcon icon = new
ImageIcon("icon/OK.png"); //图像图标
this.setSize(200 + fWidth, 200
+ fHeight);
this.setIconImage(icon.getImage());
this.setVisible(true);
}
private void startGame()
{
if (start)
return;
start = true;
updateMenuBegin();
}
public void endGame()
{
updateMenuBegin();
initMenuBackground();
start = false;
JOptionPane.showMessageDialog(null,
"Time:" +
gOver.getTime() + "s\n" +
"Step:" +
gOver.getStep()
);
Grades g = new
Grades(this);
g.set((int)gOver.getTime(),
gOver.getStep());
}
protected void FrameLostFocus()
{
if (start
&& index)
{
nextCard();
if (gOver !=
null) gOver.pause();
index =
false;
}
}
protected void FrameGetFocus()
{
nextCard();
if (gOver != null)
gOver.pause();
index = true;
}
public void menuNewClick()
{
Split sp = Split.get();
BufferedImage [][] image;
//BufferedImage
子类描述具有可访问图像数据缓冲区的 Image
if (!sp.set(getFilename()) ||
(image = sp.divid(getType())) == null)
{
JOptionPane.showMessageDialog(null,
"File "+getFilename()+" not exists!\nPlease select again~");
return;
}
startGame();
this.setSize(fWidth,
fHeight);
this.setVisible(true);
int len =
Split.level[getType()];
int row = image.length;
int cal = image[0].length;
gOver = new
GameOver(this);
JButton [][] button = new
JButton[row][cal];
Matrix matrix = new
Matrix(button, panel[0], len, gOver);
matrix.init(image);
this.setSize(cal * len +
fWidth, row * len + fHeight);
this.setVisible(true);
}
public void menuGradesClick()
{
Grades g = new
Grades(this);
g.show();
}
public void menuShowClick()
{
new
ShowImage(getFilename());
}
public void menuExitClick()
{
System.exit(0);
}
public void menuHelpClick()
{
String help0 = "Move the small
pictures to make it become the original image.\n\n";
String help1 = "(1)touch the
small picture around the blank block to make it move toward to the
blank block.";
JOptionPane.showMessageDialog(null,
help0 + help1);
}
public void menuAboutClick()
{
String version = "Version:
0.0.2 beta 1\n";
String author = "Author: Write
by ZJGSU redraiment\n";
String email = "E-mail:
redraiment@126.com";
JOptionPane.showMessageDialog(null,
version + author + email);
}
public static void main(String [] argv)
{
Puzzle app = new
Puzzle();
}
}
//Arg.java
public interface Arg
{
public static final String path =
"background";
public static final String rc = "Game.rc";
}
//ButtonClick.java
--------------------------------------------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class ButtonClick implements
ActionListener //实现接口..事件监听
{
private JButton [][]
button; //按钮
private point pint;
private int row;
private int cal;
private int [][] matrix;
private GameOver gOver;
private boolean end;
public ButtonClick(JButton [][] b, point p,
int [][] m, int r, int c, GameOver g)
{
button = b;
pint = p;
matrix =
m; //矩阵
row = r;
cal = c;
gOver = g;
end = false;
}
public void actionPerformed(ActionEvent
e) //发生操作事件时,调用此方法
{
//执行
if (end || !pint.neighbor(row,
cal))
return;
int r = pint.getRow();
int c = pint.getCal();
button[r][c].setIcon(button[row][cal].getIcon());
button[row][cal].setIcon(nu