Commit 0a36a8ee authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Cleaning up.

parent c9b092e2
Loading
Loading
Loading
Loading
+34 −25
Original line number Diff line number Diff line
package edu.bu.ec504.spr19.sameGameTris;

/* An implementation of the "samegnome" game, possibly with a computer-aided solver.
   Written by Prof. Ari Trachtenberg for EC504 at Boston University.
*/

package edu.bu.ec504.spr24.sameGameTris;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
@@ -29,14 +24,18 @@ import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;

import edu.bu.ec504.spr19.Brain.smarterBrain;
import edu.bu.ec504.spr19.highScores.highScore;
import edu.bu.ec504.spr19.Brain.Brain;
import edu.bu.ec504.spr19.Brain.lazyBrain;
import edu.bu.ec504.spr19.Brain.simpleBrain;
import edu.bu.ec504.spr24.Brain.SmarterBrain;
import edu.bu.ec504.spr24.highScores.highScore;
import edu.bu.ec504.spr24.Brain.Brain;
import edu.bu.ec504.spr24.Brain.LazyBrain;
import edu.bu.ec504.spr24.Brain.SimpleBrain;

import static java.util.concurrent.Executors.newScheduledThreadPool;

/**
 * A Singleton Graphical User Interface for the game.
 * @author Ari Trachtenberg
 */
class sge extends GUI implements ActionListener, ItemListener {

    // CONSTANTS
@@ -56,8 +55,11 @@ class sge extends GUI implements ActionListener, ItemListener {
    private SelfAwareCircle[][] circles;
    private String highScoreName = null;              // the name to use for the high score
    static final Random randGen = new Random();       // package-private random number generator used for the entire package (i.e., repeatedly seeding with the same value produces the same randomness).
	private int numClicks = 1;	                      // Must be a positive integer; counts the number of clicks on circles since the last time the board was reset.

	static private int numClicks = 1;	                      // Must be a positive integer; counts the number of clicks on circles since the last time the board was reset.
  /**
   * An instane of the SGE GUI.
   */
  private static sge Instance = null;

	// ... GUI elements
    private JPanel circlePanel; // the panel containing the circles
@@ -94,12 +96,12 @@ class sge extends GUI implements ActionListener, ItemListener {
			try {
				int randColumn = randGen.nextInt(width);
				SelfAwareCircle myCircle = circles[randColumn][0];
				if (myCircle.getState() != SelfAwareCircle.Visibility.clear) { // i.e. the spot is already occupied
				if (myCircle.get_state() != SelfAwareCircle.Visibility.clear) { // i.e. the spot is already occupied
					doGameOver("overran column "+randColumn);
				}
				else {
					myCircle.resetColor();
					myCircle.setState(SelfAwareCircle.Visibility.plain);
					myCircle.set_state(SelfAwareCircle.Visibility.plain);
				}
			} finally {
				GUIlock.unlock();
@@ -124,8 +126,8 @@ class sge extends GUI implements ActionListener, ItemListener {
					for (int yy = height - 2; yy >= 0; yy--) {  // go down to up, so as not to move circles more than once
						SelfAwareCircle orig = circles[xx][yy],
								dest = circles[xx][yy + 1];
						if (orig.getState() != SelfAwareCircle.Visibility.clear &&        // a colored circle
								dest.getState() == SelfAwareCircle.Visibility.clear) {    // above a cleared circle
						if (orig.get_state() != SelfAwareCircle.Visibility.clear &&        // a colored circle
								dest.get_state() == SelfAwareCircle.Visibility.clear) {    // above a cleared circle
							// move it down
							moveCircle(orig, dest);
						}
@@ -138,12 +140,12 @@ class sge extends GUI implements ActionListener, ItemListener {
		}
	}

    // PUBLIC ACCESS METHODS
    // METHODS

    /*
     * Default no-args constructor
     */
    public sge() {
    private sge() {
        super("Ari's samegame");
        try {
            SwingUtilities.invokeAndWait(
@@ -154,6 +156,13 @@ class sge extends GUI implements ActionListener, ItemListener {
        }
    }

    public static sge getInstance() {
      if (sge.Instance == null) {
        sge.Instance = new sge();
      }
      return Instance;
    }

    /*
     * Returns the color of the circle at location [xx][yy], or NONE if the circle has been cleared
     * @param xx must be between 0 and width
@@ -422,7 +431,7 @@ class sge extends GUI implements ActionListener, ItemListener {
     */
    synchronized private void moveCircle(SelfAwareCircle orig, SelfAwareCircle dest) {
        // copy the immutable, position independent values
        orig.copy(dest);
        orig.copyTo(dest);

        // clear the top item
        orig.setClear();
@@ -605,11 +614,11 @@ class sge extends GUI implements ActionListener, ItemListener {
            if (source == noPlayerMenuItem)
                return; // i.e. no players
            else if (source == simplePlayerMenuItem)
                startBrain(new simpleBrain(this));
                startBrain(new SimpleBrain(this));
            else if (source == lazyPlayerMenuItem)
                startBrain(new lazyBrain(this));
                startBrain(new LazyBrain(this));
            else if (source == smarterPlayerMenuItem)
                startBrain(new smarterBrain( this));
                startBrain(new SmarterBrain( this));
        } else {
            // deselected
            if (theBrain != null)
@@ -624,7 +633,7 @@ class sge extends GUI implements ActionListener, ItemListener {
     * Runs the application
     */
    public static void main(String[] args) {
        JFrame myApp = new sge();
        JFrame myApp = sge.getInstance();
        myApp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myApp.setSize(defaultWindowWidth, defaultWindowHeight);
        myApp.setVisible(true);
Loading