Class mazebase

All Implemented Interfaces:
KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class mazebase extends JFrame implements KeyListener

Superclass of maze generation/solution assignments for CSC17.

Protected fields, except the 2D array M, can be modified by overriding the customize() function in a subclass.
This class does not contain a main, which should be supplied in a subclass.
See Also:
  • Field Details

    • mheight

      protected int mheight
      The number of rows of the maze 2D array. This number should be odd in order for the maze to have a border. The default value is 41.
    • mwidth

      protected int mwidth
      The number of columns of the maze 2D array. This number should be odd in order for the maze to have a border. The default value is 41.
    • M

      protected int[][] M
      The array for the maze is declared and initialized in the superclass. This variable should be not set in customize()
    • showvalue

      protected boolean showvalue
      If set to true, the drawblock(int,int) function will display the values of the maze matrix that are non-zero
    • autodelay

      protected boolean autodelay
      If set to true, will automatically delay by value dtime at end of calls to drawdot(int,int)
    • usegif

      protected boolean usegif
      If set to true, will try to load animated gif from filename gifname, which will be displayed by drawdot(int,int)
    • bh

      protected int bh
      the height in pixels of graphical square representing a maze coordinate
    • bw

      protected int bw
      the width in pixels of graphical square representing a maze coordinate
    • yoff

      protected int yoff
      "y-offset", which is required on some systems that automatically displays a title bar for every window.
    • dtime

      protected int dtime
      The approximate number of milliseconds delayed in calls to drawdot(int,int) if autodelay is set to true
    • wallcolor

      protected Color wallcolor
      The color of maze "walls", or M[row][column] values that are zero
    • pathcolor

      protected Color pathcolor
      The color of maze "paths", or M[row][column] values that are non-zero
    • dotcolor

      protected Color dotcolor
      The color of the graphical circle drawn by default by drawdot(int,int)
    • pencolor

      protected Color pencolor
      The color of text messages that are displayed on the maze by drawMessage(java.lang.String)
    • gifname

      protected String gifname
      The path-name of the gif/jpeg file that replaces a circle if usegif is set to true
    • startdigx

      protected int startdigx
      Starting x coordinate of maze
    • startdigy

      protected int startdigy
      Starting y coordinate of maze: the mazebase superclass will call digout(startdigy,startdigx)
  • Constructor Details

    • mazebase

      public mazebase()
      constructor calls customize first, then creates the matrix M
  • Method Details

    • Graphics

      protected Graphics Graphics()
      returns java.awt.Graphics object that allows drawing to animation buffer: nothing will be displayed, however, until nextframe() is called.
    • loadgif

      protected void loadgif(String filename)
      utility to load animated gif, called from setup after customize()
    • paint

      public void paint(Graphics g)
      this function overrides automatic repaint: do not change
      Overrides:
      paint in class Window
    • clear

      protected void clear()
    • refresh

      protected void refresh()
    • nextframe

      public void nextframe()
      redraws animation buffer without delay
    • nextframe

      public void nextframe(int msdelay)
      redraws animation buffer after specified delay
      Parameters:
      msdelay - The approximate number of milliseconds to delay
    • delay

      public void delay(int ms)
      delays current thread by approximately ms milliseconds. This function is non-blocking.
    • drawblock

      public void drawblock(int y, int x)
      draws a graphical square of color pathcolor corresponding to matrix coordinates row y, column x.
    • drawdot

      public void drawdot(int y, int x)
      draws a solid circle of color dotcolor corresponding to matrix coordinates y,x, unless usegif is set true, in which case it will draw a gif as indicated by gifname
    • drawdot2

      protected void drawdot2(int y, int x)
    • drawgif

      public void drawgif(int y, int x)
      draw default gif
    • drawgif2

      protected void drawgif2(int y, Image gif, int x)
      draw a specific Image (such as animated gif)
    • drawMessage

      public void drawMessage(String m)
      displays string message m at top row of maze
    • customize

      public void customize()
      User-defined initialization code. This function can be overridden in a subclass. The default, base class version does nothing. This function is called by the constructor of base class
    • digout

      public void digout(int y, int x)
      This function must be override in a subclass to generate a random maze. The default, base-class version does nothing.
    • solve

      public void solve()
      Override this function in a subclass to solve the maze. Start at coordinates x=1, y=1, and stop at coordinates x=mwidth-1, y=mheight-2.
    • trace

      public void trace()
      Override this function to trace the optimal solution path of the maze.
    • play

      public void play()
      Optional function to override to set up an interactive game
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Override this function to respond to keyboard events. The default function prints the numerical value corresponding to the key pressed
      Specified by:
      keyPressed in interface KeyListener