1 package erland.game.tetris;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import erland.game.*;
22
23 public class TetrisModelStandalone implements TetrisModelInterface {
24 TetrisPlayer model;
25 private boolean bStarted;
26 GameEnvironmentInterface environment;
27 HighScore highScore;
28
29 public BlockContainerData getMainContainer() {
30 return model.getMainContainer();
31 }
32
33 public Block getNextBlock() {
34 return model.getNextBlock();
35 }
36
37 public BlockContainerData getOpponentMainContainer() {
38 return null;
39 }
40
41 public boolean isEnd() {
42 return model.isGameOver();
43 }
44
45 public boolean isStarted() {
46 return bStarted;
47 }
48
49 public boolean isCompleted() {
50 return model.isCompleted();
51 }
52
53 public String getHighScore() {
54 return model.getNumberString(6,highScore.get());
55 }
56
57 public String getScore() {
58 return model.getNumberString(6,model.getScore());
59 }
60
61 public String getOpponentScore() {
62 return null;
63 }
64
65 public String getLevel() {
66 return model.getNumberString(2,model.getLevel());
67 }
68
69 public String getOpponentLevel() {
70 return null;
71 }
72
73 public boolean isMultiplayer() {
74 return false;
75 }
76
77 public boolean isOpponentConnected() {
78 return false;
79 }
80
81 public void init(GameEnvironmentInterface environment) {
82 this.environment = environment;
83 GameEnvironmentCustomizable serverEnvironment = new GameEnvironmentCustomizable(environment);
84 highScore = new HighScore(environment.getStorage());
85 highScore.load();
86 serverEnvironment.setHighScore(highScore);
87 model = new TetrisPlayer(serverEnvironment);
88 bStarted = false;
89 }
90
91 public void moveLeft() {
92 model.moveLeft();
93 }
94
95 public void moveRight() {
96 model.moveRight();
97 }
98
99 public void rotate() {
100 model.rotateRight();
101 }
102
103 public void moveDown() {
104 model.moveDownBottom();
105 }
106
107 public void startGame() {
108 bStarted = true;
109 model.startNewGame();
110 }
111
112 public void update() {
113 if(bStarted) {
114 model.update();
115 if(isEnd()) {
116 bStarted = false;
117 }
118 }
119 }
120 }