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

📄 utility.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.util;

import java.lang.reflect.Array;
import java.util.Random;

public class Utility
{

    private static final Random a = new Random();

    public static Object expand(Object obj, int i, boolean flag)
    {
        int j = Array.getLength(obj);
        Object obj1 = Array.newInstance(obj.getClass().getComponentType(), j + i);
        System.arraycopy(obj, 0, obj1, flag ? 0 : i, j);
        return obj1;
    }

    public static Object expand(Object obj, int i)
    {
        return expand(obj, i, true);
    }

    public static Object expand(Object obj, int i, boolean flag, Class class1)
    {
        if(obj == null)
            return Array.newInstance(class1, 1);
        else
            return expand(obj, i, flag);
    }

    public static Object cut(Object obj, int i)
    {
        int j;
        if((j = Array.getLength(obj)) == 1)
            return Array.newInstance(obj.getClass().getComponentType(), 0);
        int k;
        if((k = j - i - 1) > 0)
            System.arraycopy(obj, i + 1, obj, i, k);
        j--;
        Object obj1 = Array.newInstance(obj.getClass().getComponentType(), j);
        System.arraycopy(obj, 0, obj1, 0, j);
        return obj1;
    }

    public static void mixElements(Object obj)
    {
        int i = Array.getLength(obj);
        for(int k = 0; k < i; k++)
        {
            int j = getRandom(k, i - 1);
            Object obj1 = Array.get(obj, j);
            Array.set(obj, j, Array.get(obj, k));
            Array.set(obj, k, obj1);
        }

    }

    public static Random getRandomObject()
    {
        return a;
    }

    public static int getRandom(int i, int j)
    {
        return i + a.nextInt((j - i) + 1);
    }

    public static String[] compactStrings(String as[])
    {
        String as1[] = new String[as.length];
        int i = 0;
        for(int j = 0; j < as.length; j++)
            i += as[j].length();

        char ac[] = new char[i];
        i = 0;
        for(int k = 0; k < as.length; k++)
        {
            as[k].getChars(0, as[k].length(), ac, i);
            i += as[k].length();
        }

        String s = new String(ac);
        i = 0;
        for(int l = 0; l < as.length; l++)
            as1[l] = s.substring(i, i += as[l].length());

        return as1;
    }

}

⌨️ 快捷键说明

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