/* * Copyright (c) 1998 Kevan Stannard. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and * without fee is hereby granted. * * Please note that this software comes with * NO WARRANTY * * BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED * BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES * PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS * TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. * * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER * PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, * INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE * THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED * BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER * OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ import java.awt.*; import java.awt.image.*; import java.applet.*; import java.net.*; class Tile extends Panel { Image image; int width; int height; MediaTracker tracker; public Tile(Image i, int w, int h) { image = i; width = w; height = h; tracker = new MediaTracker(this); tracker.addImage(i,0); tracker.checkAll(true); } public final void draw(Graphics g, int x, int y) { g.drawImage(image,x,y,null); } public final String toString() { return image.toString(); } public final boolean check() { if (tracker == null) { return true; } else { if (tracker.checkAll()) { tracker = null; return true; } } return false; } public final void addBorder() { int numPixels; int pix[]; numPixels = width*height; pix = new int[numPixels+1]; // grab the pixels PixelGrabber pg = new PixelGrabber(image,0,0,width,height,pix,0,width); try { pg.grabPixels(); } catch (InterruptedException e) { } // process the pixels for (int p=0; p> 32; int r = (pix[p] & 0x00ff0000) >> 16; int g = (pix[p] & 0x0000ff00) >> 8; int b = (pix[p] & 0x000000ff); if (p255) r=255; if (g>255) g=255; if (b>255) b=255; } if (p>=(numPixels-width) || (p%width)==width-1) { r >>= 1; g >>= 1; b >>= 1; if (r<0) r=0; if (g<0) g=0; if (b<0) b=0; } pix[p] = (a << 32) | (r << 16) | (g << 8) | (b); } // create new image image = createImage(new MemoryImageSource(width,height,pix,0,width)); } public final void darken() { int numPixels; int pix[]; numPixels = width*height; pix = new int[numPixels+1]; // grab the pixels PixelGrabber pg = new PixelGrabber(image,0,0,width,height,pix,0,width); try { pg.grabPixels(); } catch (InterruptedException e) { } // process the pixels for (int p=0; p> 32; int r = (pix[p] & 0x00ff0000) >> 16; int g = (pix[p] & 0x0000ff00) >> 8; int b = (pix[p] & 0x000000ff); r >>= 1; g >>= 1; b >>= 1; if (r<0) r=0; if (g<0) g=0; if (b<0) b=0; pix[p] = (a << 32) | (r << 16) | (g << 8) | (b); } // create new image image = createImage(new MemoryImageSource(width,height,pix,0,width)); } } public class JZOOTileWork extends Applet implements Runnable { // applet int appletWidth = 0; int appletHeight = 0; // thread Thread thread; // main image String imageName; Image image; int imageWidth; int imageHeight; // tiles final int TILES_ACROSS = 4; final int TILES_DOWN = 4; int tileWidth; int tileHeight; int blankTile; int blankx; int blanky; Tile tile[] = new Tile[TILES_ACROSS * TILES_DOWN]; int matrix[][] = new int[TILES_ACROSS][TILES_DOWN]; // double buffer Image db; Graphics dbGraphics; // blank tile glow int glow = 0; int glowDirection = 16; // image tracker MediaTracker tracker; // status final int LOADING_IMAGES = 1; final int START_CREATING_TILES = 2; final int CREATING_TILES = 3; final int READY = 4; final int GAME_FINISHED = 5; int status = 0; // time int time; int gameCounter; // font Font font; FontMetrics fm; int textWidth; int textAscent; int textDescent; public void init() { appletWidth = Integer.parseInt(getParameter("width")); appletHeight = Integer.parseInt(getParameter("height")); imageName = getParameter("imageName"); db = createImage(appletWidth, appletHeight); dbGraphics = db.getGraphics(); font = new Font("Ariel",Font.BOLD,14); fm = getFontMetrics(font); } public void start() { if (thread == null) { thread = new Thread(this); } thread.start(); } public void stop() { if (thread != null) { thread.stop(); } } public void update(Graphics g) { paint(dbGraphics); g.drawImage(db,0,0,null); } public void paint(Graphics g) { g.setFont(font); if (status == READY) { int i=0; int tileNum; for (int y=0; y 255) { glow = 255; glowDirection = -32; } // draw the timer String s = "" + time; textWidth = fm.stringWidth(s); textAscent = fm.getAscent(); textDescent = fm.getDescent(); int xoff = (tileWidth - textWidth) / 2; int yoff = textAscent + (tileHeight - (textAscent + textDescent)) / 2; g.setColor(Color.red); g.drawString(s,(x*tileWidth)+xoff,(y*tileHeight)+yoff); } else { tile[tileNum].draw(g, x*tileWidth, y*tileHeight); } } } } else if (status == GAME_FINISHED) { int i=0; int tileNum; for (int y=0; y