java版 贪吃蛇小游戏 完整源码 (测试100%无误

package mvcTest;

 


    //July、06.11(完成测试)。
    //根据以下代码,编译,游戏运行界面如下:

   java版 <wbr>贪吃蛇小游戏 <wbr>完整源码 <wbr>(测试100%无误)java版 <wbr>贪吃蛇小游戏 <wbr>完整源码 <wbr>(测试100%无误)




public class GreedSnake {
   public static void main(String[] args) {
       SnakeModel model = new SnakeModel(20,30);
       SnakeControl control = new SnakeControl(model);
       SnakeView view = new SnakeView(model,control);
       //添加一个观察者,让view成为model的观察者
       model.addObserver(view);
      
       (new Thread(model)).start();
   }
}

-------------------------------------------------------------
2、


package mvcTest;

//SnakeControl.java
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class SnakeControl  implements KeyListener{
    SnakeModel model;

    public SnakeControl(SnakeModel model){
        this.model = model;
    }

    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (model.running){                // 运行状态下,处理的按键
            switch (keyCode) {
                case KeyEvent.VK_UP:
                    model.changeDirection(SnakeModel.UP);
                    break;
                case KeyEvent.VK_DOWN:
                    model.changeDirection(SnakeModel.DOWN);
                    break;
                case KeyEvent.VK_LEFT:
                    model.changeDirection(SnakeModel.LEFT);
      

阅读更多
文章标签: Java 贪吃蛇
想对作者说点什么? 我来说一句

java实现简单的贪吃蛇

2014年03月07日 10KB 下载

Snake-Java贪吃蛇

2017年09月04日 15KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭