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

📄 tools.java

📁 手机版本的泡泡堂 用j2me写的 大家可以参考下
💻 JAVA
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/***
 * 类名:Tools
 * 功能:工具类  提供常用方法和资源管理。
 */
public final class Tools
{
    private static Random r = new Random();
    public static final int box4[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 11, 19, 11, 19, 11, 19 },
    { 0, 0, 23, 19, 19, 23, 19, 23 },
    { 19, 19, 11, 23, 11, 23, 11, 23 },
    { 19, 19, 0, 23, 23, 0, 19, 19 },
    { 23, 23, 0, 19, 19, 0, 19, 19 },
    { 23, 11, 23, 11, 23, 11, 19, 19 },
    { 23, 19, 23, 19, 19, 23, 0, 0 },
    { 19, 11, 19, 11, 19, 11, 0, 0 } };
    public static final int box3[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 22, 22, 22, 22, 22, 22 },
    { 0, 12, 18, 18, 18, 18, 12, 22 },
    { 18, 18, 18, 18, 18, 18, 18, 18 },
    { 20, 20, 12, 20, 20, 12, 20, 20 },
    { 20, 20, 12, 20, 20, 12, 20, 20 },
    { 18, 18, 18, 18, 18, 18, 18, 18 },
    { 22, 12, 18, 18, 18, 18, 12, 0 },
    { 22, 22, 22, 22, 22, 22, 0, 0 } };
    public static final int box2[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 21, 21, 21, 13, 21, 21 },
    { 0, 13, 21, 13, 21, 13, 21, 13 },
    { 13, 21, 21, 21, 21, 21, 21, 21 },
    { 21, 21, 21, 21, 13, 21, 13, 13 },
    { 13, 21, 13, 21, 13, 21, 21, 21 },
    { 21, 21, 21, 21, 21, 21, 21, 13 },
    { 13, 21, 13, 21, 13, 21, 13, 0 },
    { 21, 21, 13, 21, 21, 21, 0, 0 } };
    public static final int box1[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 17, 16, 17, 16, 0, 0 },
    { 0, 14, 17, 16, 17, 16, 14, 0 },
    { 17, 16, 15, 15, 15, 15, 16, 17 },
    { 16, 17, 15, 14, 14, 15, 17, 16 },
    { 17, 16, 15, 14, 14, 15, 16, 17 },
    { 16, 17, 15, 15, 15, 15, 17, 16 },
    { 0, 14, 16, 17, 16, 17, 14, 0 },
    { 0, 0, 16, 17, 16, 17, 0, 0 } };
    public static final int map4[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 1, 2, 1, 2, 1, 2, 1, 2 },
    { 2, 1, 2, 1, 2, 1, 2, 1 },
    { 1, 2, 1, 2, 1, 2, 1, 2 },
    { 2, 1, 2, 1, 2, 1, 2, 1 },
    { 1, 2, 1, 2, 1, 2, 1, 2 },
    { 2, 1, 2, 1, 2, 1, 2, 1 },
    { 1, 2, 1, 2, 1, 2, 1, 2 },
    { 2, 1, 2, 1, 2, 1, 2, 1 } };
    public static final int map3[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 3, 4, 3, 4, 3, 4, 3, 4 },
    { 4, 3, 4, 3, 4, 3, 4, 3 },
    { 3, 4, 3, 4, 3, 4, 3, 4 },
    { 4, 3, 4, 3, 4, 3, 4, 3 },
    { 3, 4, 3, 4, 3, 4, 3, 4 },
    { 4, 3, 4, 3, 4, 3, 4, 3 },
    { 3, 4, 3, 4, 3, 4, 3, 4 },
    { 4, 3, 4, 3, 4, 3, 4, 3 } };
    public static final int map2[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 5, 6, 5, 6, 5, 6, 5, 6 },
    { 6, 5, 6, 5, 6, 5, 6, 5 },
    { 5, 6, 5, 6, 5, 6, 5, 6 },
    { 6, 5, 6, 5, 6, 5, 6, 5 },
    { 5, 6, 5, 6, 5, 6, 5, 6 },
    { 6, 5, 6, 5, 6, 5, 6, 5 },
    { 5, 6, 5, 6, 5, 6, 5, 6 },
    { 6, 5, 6, 5, 6, 5, 6, 5 } };
    public static final int map1[][] =
    {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 },
    { 8, 7, 7, 8, 8, 7, 7, 8 } };
    public static Image logo;
    public static Image menu;
    public static Image water;
    public static Image cue;
    public static Image tile;
    public static Image player;
    public static Image playerstart;
    public static Image npc;
    public static Image npcstart;
    public static Image pass;
    public static Image over;
    public static Image map;
    public static Image ending;
    public static Image die;
    public static Image bg;
    public static Image font;
    public static Image arrowhead;

    private Tools()
    {
    }

    public static final void loadLogo()
    {
        try
        {
            logo = Image.createImage("/res/logo.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseLogo()
    {
        logo = null;
    }

    public static final void loadMenu()
    {
        try
        {
            menu = Image.createImage("/res/menu.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseMenu()
    {
        menu = null;
    }

    public static final void loadSetName()
    {
        try
        {
            bg = Image.createImage("/res/bg.png");
            font = Image.createImage("/res/font.png");
            arrowhead = Image.createImage("/res/arrowhead.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseSetName()
    {
        bg = null;
        font = null;
        arrowhead = null;
        System.gc();
    }

    public static final void loadBackGround()
    {
        try
        {
            bg = Image.createImage("/res/bg.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseBackGround()
    {
        bg = null;
    }

    public static final void loadGame()
    {
        try
        {
            bg = Image.createImage("/res/bg.png");
            water = Image.createImage("/res/water.png");
            cue = Image.createImage("/res/cue.png");
            tile = Image.createImage("/res/tile.png");
            player = Image.createImage("/res/player.png");
            playerstart = Image.createImage("/res/playerstart.png");
            map = Image.createImage("/res/map.png");
            die = Image.createImage("/res/die.png");
            npc = Image.createImage("/res/npc.png");
            npcstart = Image.createImage("/res/npcstart.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseGame()
    {
        bg = null;
        water = null;
        cue = null;
        tile = null;
        player = null;
        playerstart = null;
        map = null;
        die = null;
        npc = null;
        npcstart = null;
        System.gc();
    }

    public static final void loadPass()
    {
        try
        {
            pass = Image.createImage("/res/pass.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releasePass()
    {
        pass = null;
        System.gc();
    }

    public static final void loadEnding()
    {
        try
        {
            ending = Image.createImage("/res/ending.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseEnding()
    {
        ending = null;
    }

    public static final void loadOver()
    {
        try
        {
            over = Image.createImage("/res/over.png");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static final void releaseOver()
    {
        over = null;
    }

    /**
     * @方法说明: 行 或 列 转换成 坐标
     */
    public static final int toCoordinate(int cols)
    {
        return (cols << 4);
    }

    /**
     * @方法说明:坐标转换成 行和列;
     */
    public static final int toRange(int x)
    {
        if (x % 16 == 0)
        {
            return (x >>> 4) - 1;
        }
        if (x >= 0)
        {
            return (x >>> 4);
        }
        return (x >>> 4) - 1;
    }

    /**
     * 返回 0~n 之间的随机整数;
     * */
    public static final int getRandom(int n)
    {
        if (n <= 0)
        {
            return 0;
        }
        return (r.nextInt() >>> 1) % (n + 1);
    }

    /**
     * 返回 [n1~n2]之间的随机整数;
     * */
    public static final int getRandom(int n1, int n2)
    {
        return n1 + getRandom(n2 - n1);
    }

    /**
     * 画出局部图片;
     * */
    public static final void paintClip(Graphics g, Image img, int x, int y,
            int clipx, int clipy, int clipw, int cliph)
    {
        g.setClip(x, y, clipw, cliph);
        g.drawImage(img, x - clipx, y - clipy, 0);
        g.setClip(0, 0, 128, 160);
    }

    /**
     * 画出字符串;
     * */
    public static final void paintString(Graphics g, String str, int x, int y,
            int anchor)
    {
        g.drawSubstring(str, 0, str.length(), x, y, anchor);
    }
}

⌨️ 快捷键说明

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