Breakout Problem Set Javadocs

breakout
Class Loader

java.lang.Object
  extended bybreakout.Loader

public class Loader
extends java.lang.Object

Utility class for parsing a board file into a breakout.Board.

A boardfile begins with one or several symbol definitions, each specifying the character used, the class it represents, and any arguments it needs in the constructor.
After the symbols are defined, the opening board tag defines the ball class and constructor arguments and the paddle class/constructor arguments. Between the opening and closing board tags is a list of characters specifying the order in which to add bricks to the board.

A vanilla boardfile looks like this:

[symbol char="b" class="breakout.BasicBrick" args="61,15"]
[symbol char="h" class="breakout.HitpointsBrick" args="58, 15"]
[board ball="breakout.BasicBall" ballargs="" paddle="breakout.BasicPaddle" paddleargs="%board"]
bhbhb
hbhbh
hhbhh
[/board]
Note the symbol tag value names: char, class, and args. Note the board tag value names: ball, ballargs, paddle, and paddleargs. These must be present in their respective tags.

You can define as many symbols as you want, and put in as many or as few bricks as you want(though if you overflow the maximum number of bricks that'll fit in the board, you'll have error messages spewing all over the console). You get one ball and one paddle to start with, and it ought to tell you what's wrong and where if something is screwed up. I did try to make it friendly.

Important things to note:
  1. You must define a symbol before you can use it.
  2. You must use the fully-qualified classname, ie, "breakout.BasicBrick" instead of just "BasicBrick".
  3. The ONLY arguments to your BreakoutComponent classes that this loader will recognize are integers and the keyword string %board. The loader will attempt to decode any argument not beginning with % into an Integer.
  4. Arguments are comma-delimited.
  5. Just because you put a carriage return at the end of a line, doesn't mean the row will end there once the board is loaded into the game. Bricks are added sequentially and automatically laid out using Board.add(BreakoutComponent bc), regardless of how it looks in the text file.
  6. The ball is added two ball-heights above the paddle, in the middle of the board(left-to-right). The paddle is asked for its location, and added using Boad.add(BreakoutComponent bc, Point p).
It will break if:
  1. The double-quote(") is used as a symbol.
  2. A value is missing from a tag.
  3. There is a carriage return in the middle of a tag.
  4. There are spaces in any of the following places:
  5. As noted above, anything other than an integer or %board tries to act as an argument.
  6. Anything other than brick symbols occurs between the board tags. Carriage returns are okay; spaces(" ") are not(unless you've defined them as symbols, of course).
It doesn't care about:
  1. The order of values within a tag.
  2. Comments, as long as they're on their own line, and aren't between the board tags.


Field Summary
protected  Board board
          The Board eventaully returned from the load() method.
protected  BoardPanel bpanel
          The BoardPanel used to create the Board for this Loader.
protected  java.io.File fromFile
          The File Loader reads from.
protected  java.io.BufferedReader reader
          Reads from fromFile.
 
Constructor Summary
Loader(java.io.File f, BoardPanel bp)
          Creates a new Loader for the specified File, to create a Board with the specified BoardPanel.
 
Method Summary
 Board load()
          Attempts to read and parse a boardfile(*.brd), returning a Board that meets the file's specifications.
protected  void processBoardTag(java.lang.String line)
          Process a line formatted like "[board ball="breakout.BasicBall" ballargs="" paddle="breakout.BasicPaddle" paddleargs="%board"]"
protected  void processSymbolTag(java.lang.String line)
          Process a line formatted like "[symbol char="b" class="breakout.BasicBrick" args="61,15"]"
protected  Board reload()
          Reloads saved data into a new Board.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

board

protected Board board
The Board eventaully returned from the load() method.


fromFile

protected java.io.File fromFile
The File Loader reads from.


bpanel

protected BoardPanel bpanel
The BoardPanel used to create the Board for this Loader.


reader

protected java.io.BufferedReader reader
Reads from fromFile.

Constructor Detail

Loader

public Loader(java.io.File f,
              BoardPanel bp)
Creates a new Loader for the specified File, to create a Board with the specified BoardPanel.

Parameters:
f - File to be read.
bp - BoardPanel used to create the Board.
Method Detail

load

public Board load()
           throws BadBoardFormatException
Attempts to read and parse a boardfile(*.brd), returning a Board that meets the file's specifications.

Returns:
a Board meeting the file's specifications.
Throws:
BadBoardFormatException - if there is a problem parsing the file.
See Also:
Board, BadBoardFormatException

processSymbolTag

protected void processSymbolTag(java.lang.String line)
                         throws BadBoardFormatException
Process a line formatted like "[symbol char="b" class="breakout.BasicBrick" args="61,15"]"

Throws:
BadBoardFormatException - if the line cannot be processed; usually a formatting error.

processBoardTag

protected void processBoardTag(java.lang.String line)
                        throws java.lang.ClassNotFoundException,
                               BadBoardFormatException
Process a line formatted like "[board ball="breakout.BasicBall" ballargs="" paddle="breakout.BasicPaddle" paddleargs="%board"]"

Throws:
java.lang.ClassNotFoundException - if the ball or paddle class cannot be found.
BadBoardFormatException - if the line cannot be processed; usually a formatting error.

reload

protected Board reload()
                throws BadBoardFormatException
Reloads saved data into a new Board. Unused as of 07/02/03.

Would allow you to reload a board you just played without having to go hunt for it again in a dialog box.

Throws:
BadBoardFormatException - if there are any problems reloading the board(not that you'd get a chance to reload the board if this had been thrown when you initially load()ed it...)

Breakout Problem Set Javadocs