// This Class is (c)opyright 1999 by Geoff Knagge. It may be freely used // for any non-commercial purpose on the following conditions: // 1. You indemnify the copyright holder of all possible liability // resulting from its use. // 2. You provide a link back to the source of this file, that is // http://browse.to/gogogeoff // // Use of this class shows your agreement to the above. import java.applet.*; import java.awt.*; import java.awt.event.*; import TrueFalse; import DropList; import PNZColours; public class MastermindApplet extends Applet implements ActionListener { // This class is the interface to the game. It lets you select the // playing conditions and then creates an instance of the game... TrueFalse unique; // do all pieces have to be different? TrueFalse holes; // do all positions have to be filled? DropList gameHeight; // number of rows in the history list DropList numColours; // number of colours to choose from DropList maxMoves; // amount of moves before you die. // 0=unlimited DropList gameWidth; // How many pieces do you need to guess Frame dummy; // Dialogs must be tied to a Frame... since // this is an applet, we use a dummy Frame public void actionPerformed(ActionEvent e) { // must be present in any class which implements an ActionListener // In this case, it is tied to the button, and is called whenever // it is pressed. if ((numColours.getValue()< gameWidth.getValue()) && (unique.getValue())) MessageBox.popUp(dummy,"If the colours are to be"+ " unique, there must be more colours"+ " than pieces!", 500,"Error in your preferences!"); else PNZColours.playGame(dummy, gameWidth.getValue()+1, gameHeight.getValue()+1, numColours.getValue()+1, holes.getValue(), (! unique.getValue()), maxMoves.getValue()); } /////////////// The constructor. In applets it's called init() public void init() { dummy = new Frame(); setLayout(new GridLayout(8,1)); unique = new TrueFalse("Each piece must be a different colour",true); holes = new TrueFalse("Some pieces may be empty spaces (grey)",false); gameHeight = new DropList("Number of previous guesses to display",null,1,20,9); maxMoves = new DropList("Maximum number of guesses","Unlimited",1,100,10); gameWidth = new DropList("Number of pieces to guess",null,1,9,3); numColours = new DropList("Number of colours to choose from",null,1,9,5); Button playNow = new Button("Play using these options"); setBackground(new Color(192,220,192)); add(gameWidth); add(maxMoves); add(gameHeight); add(numColours); add(unique); add(holes); add(playNow); playNow.addActionListener(this); } }