/** * @author Kaushik Raj * @see http://www.cis.syr.edu/~kraj/java/ * @email kraj@syr.edu * * (c) copyright-98 Kaushik Raj * All Rights Reserved. * * This source code is free for all non-commercial purposes, as long as the name * and the url address given above is written with the modified program. The author does not gives * the permission to publish the source code in any book or any other publishing media. * * * The author doesnot takes any responsibility for the software/hardware damages * that may occur due to this program. */ /** * Part of this program has been taken from MazeGen.java * * @see http://www.mazeworks.com/mazegen/mazegen.htm */ /** * File : MazeCanvas.java * Last update : 10 July,1998 */ import java.awt.*; import java.applet.*; import java.util.*; /** * draws the maze canvas using image buffering */ public class MazeCanvas extends Canvas { static final int BORDER=10, MAX_CELL_SIZE=20 ; private int width, height, mzWidth, mzHeight, cellSize, wOffset, hOffset, rows, cols, pathSize, nwPathOffset, sePathOffset ; /** for double buffering */ Image bufferImage ; Graphics buffer ; /** handle */ MazeGame mg ; private Font font; /** intialisationm with height and lenght of the canvas */ MazeCanvas(int mcw,int mch) { width = mcw ; height = mch ; } /** initialises the maze and the canvas */ private void drawInit(Maze mz) { cols = mz.getCols() ; rows = mz.getRows() ; cellSize = (int)Math.min(MAX_CELL_SIZE, Math.min((width-BORDER)/cols,(height-BORDER)/rows)) ; mzWidth = cellSize * cols ; mzHeight = cellSize * rows ; wOffset = (int)((width-mzWidth)/2) ; hOffset = (int)((height-mzHeight)/2) ; pathSize = (int)(cellSize/2)-1 ; nwPathOffset = (int)((cellSize-pathSize)/2) ; sePathOffset = cellSize - pathSize - nwPathOffset ; if (buffer==null) { bufferImage = createImage(width,height) ; buffer = bufferImage.getGraphics() ; } // draw background buffer.setColor(mg.appletColor); buffer.fillRect(0,0,width,height) ; buffer.setColor(mg.bkgrndColor); buffer.fillRect(wOffset,hOffset,mzWidth,mzHeight) ; // draw outer maze frame buffer.setColor(mg.frameColor); buffer.draw3DRect(wOffset-2, hOffset-2, mzWidth+4, mzHeight+4, true) ; buffer.drawRect(wOffset-1, hOffset-1, mzWidth+2, mzHeight+2) ; } /** initialisation */ public void init(){ if (buffer==null) { bufferImage = createImage(width,height) ; buffer = bufferImage.getGraphics() ; } } // draw full generated maze with start and end points // called if Show Gen off public void drawMaze(Maze mz) { drawInit(mz) ; buffer.setColor(mg.wallColor); for (int i=0; i",60,170); buffer.setColor(Color.yellow); buffer.drawString("http://web.syr.edu/~kraj/",70,250); repaint(); } private void setFontData(){ font=new Font("Times",Font.PLAIN,20); buffer.setFont(font); } /** when the images are being downloaded */ public void loadingImages(){ buffer.setColor(mg.appletColor); buffer.fillRect(0,0,width,height) ; setFontData(); buffer.setColor(Color.red); buffer.drawString("Loading Images",135,50); gameCopyRight(); repaint(); } }