|
Breakout Problem Set Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object breakout.Loader
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.%board
.
The loader will attempt to decode any argument not beginning with %
into an Integer.
Board.add(BreakoutComponent bc)
, regardless
of how it looks in the text file.
Boad.add(BreakoutComponent bc, Point p)
.
"
) is used as a symbol.
char ="
) or between an equals
sign and its first set of quotes(char= "
).
ball args="
or paddle args="
)
args="61, 15"
or ballargs="61, 15 "
is okay; class=" breakout.BasicBrick"
is not)
%board
tries
to act as an argument.
board
tags.
Carriage returns are okay; spaces(" ") are not(unless you've defined them as symbols, of course).
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 |
protected Board board
load()
method.
protected java.io.File fromFile
Loader
reads from.
protected BoardPanel bpanel
Loader
.
protected java.io.BufferedReader reader
fromFile
.
Constructor Detail |
public Loader(java.io.File f, BoardPanel bp)
f
- File to be read.bp
- BoardPanel used to create the Board.Method Detail |
public Board load() throws BadBoardFormatException
BadBoardFormatException
- if there is a problem parsing the file.Board
,
BadBoardFormatException
protected void processSymbolTag(java.lang.String line) throws BadBoardFormatException
"[symbol char="b" class="breakout.BasicBrick" args="61,15"]"
BadBoardFormatException
- if the line cannot be processed; usually a formatting error.protected void processBoardTag(java.lang.String line) throws java.lang.ClassNotFoundException, BadBoardFormatException
"[board ball="breakout.BasicBall" ballargs="" paddle="breakout.BasicPaddle" paddleargs="%board"]"
java.lang.ClassNotFoundException
- if the ball or paddle class cannot be found.
BadBoardFormatException
- if the line cannot be processed; usually a formatting error.protected Board reload() throws BadBoardFormatException
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 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |