View Javadoc

1   package erland.game.tetris;
2   /*
3    * Copyright (C) 2003 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.*;
22  import erland.game.component.EComponentMode;
23  import erland.util.*;
24  
25  import java.awt.*;
26  import java.applet.Applet;
27  
28  public class TetrisApplet extends Applet implements GamePanelHandlerApplicationInterface, Runnable {
29      protected Thread animator;
30  
31      public DisplayMode[] getDisplayModes() {
32          DisplayMode[] displayModes = new DisplayMode[] {
33              new DisplayMode(640,480,32,0),
34              new DisplayMode(640,480,16,0),
35              new DisplayMode(640,480,8,0)};
36          return displayModes;
37      }
38  
39      public void initGames(GamePanelHandlerInterface handler) {
40          handler.addPanel("Singleplayer","Starting the game",new TetrisMain(new TetrisModelStandalone()));
41          handler.addPanel("Multiplayer","Starting the game",new TetrisMain(new TetrisModelNetworked(getDocumentBase().getHost(),"player","player")));
42          handler.cheatWord("erland");
43      }
44  
45  
46      public void init() {
47      }
48  
49      public void start()
50      {
51          if(animator==null) {
52              animator= new Thread(this);
53              animator.start();
54          }
55      }
56      public void stop()
57      {
58          if((animator != null) && (animator.isAlive())) {
59              animator = null;
60          }
61      }
62      public void run() {
63          ParameterValueStorageExInterface storage = null;
64          String mayScript = getParameter("MAYSCRIPT");
65          if(mayScript!=null) {
66              storage = new ParameterStorageString(
67                      new CookieStorage(this,"tetris"),
68                      null);
69          }
70          ImageHandlerInterface imageHandler = new ImageHandlerForApplet(this,"images/tetris");
71          GamePanelHandlerForApplet handler = new GamePanelHandlerForApplet(this);
72          handler.setImageHandler(imageHandler);
73          handler.setStorage(storage);
74          EComponentMode.setAppletMode(true);
75          while(animator!=null) {
76              GamePanelHandler.run(this,handler);
77          }
78      }
79  }