资源简介
猴子摘香蕉 源码 人工智能课程作业 界面写的还不错 用的状态空间法
代码片段和文件信息
package Monkey;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Monkey extends Jframe implements ActionListener{
private Dimension screenSize;
private Canvas monkeyP;
private JButton start;
private FlowLayout fl;
private Point monkeyLocation=null;
private Point boxLocation=null;
private Point bananaLocation=null;
private Image box=null;
private Image banana=null;
private Image monkey=null;
private Image offScreenImage = null;
private static final int x=300;
private static final int y=395;
private static final int stepXX=150;
private static final int stepXY=50;
private static final int stepY=75;
private static int step=0;
private Graphics gg1;
private Point roomMonkey;
private Point roomBox;
private Point roomBlanana;
private int[][] room;
private boolean onlyMonkey=true;
private int State;
public static final int START=0;
public static final int FINDBOX=1;
public static final int ONBOX=2;
public static final int GETBLANANA=3;
public static final int END=4;
public Monkey()
{
super();
screenSize=Toolkit.getDefaultToolkit().getScreenSize();
fl=new FlowLayout();
this.settitle(“猴子摘香蕉“);
this.setSize(screenSize.width screenSize.height);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
init();
}
public void init()
{
monkeyP=new Canvas();
start=new JButton(“start“);
start.addActionListener(this);
this.add(monkeyPBorderLayout.CENTER);
this.add(startBorderLayout.EAST);
monkeyP.setSize(this.getWidth() this.getHeight());
//System.out.println(“ “+monkeyP.getWidth()+“ “+monkeyP.getHeight());
System.out.println(“ “+monkeyP.getWidth()+“ “+monkeyP.getHeight());
}
public void common(Graphics gGraphics g1){
g.clearRect(0 0 monkeyP.getWidth() monkeyP.getHeight());
g.drawImage(box (int)boxLocation.getX()(int) boxLocation.getY() null);
g.drawImage(banana(int)bananaLocation.getX()+10(int)bananaLocation.getY()-20null);
g.drawImage(monkey (int)monkeyLocation.getX()(int) monkeyLocation.getY() null);
g.setColor(Color.black);
g.drawLine(300 5 1200 5);
g.drawLine(100 305 1000 305);
g.drawLine(300 5 100 305);
g.drawLine(1200 5 1000 305);
g.drawLine(100 305 100 695);
g.drawLine
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 232 2013-09-21 12:31 monkey\.classpath
文件 382 2013-09-21 12:31 monkey\.project
文件 519 2013-10-01 15:32 monkey\bin\Monkey\Monkey$1.class
文件 12007 2013-10-01 15:32 monkey\bin\Monkey\Monkey.class
文件 18532 2013-10-01 15:32 monkey\src\Monkey\Monkey.java
目录 0 2013-10-01 15:25 monkey\bin\Monkey
目录 0 2013-09-23 12:47 monkey\src\Monkey
目录 0 2013-09-30 21:38 monkey\bin
目录 0 2013-09-24 10:21 monkey\src
目录 0 2013-09-21 12:31 monkey
----------- --------- ---------- ----- ----
31672 10
评论
共有 条评论