home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / TUBES.EXE / Tubes.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-05-21  |  3.7 KB  |  132 lines

  1. import java.applet.Applet;
  2. import java.awt.BorderLayout;
  3. import java.awt.Button;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Dimension;
  8. import java.awt.Event;
  9. import java.awt.Graphics;
  10. import java.awt.GridLayout;
  11. import java.awt.Image;
  12. import java.awt.Panel;
  13. import java.awt.image.FilteredImageSource;
  14. import java.awt.image.ImageObserver;
  15.  
  16. public class Tubes extends Applet {
  17.    static final Color[] colors;
  18.    private Image _image;
  19.    private Graphics _graphics;
  20.    private Dimension _size;
  21.    private Help _help;
  22.    private Puzzle _puzzle;
  23.    private int _level = 4;
  24.  
  25.    public void init() {
  26.       ((Container)this).setLayout(new BorderLayout());
  27.       Panel var1 = new Panel();
  28.       ((Container)var1).setLayout(new GridLayout(1, 0));
  29.       ((Container)var1).add(new Button("Goal"));
  30.       ((Container)var1).add(new Button("Random"));
  31.       ((Container)var1).add(new Button("Help"));
  32.       ((Container)this).add("North", var1);
  33.       var1 = new Panel();
  34.       ((Container)var1).setLayout(new GridLayout(1, 0));
  35.       ((Container)var1).add(new Button("Left"));
  36.       ((Container)var1).add(new Button("Flip"));
  37.       ((Container)var1).add(new Button("Right"));
  38.       ((Container)this).add("South", var1);
  39.       this._help = new Help(this, this._level);
  40.       this._puzzle = new Puzzle(this, this._level + 2);
  41.    }
  42.  
  43.    public void stop() {
  44.       if (this._help != null) {
  45.          this._help.hide();
  46.       }
  47.  
  48.    }
  49.  
  50.    public boolean action(Event var1, Object var2) {
  51.       if (var2.equals("Help")) {
  52.          this._help.show();
  53.          return true;
  54.       } else {
  55.          if (var2.equals("Goal")) {
  56.             this._puzzle.goal();
  57.          } else if (var2.equals("Random")) {
  58.             this._puzzle.randomize();
  59.          } else if (var2.equals("Left")) {
  60.             this._puzzle.left();
  61.          } else if (var2.equals("Flip")) {
  62.             this._puzzle.flip();
  63.          } else if (var2.equals("Right")) {
  64.             this._puzzle.right();
  65.          }
  66.  
  67.          ((Component)this).repaint();
  68.          return true;
  69.       }
  70.    }
  71.  
  72.    public boolean mouseDown(Event var1, int var2, int var3) {
  73.       if (var2 < this._size.width / 3) {
  74.          this._puzzle.left();
  75.       } else if (var2 < this._size.width * 2 / 3) {
  76.          this._puzzle.flip();
  77.       } else {
  78.          this._puzzle.right();
  79.       }
  80.  
  81.       ((Component)this).repaint();
  82.       return true;
  83.    }
  84.  
  85.    public void update(Graphics var1) {
  86.       this.paint(var1);
  87.    }
  88.  
  89.    public void paint(Graphics var1) {
  90.       ((Applet)this).showStatus(this._puzzle.goal_p() ? " G O A L !" : "");
  91.       if (this._image == null || this._size.width != ((Component)this).size().width || this._size.height != ((Component)this).size().height) {
  92.          this._size = new Dimension(((Component)this).size());
  93.          this._image = ((Component)this).createImage(this._size.width, this._size.height);
  94.          this._graphics = this._image.getGraphics();
  95.       }
  96.  
  97.       this._graphics.setColor(Color.black);
  98.       this._graphics.fillRect(0, 0, this._size.width, this._size.height);
  99.       this._graphics.translate(this._size.width / 2, this._size.height / 2);
  100.       this._puzzle.draw(this._graphics);
  101.       this._graphics.translate(-this._size.width / 2, -this._size.height / 2);
  102.       var1.drawImage(this._image, 0, 0, (ImageObserver)null);
  103.    }
  104.  
  105.    Image makeImage(int var1, int var2) {
  106.       Image var3 = ((Component)this).createImage(var1, var2);
  107.       Graphics var4 = var3.getGraphics();
  108.       var4.setColor(Hollow.color);
  109.       var4.fillRect(0, 0, var1, var2);
  110.       return var3;
  111.    }
  112.  
  113.    Image hollowImage(Image var1) {
  114.       return ((Component)this).createImage(new FilteredImageSource(var1.getSource(), new Hollow()));
  115.    }
  116.  
  117.    static void drawImageCentered(Graphics var0, Image var1, int var2, int var3) {
  118.       var0.drawImage(var1, var2 - var1.getWidth((ImageObserver)null) / 2, var3 - var1.getHeight((ImageObserver)null) / 2, (ImageObserver)null);
  119.    }
  120.  
  121.    void setLevel(int var1) {
  122.       if (this._level != var1) {
  123.          this._puzzle.setSize((this._level = var1) + 2);
  124.          ((Component)this).repaint();
  125.       }
  126.    }
  127.  
  128.    static {
  129.       colors = new Color[]{Color.black, Color.red, Color.yellow, Color.green, Color.cyan, Color.blue, Color.magenta, Color.white};
  130.    }
  131. }
  132.