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

📄 gameloader.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;

import com.golden.gamedev.engine.BaseGraphics;
import com.golden.gamedev.engine.graphics.AppletMode;
import com.golden.gamedev.engine.graphics.FullScreenMode;
import com.golden.gamedev.engine.graphics.WindowExitListener;
import com.golden.gamedev.engine.graphics.WindowedMode;
import com.golden.gamedev.funbox.ErrorNotificationDialog;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.PrintStream;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;

// Referenced classes of package com.golden.gamedev:
//            Game

public class GameLoader extends AppletMode
    implements WindowListener, Runnable
{

    public static final String JAVA_VERSION;
    public String MINIMUM_VERSION;
    private boolean c;
    private String d[] = {
        "Loading Game, please wait a moment"
    };
    protected BaseGraphics gfx;
    protected Game game;

    public GameLoader()
    {
        MINIMUM_VERSION = "1.4";
        c = true;
    }

    public void start()
    {
        if(!c)
            break MISSING_BLOCK_LABEL_267;
        if(gfx != null)
        {
            if(game != null)
                game.start();
            return;
        }
        String s;
        try
        {
            if((s = getParameter("MINIMUM_VERSION")) != null)
                MINIMUM_VERSION = s;
        }
        catch(Exception _ex)
        {
            JOptionPane.showMessageDialog(null, "ERROR: GameLoader.setup(Game, Dimension, Fullscreen); need to be called\nbefore calling GameLoader.start();", "Game Initialization", 0);
            System.exit(0);
        }
        if(!validJavaVersion())
        {
            d = (new String[] {
                "Sorry, this game requires Java " + MINIMUM_VERSION + "++", "Your machine only has Java " + JAVA_VERSION + " installed", "", "Install the latest Java Runtime Edition (JRE)", "from http://www.java.com"
            });
            return;
        }
        if(game != null)
            break MISSING_BLOCK_LABEL_205;
        game = createAppletGame();
        if(game == null)
        {
            JOptionPane.showMessageDialog(null, "FATAL ERROR: Game main-class is not specified!\nPlease subclass GameLoader class and override\ncreateAppletGame() method to return your game main class.\n\nFor example :\npublic class YourGameApplet extends GameLoader {\n   protected Game createAppletGame() {\n      return new YourGame();\n   }\n}", "Game Initialization", 0);
            c = false;
            return;
        }
        gfx = this;
        game.bsGraphics = gfx;
        super.start();
        (new Thread(this)).start();
        return;
        Throwable throwable;
        throwable;
        d = (new String[] {
            "UNRECOVERABLE ERROR", "PLEASE CONTACT THE GAME AUTHOR"
        });
        removeAll();
        setIgnoreRepaint(false);
        new ErrorNotificationDialog(throwable, this, getClass().getName(), null);
    }

    public void stop()
    {
        if(game != null)
            game.stop();
    }

    public final void run()
    {
        if(game != null)
            game.start();
    }

    protected Game createAppletGame()
    {
        String s;
        if((s = getParameter("GAME")) == null)
            break MISSING_BLOCK_LABEL_45;
        if(s.endsWith(".class"))
            s = s.substring(0, s.length() - 6);
        return (Game)Class.forName(s).newInstance();
        JVM INSTR pop ;
        return null;
    }

    public void setup(Game game1, Dimension dimension, boolean flag, boolean flag1)
    {
        Object obj;
        if(!validJavaVersion())
        {
            JOptionPane.showMessageDialog(null, "Sorry, this game requires Java " + MINIMUM_VERSION + "++ installed\n" + "Your machine only has Java " + JAVA_VERSION + " installed\n\n" + "Please install the latest Java Runtime Edition (JRE)\n" + "from http://www.java.com", "Game Initialization", 0);
            System.exit(-1);
        }
        if(!flag)
            break MISSING_BLOCK_LABEL_166;
        obj = null;
        ((FullScreenMode) (obj = new FullScreenMode(dimension, flag1))).getFrame().removeWindowListener(WindowExitListener.getInstance());
        ((FullScreenMode) (obj)).getFrame().addWindowListener(this);
        gfx = ((BaseGraphics) (obj));
        break MISSING_BLOCK_LABEL_166;
        JVM INSTR dup ;
        Throwable throwable;
        throwable;
        printStackTrace();
        JOptionPane.showMessageDialog(null, "ERROR: Entering FullScreen Mode\nCaused by: " + throwable.toString(), "Graphics Engine Initialization", 0);
        flag = false;
        if(obj != null)
            ((FullScreenMode) (obj)).cleanup();
        if(!flag)
        {
            ((WindowedMode) (obj = new WindowedMode(dimension, flag1))).getFrame().removeWindowListener(WindowExitListener.getInstance());
            ((WindowedMode) (obj)).getFrame().addWindowListener(this);
            gfx = ((BaseGraphics) (obj));
        }
        game = game1;
        game.bsGraphics = gfx;
        return;
        JVM INSTR dup ;
        obj;
        printStackTrace();
        JOptionPane.showMessageDialog(null, "Fatal Error: Failed to initialize game environment!\nCaused by:\n       " + obj + "\n" + "Please send above exception to the Game Author.\n", "Game Initialization", 0);
        System.exit(-1);
        return;
    }

    public void setup(Game game1, Dimension dimension, boolean flag)
    {
        setup(game1, dimension, flag, true);
    }

    public Game getGame()
    {
        return game;
    }

    public void paint(Graphics g)
    {
        int i = getSize().width;
        int j = getSize().height;
        g.setColor(new Color(255, 0, 0));
        g.fillRect(0, 0, i, j);
        g.setFont(new Font("Monospaced", 0, 16));
        FontMetrics fontmetrics = g.getFontMetrics();
        int l = j / 2 - (fontmetrics.getHeight() + 10) * (d.length / 2);
        g.setColor(new Color(0, 0, 0));
        try
        {
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }
        catch(Exception _ex) { }
        for(int i1 = 0; i1 < d.length; i1++)
        {
            g.drawString(d[i1], i / 2 - fontmetrics.stringWidth(d[i1]) / 2, l);
            l += fontmetrics.getHeight() + 10;
        }

    }

    protected boolean validJavaVersion()
    {
        c = k();
        return c;
    }

    private boolean k()
    {
        StringTokenizer stringtokenizer = new StringTokenizer(JAVA_VERSION, ".");
        StringTokenizer stringtokenizer1 = new StringTokenizer(MINIMUM_VERSION, ".");
        int i = stringtokenizer.countTokens() <= stringtokenizer1.countTokens() ? stringtokenizer1.countTokens() : stringtokenizer.countTokens();
        String s = "";
        String s1 = "";
        String s2 = "";
        for(int j = 0; j < i; j++)
        {
            char c1;
            try
            {
                c1 = stringtokenizer.nextToken().charAt(0);
            }
            catch(Exception _ex)
            {
                c1 = '0';
            }
            s = s + c1;
            try
            {
                c1 = stringtokenizer1.nextToken().charAt(0);
                if(s2.length() > 0)
                    s2 = s2 + ".";
                s2 = s2 + c1;
            }
            catch(Exception _ex)
            {
                c1 = '0';
            }
            s1 = s1 + c1;
        }

        int l = Integer.parseInt(s);
        int i1 = Integer.parseInt(s1);
        MINIMUM_VERSION = s2;
        if(l >= i1)
            return true;
        return false;
        Exception exception;
        exception;
        System.err.println("WARNING: MINIMUM_VERSION [" + MINIMUM_VERSION + "] and/or " + "JAVA_VERSION [" + JAVA_VERSION + "] value is not valid!");
        return true;
    }

    public String getGraphicsDescription()
    {
        if(gfx != null)
            return gfx.getGraphicsDescription();
        return super.getGraphicsDescription();
        JVM INSTR pop ;
        if(gfx != null)
            return gfx.getClass().toString();
        else
            return getClass().toString();
    }

    public void windowClosing(WindowEvent windowevent)
    {
        if(game != null)
            game.finish();
    }

    public void windowOpened(WindowEvent windowevent)
    {
    }

    public void windowClosed(WindowEvent windowevent)
    {
    }

    public void windowIconified(WindowEvent windowevent)
    {
    }

    public void windowDeiconified(WindowEvent windowevent)
    {
    }

    public void windowActivated(WindowEvent windowevent)
    {
    }

    public void windowDeactivated(WindowEvent windowevent)
    {
    }

    static 
    {
        String s = "1.4.1";
        try
        {
            s = System.getProperty("java.version");
        }
        catch(Exception _ex) { }
        JAVA_VERSION = s;
    }
}

⌨️ 快捷键说明

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