import wheels.users.*;
import java.awt.Color;
import java.awt.event.MouseEvent;

/**
 * Simulates the old hand-held version of Simon-Says.
 * (Currently has no game mechanics though.)
 *
 * @author Zach Tomaszewski
 * @version 14 Nov 07
 */
public class SimpleSimonSays {

  private Frame window;
  private Button red;
  private Button green;
  private Button blue;
  private Button yellow;


  /**
   * Builds a SimonSays interface with four buttons
   * (red, green, blue, yellow) to click.
   */
  public SimpleSimonSays() {
    window = new Frame();

    //calculate dimensions of buttons
    int bWidth = Frame._dp.getWidth() / 2;
    int bHeight = Frame._dp.getHeight() / 2;

    //create buttons
    red = new Button(0, 0, bWidth, bHeight, Color.red, new Color(100, 0, 0));
    green = new Button(bWidth, 0, bWidth, bHeight, Color.green, new Color(0, 100, 0));
    blue = new Button(0, bHeight, bWidth, bHeight, Color.blue, new Color(0, 0, 100));
    yellow = new Button(bWidth, bHeight, bWidth, bHeight,
                        Color.yellow, new Color(100, 100, 0));
  }

  /**
   * Creates an instance of Simon Says for the player to enjoy.
   */
  public static void main(String[] args) {
    SimpleSimonSays game = new SimpleSimonSays();
  }


  /**
   * A clickable button that changes color from on-to-off or
   * off-to-on each time it is clicked.
   */
  protected class Button extends Rectangle {

    private Color onColor;
    private Color offColor;

    /**
     * Creates a new button with its upper-left corner
     * positioned at (xPos, yPos).  The button has the given
     * width and height (in pixels), and it changes between
     * onColor and offColor when clicked.
     * A new button starts in the offColor.
     */
    public Button(int xPos, int yPos, int width, int height,
                  Color onColor, Color offColor) {
      super();
      this.setLocation(xPos, yPos);
      this.setSize(width, height);

      this.onColor = onColor;
      this.offColor = offColor;
      this.setColor(offColor);
    }

    /**
     * Overrides Recantangle's method to receive clicks.
     * When clicked, a Button will toggle between its on and off colors.
     */
    public void mousePressed(MouseEvent me) {
      if (this.getColor().equals(onColor)){
        this.setColor(offColor);
      }else {
        this.setColor(onColor);
      }
    }

  }
}
