• 大小: 12KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: Java
  • 标签: java  

资源简介

java实现贪吃蛇-源码+资源+可运行的jar包,下载后直接解压双击内部的jar包可直接查看运行效果,内部符源码和资源,注释详细,欢迎下载。

资源截图

代码片段和文件信息

package Snake;

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);
                    break;
                case KeyEvent.VK_RIGHT:
                    model.changeDirection(SnakeModel.RIGHT);
                    break;             
                case KeyEvent.VK_SPACE:               
                    model.changePauseState();
                    break;
                default:
            }
        }

        // 致重新启动游戏
        if (keyCode == KeyEvent.VK_ENTER) {
            model.reset();
        }
    }

@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub

}

@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub

}

    
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-25 17:05  GreedSnake\
     文件         301  2018-01-01 13:34  GreedSnake\.classpath
     文件         386  2018-01-01 13:34  GreedSnake\.project
     目录           0  2018-09-25 17:05  GreedSnake\.settings\
     文件         598  2018-01-01 13:34  GreedSnake\.settings\org.eclipse.jdt.core.prefs
     目录           0  2018-09-25 17:05  GreedSnake\bin\
     目录           0  2018-09-25 17:05  GreedSnake\bin\Snake\
     文件         353  2018-01-08 15:47  GreedSnake\bin\Snake\Node.class
     文件        1135  2018-01-08 13:05  GreedSnake\bin\Snake\SnakeControl.class
     文件        3476  2018-01-08 15:47  GreedSnake\bin\Snake\SnakeModel.class
     文件        3668  2018-01-08 14:02  GreedSnake\bin\Snake\SnakeView.class
     文件         852  2018-01-08 12:35  GreedSnake\bin\Snake\Text.class
     目录           0  2018-09-25 17:05  GreedSnake\src\
     目录           0  2018-09-25 17:05  GreedSnake\src\Snake\
     文件        1471  2018-01-08 13:05  GreedSnake\src\Snake\SnakeControl.java
     文件        5372  2018-01-08 15:47  GreedSnake\src\Snake\SnakeModel.java
     文件        2839  2018-01-08 14:02  GreedSnake\src\Snake\SnakeView.java
     文件         393  2018-01-08 12:35  GreedSnake\src\Snake\Text.java

评论

共有 条评论