home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.BorderLayout;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.GridLayout;
- import java.awt.Image;
- import java.awt.Panel;
- import java.awt.image.FilteredImageSource;
- import java.awt.image.ImageObserver;
-
- public class Tubes extends Applet {
- static final Color[] colors;
- private Image _image;
- private Graphics _graphics;
- private Dimension _size;
- private Help _help;
- private Puzzle _puzzle;
- private int _level = 4;
-
- public void init() {
- ((Container)this).setLayout(new BorderLayout());
- Panel var1 = new Panel();
- ((Container)var1).setLayout(new GridLayout(1, 0));
- ((Container)var1).add(new Button("Goal"));
- ((Container)var1).add(new Button("Random"));
- ((Container)var1).add(new Button("Help"));
- ((Container)this).add("North", var1);
- var1 = new Panel();
- ((Container)var1).setLayout(new GridLayout(1, 0));
- ((Container)var1).add(new Button("Left"));
- ((Container)var1).add(new Button("Flip"));
- ((Container)var1).add(new Button("Right"));
- ((Container)this).add("South", var1);
- this._help = new Help(this, this._level);
- this._puzzle = new Puzzle(this, this._level + 2);
- }
-
- public void stop() {
- if (this._help != null) {
- this._help.hide();
- }
-
- }
-
- public boolean action(Event var1, Object var2) {
- if (var2.equals("Help")) {
- this._help.show();
- return true;
- } else {
- if (var2.equals("Goal")) {
- this._puzzle.goal();
- } else if (var2.equals("Random")) {
- this._puzzle.randomize();
- } else if (var2.equals("Left")) {
- this._puzzle.left();
- } else if (var2.equals("Flip")) {
- this._puzzle.flip();
- } else if (var2.equals("Right")) {
- this._puzzle.right();
- }
-
- ((Component)this).repaint();
- return true;
- }
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (var2 < this._size.width / 3) {
- this._puzzle.left();
- } else if (var2 < this._size.width * 2 / 3) {
- this._puzzle.flip();
- } else {
- this._puzzle.right();
- }
-
- ((Component)this).repaint();
- return true;
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public void paint(Graphics var1) {
- ((Applet)this).showStatus(this._puzzle.goal_p() ? " G O A L !" : "");
- if (this._image == null || this._size.width != ((Component)this).size().width || this._size.height != ((Component)this).size().height) {
- this._size = new Dimension(((Component)this).size());
- this._image = ((Component)this).createImage(this._size.width, this._size.height);
- this._graphics = this._image.getGraphics();
- }
-
- this._graphics.setColor(Color.black);
- this._graphics.fillRect(0, 0, this._size.width, this._size.height);
- this._graphics.translate(this._size.width / 2, this._size.height / 2);
- this._puzzle.draw(this._graphics);
- this._graphics.translate(-this._size.width / 2, -this._size.height / 2);
- var1.drawImage(this._image, 0, 0, (ImageObserver)null);
- }
-
- Image makeImage(int var1, int var2) {
- Image var3 = ((Component)this).createImage(var1, var2);
- Graphics var4 = var3.getGraphics();
- var4.setColor(Hollow.color);
- var4.fillRect(0, 0, var1, var2);
- return var3;
- }
-
- Image hollowImage(Image var1) {
- return ((Component)this).createImage(new FilteredImageSource(var1.getSource(), new Hollow()));
- }
-
- static void drawImageCentered(Graphics var0, Image var1, int var2, int var3) {
- var0.drawImage(var1, var2 - var1.getWidth((ImageObserver)null) / 2, var3 - var1.getHeight((ImageObserver)null) / 2, (ImageObserver)null);
- }
-
- void setLevel(int var1) {
- if (this._level != var1) {
- this._puzzle.setSize((this._level = var1) + 2);
- ((Component)this).repaint();
- }
- }
-
- static {
- colors = new Color[]{Color.black, Color.red, Color.yellow, Color.green, Color.cyan, Color.blue, Color.magenta, Color.white};
- }
- }
-