import java.awt.*; import java.awt.event.*; import GUIBoard; import OptionsWindow; /** * Pseudocode for the Othello GUI * @author Greg Fuller * @author Ellen Gallagher * @author Jill Lofchie * @author Dave Wingate * March 1, 2000 */ public class OthelloGUIv1 extends WindowAdapter implements ActionListener { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The frame that will display the board and important information. */ protected Frame main; /** The frame that will display any help information. */ protected static Frame helptext; /** The button that you press to end the program. */ protected Button quit; /** The button that you press to get help */ protected Button help; /** The button that you press to undo a move */ protected Button undo; /** The button that you press to show what the last move was */ protected Button showlastmove; /** Options Button */ protected Button options; /** Label for displaying the name of the game */ protected Label grinnello; /** display info to the player */ protected TextField textout; /** All the buttons */ protected Panel buttons; /** Contains the help dialog */ protected static Label helpoptions; /** Field for board from GUIBoard class */ protected GUIBoard brd; /** field for the Boardtype that will be associated with this game * (the constructor for this class should have a rules field) */ // protected Board board /** there will be a bunch of other fields and stuff, see the picture */ /** There will also need to be some totally seperate windows that are * launched from the beginning and will prompt the user for the variants * on the game rules, number of players, etc. We didn't write this yet * because we don't know what the different options will be yet * We will, however, need constructors for all of these options so that we * can initialize them in the correct way once we know how the user wants * them. */ // +----------------+----------------------------------------- // | Constructors | // +----------------+ /** * The main window that the game will take place in. * */ protected OthelloGUIv1() { // create the pretty new window with an appropriate layout. main = new Frame("Grinnello!"); main.setLayout(new BorderLayout(1,1)); main.addWindowListener(this); // create the informational texts grinnello = new Label("Grinnello!"); textout = new TextField(" "); // create the buttons buttons = new Panel(new GridLayout(5,1)); quit = new Button("Quit"); help = new Button("Help"); undo = new Button("Undo"); options = new Button("Options"); showlastmove = new Button("Show Last Move"); GUIBoard brd = new GUIBoard(4,4); // add actionlisteners to the buttons quit.addActionListener(this); help.addActionListener(this); undo.addActionListener(this); options.addActionListener(this); showlastmove.addActionListener(this); // add everything into the window main.add("North",grinnello); main.add("South",textout); buttons.add(showlastmove); buttons.add(options); buttons.add(undo); buttons.add(help); buttons.add(quit); main.add("East",buttons); main.add("Center",brd); main.pack(); main.show(); } // main() /** help popup window */ protected void HelpText() { helptext = new Frame("Game options"); helptext.setLayout(new FlowLayout()); helptext.addWindowListener(this); helpoptions = new Label("There is no game yet, so I can't help you! I recommend you hit 'Quit'"); helptext.add(helpoptions); helptext.pack(); helptext.show(); } // helpText() // +----------------+----------------------------------------- // | Event Handlers | // +----------------+ /** * We figured the action listeners for all the buttons and objects we * have in our main window are the most important things, and all the * things that require calling other peoples' methods. */ public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); // Action Listener for the quit button will call: if (command.equals("Quit")) { main.dispose(); System.exit(0); } // if quit // Action Listener for the help button will call: else if (command.equals("Help")) { // helptext is a window with the rules and suggestions for how to play // it may need to be different when playing under different games. HelpText(); } // if help // Action Listener for the undo button will call: else if (command.equals("Undo")) { // We need the board people to write a method that undoes the last move or, // in the case of a computer/human game, the last two moves, if the // computer has gone. // board.undoLastMove(); // GUIboard.update(); } // if undo // Action Listener for the options button: else if (command.equals("Options")) { // opens the window with the options in it new OptionsWindow(); } // if options // Action Listener for the Show Last Move button: else if (command.equals("Show Last Move")) { // Highlights the places on the board that were recently flipped // The board class will need a LastMove() method that returns an // array of the pieces that were added and changed. // GUIboard.highlight(board.LastMove()); } /** Action Listener for the GUI board */ /** STUBSTUBSTUBSTUB { // The rules class tells us if the place played is legal. if !(rules.legalMove(x,y,player.currentColor())) // if the move was not legal { out.setText(textobject.illegalMove()) } // if else { // the move was legal // GUIboard.update takes an array of coordinates and concult the board // object for information about the pieces at each of those // coordinates and make the appropriate changes on the GUIboard GUIboard.update( board.move(x,y,player.currentColor()) ); // report to board the creation of a new piece object, then use some // method of the rules class to decide which pieces to flip subsequently // additionally, this method should return an array of coordinates // of the pieces that have been flipped player.nextPlayer(); // this should start with an index = to the number of player,check to // see that this next player has a legal move, if not, decrease the index // by one and check for the next possible player. if the index reaches // zero, then the game is over out.setText(textobject.promptPlayer()); } // else */ // STUBSTUBSTUBSTUB // } // Action Listener for the GUI Board } // no more action listeners! public void windowClosing(WindowEvent event) { main.dispose(); System.exit(0); } // windowClosing(WindowEvent) } // class OthelloGUIv1