⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fruit.java

📁 一款修改过的手机贪食蛇游戏
💻 JAVA
字号:
/* * Fruit.java * * Created on June 19, 2007, 2:34 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package hello;import java.util.Random;import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;/** * * @author jiabei */public class Fruit {        private Point point;    public Fruit(int x, int y) {        point = new Point(x, y);    }         /** Creates a new instance of Fruit */    private static Random random = new Random();        public static int getRandomInt(int min, int max) {        return Math.abs(random.nextInt()) % (max + 1 - min) + min;    }        public static Fruit getRandomFruit(Map map) {        boolean run = true;        Point tmpPoint = new Point(0, 0);        while (run) {            tmpPoint.setX(getRandomInt(0, map.getWidth()));            tmpPoint.setY(getRandomInt(0, map.getHeight()));            run = false;            for (int i = 0; i < map.getSnakeNum(); i ++) {                if (map.getCurSnake(i).isInside(tmpPoint) >= 0) {                    run = true; break;                }            }            for (int i = 0; i < map.getFruitNum(); i ++) {                if (map.getFruit(i).getPoint().isSame(tmpPoint)) {                    run =true; break;                }            }        }        return new Fruit(tmpPoint.getX(), tmpPoint.getY());    }        public void drawFruit(Graphics g, int xPixels, int yPixels) {                g.setColor(0, 100, 0);        g.drawRect(xPixels * point.getX(), yPixels * point.getY(), xPixels, yPixels);           }        public Point getPoint() {        return point;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -