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  
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 }