1 package erland.game.tileadventure;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }