1 /*
2  *  CVS: $Id: JZuulApplet.java,v 1.1 2004/07/21 11:13:46 marcus Exp $
3  * 
4  *  This file is part of JZuul.
5  *
6  *  JZuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  JZuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with Zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by marcus, leh
21 *  Initially based on an example by Michael Kolling and David J. Barnes
22 * 
23 */
24
25package org.jzuul.tools;
26
27import java.util.List;
28import java.util.Vector;
29
30import javax.swing.JApplet;
31import javax.swing.RootPaneContainer;
32
33import org.jzuul.engine.CommandList;
34import org.jzuul.engine.Engine;
35import org.jzuul.engine.gui.GuiInterface;
36import org.jzuul.engine.gui.SwingGui;
37import org.jzuul.engine.gui.TextUi;
38
39/**
40 * Starterklasse für das supertolle ZuulSpiel
41*
42* 
43* @version $Revision: 1.1 $
44*/
45
46public class JZuulApplet extends JApplet implements Runnable {
47    boolean init;
48    Engine engine;
49    JZuulApplet game;
50    Thread runner;
51    List cmdargs;
52    
53    public static String gamefile, demo;
54    
55
56    public JZuulApplet() {
57        
58    }
59    
60    public JZuulApplet(List cmdargs) {
61        this.cmdargs = cmdargs;
62    }
63    
64    private void initEngine(RootPaneContainer root) {
65
66        GuiInterface gui = null;
67        if (cmdargs.contains("text")) {
68            gui = new TextUi();
69        } else {
70            gui = new SwingGui(root);
71        }
72        this.engine = new Engine(JZuulApplet.gamefile, CommandList.defaultList(), gui);
73    }
74
75    private void runGame() {
76
77        boolean withPlayerName = false;
78
79        if (!this.cmdargs.isEmpty()) {
80            if (cmdargs.contains("demo") && (JZuulApplet.demo != null)) {
81                Engine.debug("Doing a history run", 1);
82                engine.runHistory(JZuulApplet.demo);
83                Engine.debug("Finished History run", 1);
84            }
85            if (cmdargs.contains("name")) {
86                withPlayerName = true;
87            }
88
89        }
90
91        engine.run(withPlayerName);
92    }
93
94    // to run as Program
95    public static void main(String[] args) {
96        Vector v = new Vector(args.length);
97        for (int i = 0; i < args.length; i++) {
98            v.add(args[i].replaceFirst("-+", ""));
99        }
00        JZuulApplet game = new JZuulApplet(v);
01        
02        game.initEngine(null);
03        game.runGame();
04    }
05
06    // Applet part:
07    public void init() {
08        runner = new Thread(this);
09        Vector v = new Vector();
10        if (this.getParameter("demo") != null) {
11            v.add("demo");
12        }
13
14        game = new JZuulApplet(v);
15        game.init = true;
16        game.initEngine(this);
17    }
18
19    public void start() {
20        Engine.debug("Now calling run\n", 1);
21        runner.start();
22        Engine.debug("JApplet start returned", 1);
23    }
24
25    public void run() {
26        game.runGame();
27    }
28
29    public boolean isActive() {
30        return this.init;
31    }
32
33    public String getAppletInfo() {
34        return "This is Zuul, $Revision: 1.1 $";
35    }
36
37    public void stop() {
38        Engine.exit(0);
39        engine = null;
40        JZuulApplet.gamefile = null;
41        JZuulApplet.demo = null;
42    }
43    
44}
45