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.GamePanelHandlerInterface;
22 import erland.game.GamePanelHandler;
23 import erland.game.GamePanelHandlerForApplication;
24 import erland.game.GamePanelHandlerApplicationInterface;
25 import erland.util.*;
26
27 import javax.swing.*;
28 import java.awt.*;
29
30 public class Tetris extends GamePanelHandlerForApplication implements GamePanelHandlerApplicationInterface {
31 private ParameterValueStorageExInterface storage;
32 private FileStorage file;
33 private ImageHandlerInterface images;
34 private String hostname;
35 private String name;
36 private TetrisMain panel;
37 private boolean bMultiplayer;
38
39 public static void main(String[] args) {
40 Tetris game;
41 if(args.length>1) {
42 game = new Tetris(args[1],args[0]);
43 }else if(args.length==1) {
44 game = new Tetris("erland.homeip.net",args[0]);
45 }else {
46 game = new Tetris("erland.homeip.net","player");
47 }
48 GamePanelHandler.run(game,game);
49 System.exit(-1);
50 }
51
52 public Tetris(String hostname,String name) {
53 this.hostname = hostname;
54 this.name = name;
55 }
56 public void askUserForOptions() {
57 Object[] possibleValues = { "Standalone single player", "Networked multiplayer"};
58 int selectedValue = JOptionPane.showOptionDialog(null,
59 "Choose game mode", "Game mode",
60 JOptionPane.DEFAULT_OPTION,
61 JOptionPane.INFORMATION_MESSAGE, null,
62 possibleValues, possibleValues[0]);
63 if(selectedValue==0) {
64 bMultiplayer = false;
65 }else {
66 bMultiplayer = true;
67 }
68 if(bMultiplayer) {
69 String hostname = JOptionPane.showInputDialog("Please enter hostname",this.hostname);
70 if(hostname!=null) {
71 this.hostname=hostname;
72 }
73 String name = JOptionPane.showInputDialog("Please enter your name",this.name);
74 if(name!=null) {
75 this.name = name;
76 }
77 }
78 }
79 public DisplayMode[] getDisplayModes() {
80 DisplayMode[] displayModes = new DisplayMode[] {
81 new DisplayMode(640,480,32,0),
82 new DisplayMode(640,480,16,0),
83 new DisplayMode(640,480,8,0)};
84 return displayModes;
85 }
86
87 public void initGames(GamePanelHandlerInterface handler) {
88 if(bMultiplayer) {
89 panel = new TetrisMain(new TetrisModelNetworked(hostname,name,name));
90 }else {
91 panel = new TetrisMain(new TetrisModelStandalone());
92 }
93 handler.addPanel("Game","Starting the game",panel);
94 handler.cheatWord("erland");
95 }
96
97 public ImageHandlerInterface getImageHandler() {
98 if(images==null) {
99 images = new ImageHandlerForApplicationJarFile(getScreenHandler().getContainer(),"images/tetris");
100 }
101 return images;
102 }
103
104 public ParameterValueStorageExInterface getStorage() {
105 if(storage==null) {
106 file = new FileStorage("tetris.xml");
107 storage = new ParameterStorageString(file,null,"tetris");
108 }
109 return storage;
110 }
111
112 }