当前位置: 代码迷 >> J2SE >> java小游戏吃豆子算法有关问题
  详细解决方案

java小游戏吃豆子算法有关问题

热度:33   发布时间:2016-04-24 14:02:33.0
java小游戏吃豆子算法问题

以下代码鬼自由跑->
需要
鬼一出来就在不停的计算离人最近的路线,然后过去抓住人.
我找个直线算法
http://www.learnjava.cn/Article/j2se/jinjie/200706/221.html   参考

初次接触望大大给与帮助
由于论坛字数限制     特把源代码存入网易163.com中ceshi_yonghu@163.com  
用户名/密码   :     ceshi_yonghu/yonghu     修改完在存与油箱中,感谢,请不要修改用户及密码谢谢合作
import   java.awt.*;
import   java.applet.Applet;

public   class   PacMan   extends   Applet   implements   Runnable
{
    Dimension d;
    Font   largefont   =   new   Font( "Helvetica ",   Font.BOLD,   24);
    Font smallfont   =   new   Font( "Helvetica ",   Font.BOLD,   14);

    FontMetrics fmsmall,   fmlarge;    
    Graphics goff;
    Image ii;
    Thread thethread;
    MediaTracker     thetracker   =   null;
    Color dotcolor=new   Color(192,192,0);
    int bigdotcolor=192;
    int dbigdotcolor=-2;
    Color mazecolor;

    boolean ingame=false;
    boolean showtitle=true;
    boolean               scared=false;
    boolean               dying=false;

    final   int screendelay=120;
    final   int           blocksize=24;
    final   int           nrofblocks=15;
    final   int           scrsize=nrofblocks*blocksize;
    final   int animdelay=8;
    final   int           pacanimdelay=2;
    final   int           ghostanimcount=2;
    final   int           pacmananimcount=4;
    final   int           maxghosts=12;
    final   int pacmanspeed=6;

    int animcount=animdelay;
    int                       pacanimcount=pacanimdelay;
    int pacanimdir=1;
    int count=screendelay;
    int ghostanimpos=0;
    int pacmananimpos=0;
    int nrofghosts=6;
    int pacsleft,score;
    int deathcounter;
    int[] dx,dy;
    int[] ghostx,   ghosty,   ghostdx,   ghostdy,   ghostspeed;

    Image ghost1,ghost2,ghostscared1,ghostscared2;
    Image pacman1,   pacman2up,   pacman2left,   pacman2right,   pacman2down;
    Image pacman3up,   pacman3down,   pacman3left,   pacman3right;
    Image pacman4up,   pacman4down,   pacman4left,   pacman4right;

    int pacmanx,   pacmany,   pacmandx,   pacmandy;
    int reqdx,   reqdy,   viewdx,   viewdy;
    int scaredcount,   scaredtime;
    final int maxscaredtime=120;
    final   int           minscaredtime=20;

    final   short       level1data[]   =   {  
19,26,26,22,   9,12,19,26,22,   9,12,19,26,26,22,
  相关解决方案