View Javadoc

1   package erland.game.tileadventure;
2   /*
3    * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   *
19   */
20  
21  import erland.game.GamePanelHandlerInterface;
22  import erland.game.GamePanelHandlerForApplet;
23  import erland.game.GamePanelHandler;
24  import erland.game.GamePanelHandlerApplicationInterface;
25  import erland.game.tileadventure.isodiamond.IsoDiamondBlockContainerData;
26  import erland.game.tileadventure.isodiamond.IsoDiamondDrawMap;
27  import erland.game.tileadventure.rect.RectBlockContainerData;
28  import erland.game.tileadventure.rect.RectDrawMap;
29  import erland.game.tileadventure.rect.RectEnvironment;
30  import erland.game.component.EComponentMode;
31  import erland.util.*;
32  
33  import java.awt.*;
34  import java.applet.Applet;
35  
36  /***
37   * This class implements the applet version of the game
38   */
39  public class TileAdventureApplet extends Applet implements GamePanelHandlerApplicationInterface, Runnable {
40      /*** Main thread in the applet */
41      protected Thread animator;
42  
43      public DisplayMode[] getDisplayModes() {
44          DisplayMode[] displayModes = new DisplayMode[] {
45              new DisplayMode(640,480,32,0),
46              new DisplayMode(640,480,16,0),
47              new DisplayMode(640,480,8,0)};
48          return displayModes;
49      }
50  
51      public void initGames(GamePanelHandlerInterface handler) {
52          handler.addPanel("Game","Starting the game",new TileAdventureMain(new TileAdventureModelStandalone()));
53          handler.cheatWord("erland");
54      }
55  
56      public void start()
57      {
58          if(animator==null) {
59              animator= new Thread(this);
60              animator.start();
61          }
62      }
63  
64      public void stop()
65      {
66          if((animator != null) && (animator.isAlive())) {
67              animator = null;
68          }
69      }
70  
71      public void run() {
72          ParameterValueStorageExInterface storage = null;
73          String mayScript = getParameter("MAYSCRIPT");
74          if(mayScript!=null) {
75              storage = new ParameterStorageString(
76                      new CookieStorage(this,"tileadventure"),
77                      new JarFileStorage("TileAdventure.xml"),
78                      "tileadventure");
79          }
80          ImageHandlerInterface imageHandler = new ImageHandlerForApplet(this,"images");
81          GamePanelHandlerForApplet handler = new GamePanelHandlerForApplet(this);
82          handler.setImageHandler(imageHandler);
83          handler.setStorage(storage);
84          handler.setCustomEnvironment(new RectEnvironment(handler));
85          EComponentMode.setAppletMode(true);
86          while(animator!=null) {
87              GamePanelHandler.run(this,handler);
88          }
89      }
90  }