拼图游戏java代码_java设计:拼图游戏 完整源码

//July/设计。//我对有的老师,很无语。/06.04/。//Puzzle.java--------------------------------------------------------------------------import java.awt.image.BufferedImage;importjavax.swing.JButton;import javax.swing....
摘要由CSDN通过智能技术生成

//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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值