home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / tydhtml / dyn.exe / CHAP13 / OldShellGame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-24  |  2.9 KB  |  85 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7.  
  8. public class OldShellGame extends Applet {
  9.    static int time = 50;
  10.    static int numframes = 8;
  11.    boolean running = false;
  12.    static int[] movesX0 = new int[]{0, 0, 0, 284, 0, 142, 284, 142, 142};
  13.    static int[] movesY0 = new int[]{50, 50, 50, 176, 50, 176, 50, 176, 50};
  14.    static int[] movesX1 = new int[]{142, 142, 142, 142, 284, 0, 0, 0, 284};
  15.    static int[] movesY1 = new int[]{50, 50, 50, 176, 50, 176, 50, 176, 50};
  16.    static int[] movesX2 = new int[]{284, 126, 284, 0, 142, 284, 142, 284, 0};
  17.    static int[] movesY2 = new int[]{50, 176, 50, 176, 50, 176, 50, 176, 50};
  18.    static int[] movesX3 = new int[]{142, 142, 300, 16, 158, 300, 158, 300, 16};
  19.    static int[] movesY3 = new int[]{192, 192, 66, 192, 66, 192, 66, 192, 66};
  20.    int[] left = new int[]{0, 142, 284, 142};
  21.    int[] top = new int[]{50, 50, 50, 192};
  22.    Image shell;
  23.    Image stone;
  24.  
  25.    public void init() {
  26.       this.stone = ((Applet)this).getImage(((Applet)this).getCodeBase(), "gem.gif");
  27.       this.shell = ((Applet)this).getImage(((Applet)this).getCodeBase(), "walnut.gif");
  28.    }
  29.  
  30.    public void paint(Graphics var1) {
  31.       int var2 = 0;
  32.       int var3 = 1;
  33.       Dimension var4 = ((Component)this).size();
  34.       var1.fillRect(0, 0, var4.width, var4.height);
  35.       var1.drawImage(this.stone, this.left[3], this.top[3], this);
  36.       var1.drawImage(this.shell, this.left[0], this.top[0], this);
  37.       var1.drawImage(this.shell, this.left[1], this.top[1], this);
  38.       var1.drawImage(this.shell, this.left[2], this.top[2], this);
  39.       if (this.running) {
  40.          for(; var2 < time * numframes; this.Delay(200L, var2)) {
  41.             this.left[0] = movesX0[var3 - 1] + (movesX0[var3] - movesX0[var3 - 1]) * (var2 % time) / time;
  42.             this.top[0] = movesY0[var3 - 1] + (movesY0[var3] - movesY0[var3 - 1]) * (var2 % time) / time;
  43.             this.left[1] = movesX1[var3 - 1] + (movesX1[var3] - movesX1[var3 - 1]) * (var2 % time) / time;
  44.             this.top[1] = movesY1[var3 - 1] + (movesY1[var3] - movesY1[var3 - 1]) * (var2 % time) / time;
  45.             this.left[2] = movesX2[var3 - 1] + (movesX2[var3] - movesX2[var3 - 1]) * (var2 % time) / time;
  46.             this.top[2] = movesY2[var3 - 1] + (movesY2[var3] - movesY2[var3 - 1]) * (var2 % time) / time;
  47.             this.left[3] = movesX3[var3 - 1] + (movesX3[var3] - movesX3[var3 - 1]) * (var2 % time) / time;
  48.             this.top[3] = movesY3[var3 - 1] + (movesY3[var3] - movesY3[var3 - 1]) * (var2 % time) / time;
  49.             var1.fillRect(0, 0, var4.width, var4.height);
  50.             if (var2 < time || var2 >= time * numframes) {
  51.                var1.drawImage(this.stone, this.left[3], this.top[3], this);
  52.             }
  53.  
  54.             var1.drawImage(this.shell, this.left[0], this.top[0], this);
  55.             var1.drawImage(this.shell, this.left[1], this.top[1], this);
  56.             var1.drawImage(this.shell, this.left[2], this.top[2], this);
  57.             ++var2;
  58.             if (var2 % time == 0 && var3 < numframes) {
  59.                ++var3;
  60.             }
  61.          }
  62.       }
  63.  
  64.       this.running = false;
  65.    }
  66.  
  67.    public boolean mouseUp(Event var1, int var2, int var3) {
  68.       this.running = true;
  69.       this.left[3] = 142;
  70.       this.top[3] = 192;
  71.       ((Component)this).repaint();
  72.       return true;
  73.    }
  74.  
  75.    public void Delay(long var1, int var3) {
  76.       long var4 = 0L;
  77.       long var6 = 0L;
  78.  
  79.       for(long var8 = 0L; var8 < var1; ++var8) {
  80.          ++var6;
  81.       }
  82.  
  83.    }
  84. }
  85.