001 package jagafa;
002
003 import jagafa.flags.TestingFlags;
004 import jagafa.scores.ScoreTable;
005 import jagafa.util.dump.Dump;
006 import jagafa.util.view.AbsConstr;
007 import jagafa.util.view.TimedDialog;
008 import jagafa.view.newui.RoundController2;
009 import jagafa.view.newui.TestingFlagsPanel;
010
011 import java.awt.BorderLayout;
012 import java.awt.Dimension;
013 import java.awt.event.ActionEvent;
014 import java.awt.event.ActionListener;
015 import java.util.Observable;
016 import java.util.Observer;
017
018 import javax.swing.JFrame;
019 import javax.swing.JInternalFrame;
020 import javax.swing.JMenu;
021 import javax.swing.JMenuBar;
022 import javax.swing.JMenuItem;
023 import javax.swing.JSeparator;
024 import javax.swing.Timer;
025
026 /**
027 * GameController skeleton
028 *
029 */
030 public class GameController implements Observer, ActionListener {
031 private ScoreTable scoreTable_;
032
033 private JFrame scoreTableFrame_;
034
035 private JFrame roundFrame_;
036
037 private JFrame ruleChoiceFrame_;
038
039 private RoundController2 roundController_;
040
041 private Timer nextRoundTimer_;
042
043 private JInternalFrame rcFrame;
044
045 public GameController() {
046 roundController_ = new RoundController2();
047
048 }
049
050 public void startGame(ScoreTable scoreTable) {
051 this.scoreTable_ = scoreTable;
052
053 startRoundController();
054
055 createRoundView();
056 createRuleChoiceView();
057
058 createScoreTableView();
059 this.roundController_.toggleNoify();
060 showHelp();
061 showDump();
062 showFlags();
063 }
064
065 private void createRoundView() {
066 roundFrame_ = new JFrame();
067 roundFrame_.setJMenuBar(getMenuBar());
068 roundFrame_.setLayout(new BorderLayout());
069 roundFrame_.getContentPane().add(this.roundController_.getRoundPanel(),
070 BorderLayout.CENTER);
071 roundFrame_.setVisible(true);
072 roundFrame_.pack();
073 roundFrame_.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
074 roundFrame_.setTitle("Jass by Matthias Amacher - (c) 2005");
075 //roundFrame_.setResizable(false);
076 roundFrame_.setLocation(200, 0);
077 this.roundController_.getRuleChoicePanel().setRoundUI(this.roundFrame_);
078
079 roundFrame_.validate();
080
081 /*
082 GraphicsEnvironment environment;
083 environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
084
085 GraphicsDevice device = environment.getDefaultScreenDevice();
086
087
088 if (device.isFullScreenSupported()) {
089 device.setFullScreenWindow(roundFrame_);
090 } else {
091 System.err.println("Fullscreen mode not supported!");
092 }
093 */
094 }
095
096 private JMenuBar getMenuBar() {
097 JMenuBar menubar = new JMenuBar();
098 JMenu menu = new JMenu("Game");
099
100 JMenuItem dump = new JMenuItem("Show Dumper");
101 JMenuItem flags = new JMenuItem("Show Control-Flags");
102 JMenuItem help = new JMenuItem("Show Help");
103 JMenuItem exit = new JMenuItem("Exit");
104
105 help.addActionListener(this);
106 exit.addActionListener(this);
107 flags.addActionListener(this);
108 dump.addActionListener(this);
109
110 menu.add(dump);
111 menu.add(flags);
112 menu.add(new JSeparator());
113 menu.add(help);
114 menu.add(new JSeparator());
115 menu.add(exit);
116
117 menubar.add(menu);
118
119 return menubar;
120 }
121
122 private void createRuleChoiceView() {
123 /* rcFrame = new JInternalFrame();
124 rcFrame.add(this.roundController_.getRuleChoicePanel());
125 //rcFrame.setUndecorated(true);
126 rcFrame.setVisible(true);
127 rcFrame.pack();
128 //rcFrame.setAlwaysOnTop(true);
129 rcFrame.setTitle("Rule Choice");
130 rcFrame.setLocation(560, 190);
131 rcFrame.setResizable(false);
132 rcFrame.setLocation(560 + this.roundFrame_.getX(), 150 + this.roundFrame_.getY());
133 */
134 AbsConstr abs = new AbsConstr(0,0,130,200);
135 AbsConstr abs2 = new AbsConstr(0,200,130,100);
136
137 this.roundController_.getRoundPanel().add(this.roundController_.getRuleChoicePanel(),abs);
138 this.roundController_.getRoundPanel().add(this.roundController_.getSTPanel(),abs2);
139 this.roundController_.getRoundPanel().validate();
140 //this.roundFrame_.getContentPane().add(this.roundController_.getRuleChoicePanel(),abs);
141 }
142
143 private void createScoreTableView() {
144 /*scoreTableFrame_ = new JFrame();
145 scoreTableFrame_.setUndecorated(true);
146 scoreTableFrame_.add(this.roundController_.getSTPanel());
147 scoreTableFrame_.setVisible(true);
148 scoreTableFrame_.pack();
149 scoreTableFrame_.setAlwaysOnTop(true);
150 scoreTableFrame_.setTitle("Score Table for SCHIEBER");
151 scoreTableFrame_.setResizable(false);
152 scoreTableFrame_.setEnabled(false);
153 scoreTableFrame_.setLocation(560, 390);
154 scoreTableFrame_.setSize(this.rcFrame.getWidth(), scoreTableFrame_.getHeight());
155 */
156 }
157
158 private boolean isGameOver() {
159 return this.scoreTable_.isGameOver();
160 }
161
162 private void startRoundController() {
163 this.roundController_.startRound(this.scoreTable_);
164 this.roundController_.addObserver(this);
165 }
166
167 public void update(Observable arg0, Object arg1) {
168 /*rcFrame.setLocation(560 + this.roundFrame_.getX(), 190 + this.roundFrame_.getY());
169 scoreTableFrame_.setLocation(560 + this.roundFrame_.getX(),
170 390 + this.roundFrame_.getY());
171 rcFrame.validate();
172 scoreTableFrame_.validate();*/
173 if (this.isGameOver()) {
174 new TimedDialog("Game is over!\n" + this.scoreTable_.toString(),
175 this.roundFrame_.getRootPane(), 5000);
176 }
177 }
178
179 public void actionPerformed(ActionEvent arg0) {
180 String command = arg0.getActionCommand();
181
182 if (command.equals("Show Help")) {
183 showHelp();
184 } else if (command.equals("Exit")) {
185 Runtime.getRuntime().exit(0);
186 } else if (command.equals("Show Dumper")) {
187 this.toggleDump();
188 } else if (command.equals("Show Control-Flags")) {
189 this.toggleFlags();
190 }
191
192 }
193
194 private void toggleDump() {
195 if (this.dumpFrame.isVisible()) {
196 this.dumpFrame.setVisible(false);
197 } else {
198 this.dumpFrame.setVisible(true);
199 }
200 }
201 private void toggleFlags() {
202 if (this.flagFrame.isVisible()) {
203 this.flagFrame.setVisible(false);
204 } else {
205 this.flagFrame.setVisible(true);
206 }
207 }
208
209 private void showHelp() {
210 String help1 = "1) To start the game, select a Trump and press the\n'Set Rule' button";
211 String help2 = "\n2) If you want to 'schieben' then press the 'Hand choice over' button";
212 String help3 = "\n3) If one round is over press 'Deal' and the AI will choose a RuleSet";
213 String help4 = "\n4) The current Rule Set will be displayed on the Rule Choice panel on the left";
214 String help5 = "\n\n5) The small panel on the left displays the current score of both teams.\n\tTeam1 is"
215 + " are the Players on the top and bottom.\n\tTeam2 are the Players on the left and right.";
216 new TimedDialog(help1 + help2 + help3 + help4+help5, roundFrame_.getRootPane(), 8000);
217
218 }
219
220 private void showDump() {
221 TestingFlags.redirectSystemOut_ = true;
222 TestingFlags.ruleSetChoiceDump_ = true;
223 Dump dump = new Dump();
224 dumpFrame = new JFrame();
225 dumpFrame.add(Dump.getDumpPanel());
226 dumpFrame.setUndecorated(true);
227 dumpFrame.setVisible(false);
228
229 dumpFrame.setPreferredSize(new Dimension(200, 300));
230 dumpFrame.pack();
231 }
232
233 private JFrame dumpFrame;
234
235 private JFrame flagFrame;
236
237 private void showFlags() {
238
239 flagFrame = new JFrame();
240 flagFrame.add(new TestingFlagsPanel());
241 flagFrame.setUndecorated(true);
242 flagFrame.setVisible(false);
243
244 flagFrame.setPreferredSize(new Dimension(200, 300));
245 flagFrame.setLocation(0, 300);
246 flagFrame.pack();
247 }
248 }