动物交换游戏java代码及注释


设计GUI(Graphical User Interface)界面的动物换位游戏,游戏的结果是让左右两组动物交换位置。具体要求如下: 1.程序分为3个级别,用户通过菜单来选择初级、中级和高级。对于初级,在水平排列的7块石头上的左右各有3个类型相同的动物,中间的石头上没有动物;对于中级,在水平排列的 块石头上的左右各有4个类型相同的动物,中间的石头上没有动物;对于高级,在水平排列的11块石头上左右各有5个类型相同的动物,中间的石头上没有动物。 2.用鼠标单击一个动物,如果该动物前方的石头上没有动物,该动物跳跃到该石头上,如果该动物前方的石头上有其他动物,但隔位上的石头没有动物,该动物就越过自己前面的动物跳跃到石头上,其他情形时,该动物不跳跃(跳跃时不能越过2块石头)。 3.左面的动物只能向右方跳跃,右面的动物只能向左方跳跃。 4.用户可以通过界面提供的按钮,让程序自动完成动物换位。 5.可以随时重新开始不同的级别。 6.用户通过菜单选项,可以选择左、右动物的图像。
资源截图
代码片段和文件信息
/*
 * 设置动物属性:
 * 动物所在的point
 * 动物图片路径
 * 动物是否在左边
 */
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Animal extends JPanel
{
   Point point; //
   
   boolean isLeft;//是否在左边
   
   Toolkit tool;//
//   This class is the abstract superclass of all actual implementations of the Abstract Window Toolkit. 
//   Subclasses of the Toolkit class are used to bind the various components to particular native toolkit implementations. 
//
//   Many GUI events may be delivered to user asynchronously if the opposite is not specified explicitly. 
//   As well as many GUI operations may be performed asynchronously. This fact means that if the state of a component is set
//   and then the state immediately queried the returned value may not yet reflect the requested change. 
//   This behavior includes but is not limited to: 
//
//   Scrolling to a specified position. 
//   For example calling ScrollPane.setScrollPosition and then getScrollPosition may return an incorrect value if the original request has not yet been processed. 
//
//   Moving the focus from one component to another. 
//   For more information see Timing Focus Transfers a section in The Swing Tutorial. 
//
//   Making a top-level container visible. 
//   Calling setVisible(true) on a Window frame or Dialog may occur asynchronously. 
//
//   Setting the size or location of a top-level container. 
//   Calls to setSize setBounds or setLocation on a Window frame or Dialog are forwarded to the underlying window management system
//   and may be ignored or modified. See java.awt.Window for more information. 
//   Most applications should not call any of the methods in this class directly. The methods defined by Toolkit are the “glue“ that 
//   joins the platform-independent classes in the java.awt package with their counterparts in java.awt.peer. 
//   Some methods defined by Toolkit query the native operating system directly.


//   实现功能
//   1、滚动到指定位置
//   例如,如果原始请求没有被处理,那么调用 ScrollPane.setScrollPosition 并随后调用 getScrollPosition 可能返回一个不正确的值。
//   2、将焦点从一个组件移动到另一个组件。
//   3、使某一顶层容器可视。
//   4、设置顶层容器的大小或位置
//   因为是抽象类,所以不能用new 实例化,可以用getDefaultToolkit返回Toolkit类的对象
//   例如: Toolkit toolkit=Toolkit.getDefaultToolkit();
   
   File leftImage; //左图片文件
   File rightImage;//右图片文件
   
   Animal()
   {
       tool=getToolkit();
//       Gets the toolkit of this component. Note that the frame that contains a component
//       controls which toolkit is used by that component. Therefore if the component is moved
//       from one frame to another the toolkit it uses may change.
//       对系统低层实现图形控件的最基本功能的一些接口
   }
   public void setLeftImage(File f)//设置左边的动物
   {
       leftImage=f;
   }
 
   public void setRightImage(File f)//设置右边的动物
   {
       rightImage=f;
   }
   public void setIsLeft(boolean boo)//设置是否为左边的动物
   {
       isLeft=boo;
   }
   public boolean  getIsLeft()//判断是否为左边的动物
   {
       return isLeft;
   }
   public void setAtPoint(Point p)//设置此时在哪个point
   {
      po

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.       295  2014-12-23 19:31  AnimalChange.classpath

    ..A..H.      8196  2014-12-25 11:39  AnimalChange.DS_Store

    ..A..H.       371  2014-12-23 19:31  AnimalChange.project

     文件         76  2015-01-05 12:00  AnimalChange.settingsorg.eclipse.core.resources.prefs

     文件        587  2014-12-23 19:31  AnimalChange.settingsorg.eclipse.jdt.core.prefs

    ..A..H.      6148  2014-12-23 20:34  AnimalChangein.DS_Store

     文件       1899  2015-01-08 09:31  AnimalChangeinAnimal.class

     文件        987  2015-01-09 11:08  AnimalChangeinAutoMoveAnimal$1.class

     文件       6935  2015-01-09 11:08  AnimalChangeinAutoMoveAnimal.class

     文件        789  2015-01-09 11:17  AnimalChangeinChangeAnimalWindow$1.class

     文件      13013  2015-01-09 11:17  AnimalChangeinChangeAnimalWindow.class

     文件        649  2015-01-08 09:31  AnimalChangeinCustomdlg$1.class

     文件       2064  2015-01-08 09:31  AnimalChangeinCustomdlg.class

     文件       5860  2015-01-08 11:17  AnimalChangeinHandleMouse.class

     文件        846  2015-01-09 09:29  AnimalChangeinPeople.class

     文件       1346  2015-01-08 09:31  AnimalChangeinPoint.class

     文件       2971  2015-01-08 09:31  AnimalChangeinRecord.class

     文件        645  2015-01-08 11:06  AnimalChangeinShowRecordDialog$1.class

     文件       3907  2015-01-08 11:06  AnimalChangeinShowRecordDialog.class

     文件        454  2015-01-08 09:31  AnimalChangeinStone.class

    ..A..H.      6148  2015-01-05 19:56  AnimalChangeimages.DS_Store

     文件      11384  2015-01-05 12:18  AnimalChangeimagescat.JPG

     文件       4793  2015-01-05 11:53  AnimalChangeimagescat10.jpg

     文件       4297  2015-01-05 11:51  AnimalChangeimagescat2.jpg

     文件       4522  2015-01-05 11:51  AnimalChangeimagescat3.jpg

     文件       4993  2015-01-05 11:51  AnimalChangeimagescat4.jpg

     文件       4401  2015-01-05 11:51  AnimalChangeimagescat5.jpg

     文件       8570  2015-01-05 11:52  AnimalChangeimagescat6.jpg

     文件       5074  2015-01-05 11:52  AnimalChangeimagescat7.jpg

     文件       7384  2015-01-05 11:52  AnimalChangeimagescat8.jpg

............此处省略40个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)