Java实现的拼图游戏.docVIP

  • 5
  • 0
  • 约2.99千字
  • 约 6页
  • 2023-11-10 发布于浙江
  • 举报
Java实现的拼图游戏 《Java实现的拼图游戏》实验指导书 一 实验目的 通过实际编程了解基于Swing的图形用户界面程序设计、简单游戏的实现原理。 二 实验原理 本实验完成的是一个基于Swing的拼图游戏,用户可更换图片,设置难度,记录步数,显示原图效果等。 三 实验环境 运行Windows的PC机,具有JDK1.4以上Java编译环境和Eclipse3.0以上Java编辑环境。 四 实验内容和步骤 1、系统需求分析,写出功能流程图 2、项目分析:确定对象并确定对象的属性和操作,为对象建模,画出UML类图 3、类的设计与实现 4、实现拼图游戏功能 5、相关提示 (1)拼图图片 制作拼图游戏之前要先把一张图片等分成若干份。可以使用Photoshop的“切片”工具对图片进行分割处理,或编写一个小的程序进行图片分割处理。代码如下: public class ImgPart extends JLabel { private static final long serialVersionUID = -9015680186663927687L; public static ImageIcon icon=Box.icon; int l; public static boolean hard=true; public ImgPart(String i) { super(i); l=Integer.parseInt(i); } protected void paintComponent(Graphics g) { super.paintComponent(g); Image img = icon.getImage(); switch(l) { case 0:g.drawImage(img, 0, 0,100,100,0,0,icon.getIconWidth()/3,icon.getIconHeight()/3,getParent());break; case 1:g.drawImage(img, 0, 0,100,100,icon.getIconWidth()/3,0,2*icon.getIconWidth()/3,icon.getIconHeight()/3,getParent());break; case 2:g.drawImage(img, 0, 0,100,100,2*icon.getIconWidth()/3,0,icon.getIconWidth(),icon.getIconHeight()/3,getParent());break; case 3:g.drawImage(img, 0, 0,100,100,0,icon.getIconHeight()/3,icon.getIconWidth()/3,2*icon.getIconHeight()/3,getParent());break; case 4:g.drawImage(img, 0, 0,100,100,icon.getIconWidth()/3,icon.getIconHeight()/3,2*icon.getIconWidth()/3,2*icon.getIconHeight()/3,getParent());break; case 5:g.drawImage(img, 0, 0,100,100,2*icon.getIconWidth()/3,icon.getIconHeight()/3,icon.getIconWidth(),2*icon.getIconHeight()/3,getParent());break; case 6:g.drawImage(img, 0, 0,100,100,0,2*icon.getIconHeight()/3,icon.getIconWidth()/3,icon.getIconHeight(),getParent());break; case 7:g.drawImage(img, 0, 0,100,100,icon.getIconWidth()/3,2*icon.getIconHeight()/3,2*icon.getIconWidth()/3,icon.getIconHeight(),getParent());break; case 8:g.drawImage(img, 0, 0,100,100,2*icon.getIconWidth()/3,2*icon.getIconHeight()/3,icon.getIconWidth(),icon.getIconHeight(),getParent());break; case 9:g.drawIm

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档