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.GameEnvironmentInterface;
22  import erland.game.BlockContainerInterface;
23  
24  public class TileAdventureModelStandalone implements TileAdventureModelInterface {
25      /*** Handling of player */
26      private TileAdventurePlayer player;
27      /*** Model object */
28      private TileAdventureModel model;
29      /*** Game environment */
30      private GameEnvironmentInterface environment;
31      /*** Block container */
32      private IrregularBlockContainerInterface cont;
33      /*** Indicates if game is initialized */
34      private boolean bInitialized;
35      /*** Indicates if game is started */
36      private boolean bStarted;
37      /*** List of all player objects */
38      private GameObject[] playerObjects;
39  
40      public void startMoveLeft() {
41          player.startMoveLeft();
42      }
43  
44      public void startMoveRight() {
45          player.startMoveRight();
46      }
47  
48      public void startMoveUp() {
49          player.startMoveUp();
50      }
51  
52      public void startMoveDown() {
53          player.startMoveDown();
54      }
55  
56      public void stopMoveLeft() {
57          player.stopMoveLeft();
58      }
59  
60      public void stopMoveRight() {
61          player.stopMoveRight();
62      }
63  
64      public void stopMoveUp() {
65          player.stopMoveUp();
66      }
67  
68      public void stopMoveDown() {
69          player.stopMoveDown();
70      }
71  
72      public void jump() {
73          player.jump();
74      }
75  
76      public void update() {
77          if(isStarted()) {
78              player.update();
79              model.update();
80          }
81      }
82      private GameObject createPlayer() {
83          MovableObject obj = new LivingObject();
84          obj.init(environment);
85          obj.setContainer(cont);
86          String prefix = ((TileGameEnvironmentInterface)(environment.getCustomEnvironment())).getTileType();
87          obj.setAnimation(prefix+"ground.gif",new Animation(0,new int[] {2}));
88          return obj;
89      }
90      private GameObject[] createPlayers() {
91          return new GameObject[] {createPlayer()};
92      }
93      public void init(GameEnvironmentInterface environment, IrregularBlockContainerInterface cont) {
94          this.environment = environment;
95          this.cont = cont;
96  
97          model = new TileAdventureModel();
98          model.init(environment,cont);
99  
100         player = new TileAdventurePlayer(environment,0);
101         player.setActionHandler(model);
102         playerObjects = createPlayers();
103         player.setPlayerObject(playerObjects[0]);
104         model.initPlayers(playerObjects);
105 
106         bInitialized = true;
107     }
108     public boolean isInitialized() {
109         return bInitialized;
110     }
111 
112     public void start() {
113         if(!isStarted()) {
114             bStarted = true;
115         }
116     }
117 
118     public MapDrawInterface getMap() {
119         return model.getMap(playerObjects[0]);
120     }
121 
122     public boolean isEnd() {
123         return false;
124     }
125 
126     public boolean isGameOver() {
127         return false;
128     }
129 
130     public boolean isCompleted() {
131         return false;
132     }
133 
134     public boolean isStarted() {
135         return bStarted;
136     }
137     public boolean isMultiplayer() {
138         return false;
139     }
140     public String getInfoString() {
141         return "";
142     }
143     public void setCheatModeParameter(String parameter, String value) {
144         return;
145     }
146 
147     public int getNoOfHumanPlayers() {
148         return 1;
149     }
150 
151     public GameObject getPlayerObject() {
152         return player.getPlayerObject();
153     }
154 }