JavaScript实现的游戏们

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

伴随Ajax与网页游戏的崛起,曾几何时JavaScript也成了游戏开发时可供选择的技术之一,文本仅列举数项由JavaScript技术实现的web小游戏(不含网游),聊作参考之用。

1、Mario(游戏地址:http://jsmario.com.ar/

00

传说中的马里奥网页版,一比一实现了红白机时代超级马里奥中所有功能与关卡,精细程度不逊原版游戏。
依赖库:无


2Bunny Hunt (游戏地址:http://www.themaninblue.com/experiment/BunnyHunt/

00

猎兔,一款简单耐玩的网页狩猎游戏,没有使用第三方支持库,直接利用cssJavasSript实现。 

依赖库:无

 

3Bomberman游戏地址:http://www.e-forum.ro/bomberman/dynagame.html

00

炸弹人,经典到无以复加的桌面游戏,通过JavaScript获得了完美再现。 

依赖库:MooTools SoundManager2

 

4PacMan游戏地址:http://www.digitalinsane.com/api/yahoo/pacman/


 00

又一款传说级的游戏,笔者开始怀疑有某个超级闲的家伙(或组织),开始悄悄将红白机时代的游戏统一移植为web版……嗯,或许近些年出现的JavaScriptFC模拟器就是他们的阴谋产物…… 

依赖库:YUI

 

5Ajax Chinese Chess(游戏地址:http://ajaxchess.pragmaticlogic.com/

00

举凡识字的中国人看到此图,就会知道这是一款基于JavaScript的中国象棋游戏…… 

依赖库:MooTools SoundManager2

 

6Sudoku(游戏地址:http://www.dhtmlgoodies.com/scripts/game_sudoku/game_sudoku.html

00

疯狂走红的数独游戏,JavaScript狂人们又怎么可能放过呢?(似乎所有可以进行图形显示的系统上都能跑这个游戏了……) 

依赖库:无

 

7Spacius(游戏地址:http://scriptnode.com/lab/spacius/

00

就是著名的雷电啦,完成度相当高的经典射击游戏,效果流畅,笔者第一次运行时曾一度误以为在玩Flash。 

依赖库:SoundManager2 

 

8BrowserShooter游戏地址:http://valums.com/demos/game/

00


想让IE干掉Firefox抑或Chrome?哎,现实生活中是没希望了——不过,在该游戏中你却可以暂时做到这一点。 

依赖库:jQuery

 

9BertsBreakdown游戏地址:http://www.paulbrunt.co.uk/bert/

00

又一款强悍到逆天的JavaScript横版游戏,在Chrome下的表现已经与同类Flash游戏不相伯仲了。 

依赖库:

 

10JS-Wars(游戏地址:http://29a.ch/jswars/

 00

雷电类的横版射击游戏,似乎用JavaScript进行游戏开发的家伙都很喜欢横板游戏……作者在游戏介绍里写到——你们的任务是:找出骷髅博士,并消灭他!

依赖库:jQuery

 

11JavascriptWolfenstein 3D(游戏地址:http://www.nihilogic.dk/labs/wolf/

 00

由传说中的天才JS程序员——Jacob Seidelin 所作(瞧瞧,人家名字是怎么叫的,学问啊……)。移植自世界上第一款第一人称射击游戏(有争议,一说为《Ultima Underworld》),也就是《重返德军总部》前作《德军总部》的JavaScript复刻版。

仅从现阶段JavaScript综合性能来说,其完成度之高令人叹为观止,恐怕连部分Flash游戏开发者也要自惭形秽。如果有朝一日WebGL标准普及了,哪怕该作者用JavaScript复刻出一个魔兽世界偶都毫不奇怪……唯一遗憾的是,此游戏依赖于JavaScriptCanvas技术,可能对IE不友好……

依赖库:SoundManager2

 

PS:本想收录js版《白之绊》、《逆转裁判》、《大恶司》等,却发现其对外链接皆已无法使用,故缺(似乎相关作者都跑去开发web网游,集体生死未卜中……)。

再者,长城以外http://www.javascriptgaming.com/上还有很多JavaScript游戏实现,由于时间关系此处不一一列举,关心者请自行“翻而阅之”。

 

 ————————正文斩断,相关退散————————

 

转了不少JavaScript游戏过来,忽然自己也想写点东西,所以用开发了“半截”的LGame-Simple-0.2.5写了其中一个JavaScript游戏的复刻(目前修正了前版部分Bug,添加了一些精灵与辅助功能,但0.2.5的核心功能尚未添加,可理解为传说中的“降龙十八缺三掌”状态……),怎么说Java开发游戏也比JavaScript方便嘛,无论是桌面上,抑或网页里……

 

PS:不要问偶为什么移植Bunny Hunt而不是Javascript Wolfenstein 3D……除非偶吃顶了,或者不用睡觉……(另外偶最近会先忙正事,LGame将暂时停笔,留待12月中旬继续……12月底前发布0.2.5版……)

 

下载地址:http://code.google.com/p/loon-simple/downloads/list

 

00

 

  1. package org.loon.test;  
  2. import java.awt.Color;  
  3. import java.awt.Graphics2D;  
  4. import java.awt.event.KeyEvent;  
  5. import java.awt.event.MouseEvent;  
  6. import org.loon.framework.game.simple.GameScene;  
  7. import org.loon.framework.game.simple.action.map.Vector2D;  
  8. import org.loon.framework.game.simple.action.sprite.Label;  
  9. import org.loon.framework.game.simple.action.sprite.StatusBar;  
  10. import org.loon.framework.game.simple.action.sprite.Picture;  
  11. import org.loon.framework.game.simple.action.sprite.Sprite;  
  12. import org.loon.framework.game.simple.action.sprite.Sprites;  
  13. import org.loon.framework.game.simple.core.Deploy;  
  14. import org.loon.framework.game.simple.core.LSystem;  
  15. import org.loon.framework.game.simple.core.LTimer;  
  16. import org.loon.framework.game.simple.core.LTimerContext;  
  17. import org.loon.framework.game.simple.core.Screen;  
  18. import org.loon.framework.game.simple.window.LButton;  
  19. import org.loon.framework.game.simple.window.LPanel;  
  20. import org.loon.framework.game.simple.window.LTag;  
  21. /** 
  22.  * Copyright 2008 - 2009 
  23.  *  
  24.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  25.  * use this file except in compliance with the License. You may obtain a copy of 
  26.  * the License at 
  27.  *  
  28.  * http://www.apache.org/licenses/LICENSE-2.0 
  29.  *  
  30.  * Unless required by applicable law or agreed to in writing, software 
  31.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
  32.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
  33.  * License for the specific language governing permissions and limitations under 
  34.  * the License. 
  35.  *  
  36.  * @project loonframework 
  37.  * @author chenpeng 
  38.  * @email:ceponline@yahoo.com.cn 
  39.  * @version 0.1 
  40.  */  
  41. public class BunnyHunt extends Screen {  
  42.     interface IBunny {  
  43.         int type();  
  44.         void reset();  
  45.         void kill();  
  46.         void setVisible(boolean visible);  
  47.     }  
  48.     private int level, count;  
  49.     private class Bunny extends Sprite implements IBunny {  
  50.         /** 
  51.          *  
  52.          */  
  53.         private static final long serialVersionUID = 1L;  
  54.         private boolean init, kill;  
  55.         private int top, bottom, type;  
  56.         private LTimer timer;  
  57.         private Vector2D oldVector2D;  
  58.         public Bunny(String fileName, int row, int col, int top, int bottom) {  
  59.             super(fileName, row, col);  
  60.             this.top = top;  
  61.             this.bottom = bottom;  
  62.             this.isRunning(false);  
  63.             this.setCurrentFrameIndex(0);  
  64.             this.timer = new LTimer(100);  
  65.             this.reset();  
  66.         }  
  67.         public void setLocation(double x, double y) {  
  68.             super.setLocation(x, y);  
  69.             this.oldVector2D = new Vector2D(x, y);  
  70.         }  
  71.         public int type() {  
  72.             return type;  
  73.         }  
  74.         public void reset() {  
  75.             this.kill = false;  
  76.             this.init = false;  
  77.             this.setVisible(false);  
  78.             this.setLocation(oldVector2D);  
  79.             if (getTotalFrames() == 2) {  
  80.                 this.setCurrentFrameIndex(0);  
  81.             }  
  82.         }  
  83.         public void update(long elapsedTime) {  
  84.             if (!isVisible()) {  
  85.                 return;  
  86.             }  
  87.             super.update(elapsedTime);  
  88.             if (gameStart) {  
  89.                 if (!init) {  
  90.                     if (y() > top) {  
  91.                         // 精灵坐标向上移动(5倍速)  
  92.                         this.move_up(5);  
  93.                     } else {  
  94.                         this.init = true;  
  95.                     }  
  96.                 }  
  97.                 if (init && timer.action(elapsedTime)) {  
  98.                     if (kill) {  
  99.                         if (getTotalFrames() != 2) {  
  100.                             this.type = 1;  
  101.                             this.setCurrentFrameIndex(2);  
  102.                         }  
  103.                     }  
  104.                     timer.setDelay(10);  
  105.                     if (y() > bottom) {  
  106.                         // 精灵坐标向下移动(10倍速)  
  107.                         this.move_down(10);  
  108.                         if (y() >= BunnyHunt.this.getHeight()) {  
  109.                             this.reset();  
  110.                             BunnyHunt.this.randomBunny();  
  111.                         }  
  112.                     }  
  113.                 }  
  114.             }  
  115.         }  
  116.         public boolean isKill() {  
  117.             return kill;  
  118.         }  
  119.         public void kill() {  
  120.             if (getCurrentFrameIndex() != 2) {  
  121.                 this.setCurrentFrameIndex(1);  
  122.                 this.timer.setDelay(100);  
  123.                 this.kill = true;  
  124.             }  
  125.         }  
  126.     }  
  127.     // 信息选择框,用于显示重启/结束菜单  
  128.     private class MsgBox extends LPanel {  
  129.         private LTag text2 = new LTag("" + count, 3701505050);  
  130.         public void setNumber(int num) {  
  131.             text2.setTag(num);  
  132.         }  
  133.         public MsgBox(int x, int y, int w, int h) {  
  134.             super(x, y, w, h);  
  135.             // 面板设为灰色  
  136.             setBackground(Color.GRAY);  
  137.             // 透明度0.5f  
  138.             setAlpha(0.5f);  
  139.             LButton button1 = new LButton("games/button_reload.gif"null180,  
  140.                     200) {  
  141.                 public void doClick() {  
  142.                     BunnyHunt.this.removeAll();  
  143.                     BunnyHunt.this.initBunny();  
  144.                 }  
  145.             };  
  146.             LButton button2 = new LButton("games/button_stop.gif"null400,  
  147.                     200) {  
  148.                 public void doClick() {  
  149.                     BunnyHunt.this.removeAll();  
  150.                     BunnyHunt.this.setBackground("games/closing.jpg");  
  151.                 }  
  152.             };  
  153.             LTag text1 = new LTag("Number of bunnies mutilated:"2159050,  
  154.                     50);  
  155.             text1.setColor(Color.WHITE);  
  156.             text1.setFont("Dialog"025);  
  157.             text2.setColor(Color.WHITE);  
  158.             text2.setFont("Dialog"130);  
  159.             add(text1);  
  160.             add(text2);  
  161.             add(button1);  
  162.             add(button2);  
  163.         }  
  164.     }  
  165.     private class Cloud extends Picture {  
  166.         private static final long serialVersionUID = 1L;  
  167.         private LTimer timer = new LTimer(20);  
  168.         public Cloud(String fileName, int x, int y) {  
  169.             super(fileName, x, y);  
  170.         }  
  171.         public void update(long elapsedTime) {  
  172.             if (isVisible() && timer.action(elapsedTime)) {  
  173.                 // 自动向左移动  
  174.                 move_left();  
  175.                 if(x()<0){  
  176.                     setX(BunnyHunt.this.getWidth());  
  177.                 }  
  178.             }  
  179.         }  
  180.     }  
  181.     private Label label1 = new Label("LEVEL :""Dialog"01530023),  
  182.             label2 = new Label("""Dialog"11236022),  
  183.             label3 = new Label("LIVES :""Dialog"01553023);  
  184.     private StatusBar timeBar = new StatusBar(400151005);  
  185.     private MsgBox msgBox = new MsgBox(00800400);  
  186.     private Bunny bunny1, bunny2, bunny3, bunny4, bunny5;  
  187.     private IBunny[] bunnies;  
  188.     private Sprite lives = new Sprite("games/lives.gif"60076021);  
  189.     private Picture hill = new Picture("games/hill.png"200288);  
  190.     private Cloud cloud1 = new Cloud("games/cloud.png"19520);  
  191.     private Cloud cloud2 = new Cloud("games/cloud2.png"7520);  
  192.     private Picture hills = new Picture("games/hills.png"0235);  
  193.     private LTimer time = new LTimer(2 * LSystem.SECOND);  
  194.     private boolean gameStart;  
  195.     public BunnyHunt() {  
  196.         // 设定初始背景  
  197.         this.setBackground("games/splash.jpg");  
  198.         LButton startButton = new LButton("games/button_start.gif"null165,  
  199.                 260) {  
  200.             public void doClick() { // 变更背景图像  
  201.                 BunnyHunt.this.setBackground("games/stage.jpg");  
  202.                 BunnyHunt.this.initBunny();  
  203.                 this.dispose();  
  204.             }  
  205.         }; // 添加开始按钮  
  206.         this.add(startButton);  
  207.     }  
  208.     private void endGame() {  
  209.         this.gameStart = false;  
  210.         this.msgBox.setNumber(count);  
  211.         this.timeBar.setHit(false);  
  212.         this.add(msgBox);  
  213.     }  
  214.     private void randomBunny() {  
  215.         for (int i = 0; i < level && i < 3; i++) {  
  216.             bunnies[getBunnyRandom(bunnies.length)].setVisible(true);  
  217.         }  
  218.     }  
  219.     private int getBunnyRandom(int type) {  
  220.         return LSystem.random.nextInt(type);  
  221.     }  
  222.     private void initBunny() {  
  223.         this.gameStart = true;  
  224.         this.level = 1;  
  225.         this.count = 0;  
  226.         this.bunny1 = new Bunny("games/bunny1.png"8415213050);  
  227.         this.bunny2 = new Bunny("games/bunny2.png"11915219050);  
  228.         this.bunny3 = new Bunny("games/bunny3.png"12215215050);  
  229.         this.bunny4 = new Bunny("games/bunny4.png"13515218050);  
  230.         this.bunny5 = new Bunny("games/bunny5.png"14015218050);  
  231.         this.bunnies = new IBunny[] { bunny1, bunny2, bunny3, bunny4, bunny5 };  
  232.         this.timeBar.setHit(true);  
  233.         this.timeBar.empty();  
  234.         this.label2.setLabel(level);  
  235.         this.label1.setAlpha(0.8f);  
  236.         this.add(label1);  
  237.         this.add(label2);  
  238.         this.label3.setAlpha(0.8f);  
  239.         this.add(label3);  
  240.         this.add(timeBar);  
  241.         this.lives.isRunning(false);  
  242.         this.lives.setCurrentFrameIndex(0);  
  243.         this.add(lives);  
  244.         this.bunny1.setLocation(40400);  
  245.         this.bunny3.setLocation(550400);  
  246.         this.bunny4.setLocation(130400);  
  247.         this.bunny5.setLocation(430400);  
  248.         this.add(bunny1);  
  249.         this.add(bunny3);  
  250.         this.add(bunny4);  
  251.         this.add(bunny5);  
  252.         this.add(hills);  
  253.         this.bunny2.setLocation(410400);  
  254.         this.add(bunny2);  
  255.         this.add(hill);  
  256.         this.add(cloud1);  
  257.         this.add(cloud2);  
  258.         this.randomBunny();  
  259.     }  
  260.     public void alter(LTimerContext timer) {  
  261.         if (time.action(timer.getTimeSinceLastUpdate())) {  
  262.             if (timeBar.getValue() < timeBar.getMaxValue()) {  
  263.                 timeBar.setUpdate(timeBar.getValue() + 10);  
  264.             } else {  
  265.                 timeBar.empty();  
  266.                 level += 1;  
  267.                 label2.setLabel(level);  
  268.             }  
  269.         }  
  270.     }  
  271.     public void draw(Graphics2D g) {  
  272.     }  
  273.     public void leftClick(MouseEvent e) {  
  274.         if (contains(msgBox)) {  
  275.             return;  
  276.         }  
  277.         Sprites ss = getSprites();  
  278.         for (int i = ss.size(); i > -1; --i) {  
  279.             if (ss.getSprite(i) instanceof IBunny) {  
  280.                 if (onClick(ss.getSprite(i))) {  
  281.                     IBunny bunny = ((IBunny) ss.getSprite(i));  
  282.                     if (bunny.type() == 1) {  
  283.                         lives  
  284.                                 .setCurrentFrameIndex(lives  
  285.                                         .getCurrentFrameIndex() + 1);  
  286.                         if (lives.getCurrentFrameIndex() >= 3) {  
  287.                             endGame();  
  288.                         }  
  289.                     } else {  
  290.                         bunny.kill();  
  291.                         count += 1;  
  292.                     }  
  293.                     return;  
  294.                 }  
  295.             }  
  296.         }  
  297.     }  
  298.     public void middleClick(MouseEvent e) {  
  299.     }  
  300.     public void onKey(KeyEvent e) {  
  301.     }  
  302.     public void onKeyUp(KeyEvent e) {  
  303.     }  
  304.     public void rightClick(MouseEvent e) {  
  305.     }  
  306.     public static void main(String[] args) {  
  307.         GameScene frame = new GameScene("猎兔(素材取自同名Javascript游戏)"800400);  
  308.         Deploy deploy = frame.getDeploy();  
  309.         deploy.setScreen(new BunnyHunt());  
  310.         deploy.setLogo(false);  
  311.         deploy.setShowFPS(true);  
  312.         deploy.setFPS(100);  
  313.         deploy.mainLoop();  
  314.         frame.showFrame();  
  315.     }  
  316. }  
package org.loon.test;import java.awt.Color;import java.awt.Graphics2D;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import org.loon.framework.game.simple.GameScene;import org.loon.framework.game.simple.action.map.Vector2D;import org.loon.framework.game.simple.action.sprite.Label;import org.loon.framework.game.simple.action.sprite.StatusBar;import org.loon.framework.game.simple.action.sprite.Picture;import org.loon.framework.game.simple.action.sprite.Sprite;import org.loon.framework.game.simple.action.sprite.Sprites;import org.loon.framework.game.simple.core.Deploy;import org.loon.framework.game.simple.core.LSystem;import org.loon.framework.game.simple.core.LTimer;import org.loon.framework.game.simple.core.LTimerContext;import org.loon.framework.game.simple.core.Screen;import org.loon.framework.game.simple.window.LButton;import org.loon.framework.game.simple.window.LPanel;import org.loon.framework.game.simple.window.LTag;/** * Copyright 2008 - 2009 *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *  * http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. *  * @project loonframework * @author chenpeng * @email:ceponline@yahoo.com.cn * @version 0.1 */public class BunnyHunt extends Screen { interface IBunny {  int type();  void reset();  void kill();  void setVisible(boolean visible); } private int level, count; private class Bunny extends Sprite implements IBunny {  /**   *    */  private static final long serialVersionUID = 1L;  private boolean init, kill;  private int top, bottom, type;  private LTimer timer;  private Vector2D oldVector2D;  public Bunny(String fileName, int row, int col, int top, int bottom) {   super(fileName, row, col);   this.top = top;   this.bottom = bottom;   this.isRunning(false);   this.setCurrentFrameIndex(0);   this.timer = new LTimer(100);   this.reset();  }  public void setLocation(double x, double y) {   super.setLocation(x, y);   this.oldVector2D = new Vector2D(x, y);  }  public int type() {   return type;  }  public void reset() {   this.kill = false;   this.init = false;   this.setVisible(false);   this.setLocation(oldVector2D);   if (getTotalFrames() == 2) {    this.setCurrentFrameIndex(0);   }  }  public void update(long elapsedTime) {   if (!isVisible()) {    return;   }   super.update(elapsedTime);   if (gameStart) {    if (!init) {     if (y() > top) {      // 精灵坐标向上移动(5倍速)      this.move_up(5);     } else {      this.init = true;     }    }    if (init && timer.action(elapsedTime)) {     if (kill) {      if (getTotalFrames() != 2) {       this.type = 1;       this.setCurrentFrameIndex(2);      }     }     timer.setDelay(10);     if (y() > bottom) {      // 精灵坐标向下移动(10倍速)      this.move_down(10);      if (y() >= BunnyHunt.this.getHeight()) {       this.reset();       BunnyHunt.this.randomBunny();      }     }    }   }  }  public boolean isKill() {   return kill;  }  public void kill() {   if (getCurrentFrameIndex() != 2) {    this.setCurrentFrameIndex(1);    this.timer.setDelay(100);    this.kill = true;   }  } } // 信息选择框,用于显示重启/结束菜单 private class MsgBox extends LPanel {  private LTag text2 = new LTag("" + count, 370, 150, 50, 50);  public void setNumber(int num) {   text2.setTag(num);  }  public MsgBox(int x, int y, int w, int h) {   super(x, y, w, h);   // 面板设为灰色   setBackground(Color.GRAY);   // 透明度0.5f   setAlpha(0.5f);   LButton button1 = new LButton("games/button_reload.gif", null, 180,     200) {    public void doClick() {     BunnyHunt.this.removeAll();     BunnyHunt.this.initBunny();    }   };   LButton button2 = new LButton("games/button_stop.gif", null, 400,     200) {    public void doClick() {     BunnyHunt.this.removeAll();     BunnyHunt.this.setBackground("games/closing.jpg");    }   };   LTag text1 = new LTag("Number of bunnies mutilated:", 215, 90, 50,     50);   text1.setColor(Color.WHITE);   text1.setFont("Dialog", 0, 25);   text2.setColor(Color.WHITE);   text2.setFont("Dialog", 1, 30);   add(text1);   add(text2);   add(button1);   add(button2);  } } private class Cloud extends Picture {  private static final long serialVersionUID = 1L;  private LTimer timer = new LTimer(20);  public Cloud(String fileName, int x, int y) {   super(fileName, x, y);  }  public void update(long elapsedTime) {   if (isVisible() && timer.action(elapsedTime)) {    // 自动向左移动    move_left();    if(x()<0){     setX(BunnyHunt.this.getWidth());    }   }  } } private Label label1 = new Label("LEVEL :", "Dialog", 0, 15, 300, 23),   label2 = new Label("", "Dialog", 1, 12, 360, 22),   label3 = new Label("LIVES :", "Dialog", 0, 15, 530, 23); private StatusBar timeBar = new StatusBar(400, 15, 100, 5); private MsgBox msgBox = new MsgBox(0, 0, 800, 400); private Bunny bunny1, bunny2, bunny3, bunny4, bunny5; private IBunny[] bunnies; private Sprite lives = new Sprite("games/lives.gif", 600, 7, 60, 21); private Picture hill = new Picture("games/hill.png", 200, 288); private Cloud cloud1 = new Cloud("games/cloud.png", 195, 20); private Cloud cloud2 = new Cloud("games/cloud2.png", 75, 20); private Picture hills = new Picture("games/hills.png", 0, 235); private LTimer time = new LTimer(2 * LSystem.SECOND); private boolean gameStart; public BunnyHunt() {  // 设定初始背景  this.setBackground("games/splash.jpg");  LButton startButton = new LButton("games/button_start.gif", null, 165,    260) {   public void doClick() { // 变更背景图像    BunnyHunt.this.setBackground("games/stage.jpg");    BunnyHunt.this.initBunny();    this.dispose();   }  }; // 添加开始按钮  this.add(startButton); } private void endGame() {  this.gameStart = false;  this.msgBox.setNumber(count);  this.timeBar.setHit(false);  this.add(msgBox); } private void randomBunny() {  for (int i = 0; i < level && i < 3; i++) {   bunnies[getBunnyRandom(bunnies.length)].setVisible(true);  } } private int getBunnyRandom(int type) {  return LSystem.random.nextInt(type); } private void initBunny() {  this.gameStart = true;  this.level = 1;  this.count = 0;  this.bunny1 = new Bunny("games/bunny1.png", 84, 152, 130, 50);  this.bunny2 = new Bunny("games/bunny2.png", 119, 152, 190, 50);  this.bunny3 = new Bunny("games/bunny3.png", 122, 152, 150, 50);  this.bunny4 = new Bunny("games/bunny4.png", 135, 152, 180, 50);  this.bunny5 = new Bunny("games/bunny5.png", 140, 152, 180, 50);  this.bunnies = new IBunny[] { bunny1, bunny2, bunny3, bunny4, bunny5 };  this.timeBar.setHit(true);  this.timeBar.empty();  this.label2.setLabel(level);  this.label1.setAlpha(0.8f);  this.add(label1);  this.add(label2);  this.label3.setAlpha(0.8f);  this.add(label3);  this.add(timeBar);  this.lives.isRunning(false);  this.lives.setCurrentFrameIndex(0);  this.add(lives);  this.bunny1.setLocation(40, 400);  this.bunny3.setLocation(550, 400);  this.bunny4.setLocation(130, 400);  this.bunny5.setLocation(430, 400);  this.add(bunny1);  this.add(bunny3);  this.add(bunny4);  this.add(bunny5);  this.add(hills);  this.bunny2.setLocation(410, 400);  this.add(bunny2);  this.add(hill);  this.add(cloud1);  this.add(cloud2);  this.randomBunny(); } public void alter(LTimerContext timer) {  if (time.action(timer.getTimeSinceLastUpdate())) {   if (timeBar.getValue() < timeBar.getMaxValue()) {    timeBar.setUpdate(timeBar.getValue() + 10);   } else {    timeBar.empty();    level += 1;    label2.setLabel(level);   }  } } public void draw(Graphics2D g) { } public void leftClick(MouseEvent e) {  if (contains(msgBox)) {   return;  }  Sprites ss = getSprites();  for (int i = ss.size(); i > -1; --i) {   if (ss.getSprite(i) instanceof IBunny) {    if (onClick(ss.getSprite(i))) {     IBunny bunny = ((IBunny) ss.getSprite(i));     if (bunny.type() == 1) {      lives        .setCurrentFrameIndex(lives          .getCurrentFrameIndex() + 1);      if (lives.getCurrentFrameIndex() >= 3) {       endGame();      }     } else {      bunny.kill();      count += 1;     }     return;    }   }  } } public void middleClick(MouseEvent e) { } public void onKey(KeyEvent e) { } public void onKeyUp(KeyEvent e) { } public void rightClick(MouseEvent e) { } public static void main(String[] args) {  GameScene frame = new GameScene("猎兔(素材取自同名Javascript游戏)", 800, 400);  Deploy deploy = frame.getDeploy();  deploy.setScreen(new BunnyHunt());  deploy.setLogo(false);  deploy.setShowFPS(true);  deploy.setFPS(100);  deploy.mainLoop();  frame.showFrame(); }}

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 12
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值