SGrid
| Kind of class: | class |
|---|---|
| Inherits from: | AbstractGrid |
| Version: | 1.0 |
| Author: | Francis Bourre |
| Classpath: | com.bourre.structures.SGrid |
| File last modified: | Wednesday, 31 October 2007, 07:35:30 |
SGrid defines String grid structure.Based on AbstractGrid class, this data's structure only accept
String element for content.
Summary
Constructor
SGrid
function SGrid (
nX:Number,
nY:Number)
Constructs a new
SGrid instance.Example
var g : SGrid = new SGrid(2, 2);
Parameters:
nX:
grid width
nY:
grid height
Instance methods
deserialize
function deserialize (
s:String,
sCharSep:String,
sUndefined:String) : Void
Deserializes passed-in
loads it into grid.
String content and loads it into grid.
Useful to load grid content.
Use serialize to save content.
Example
var b : SGrid = new SGrid(2, 2); var sContent : String = "chair|room|tree|__"; b.deserialize(sContent, "|", "__");
Parameters:
value in grid. (default "_")
s :
Content
String representationsCharSep :
String separator value (default ",");sUndefined:
String used for undefined or null value in grid. (default "_")
getVal
function getVal (
v:Point) : String
Returns value stored in grid cell defining by
passed-in Point coordinate.
passed-in Point coordinate.
Concrete implementation of AbstractGrid.getVal method.
Example
var g : SGrid = new SGrid(2, 2); var aElements : Array = new Array("chair", "room", "tree", "carpet"); g.setContent(aElements}; var r : String = g.getVal( new Point(0,1) ); //return "tree"
Parameters:
v:
Cell Point position
Returns:
String valuepermute
Permutes 2 passed-in
cell value.Example
var g : SGrid = new SGrid(2, 2); var aElements : Array = new Array("chair", "room", "tree"); g.setContent(aElements); PixlibDebug.DEBUG( g.serialize() ); //return "chair,room,tree,_" g.permute( new Point(0,1), new Point(1,0) ); PixlibDebug.DEBUG( g.serialize() ); //return "chair,tree,room,_"
serialize
function serialize (
sCharSep:String,
sUndefined:String) : String
Serializes grid content.
Useful to save grid content.
Use deserialize to load content.
Example
var g : SGrid = new SGrid(2, 2); var aElements : Array = new Array("chair", "room", "tree"); g.setContent(aElements); PixlibDebug.DEBUG( g.serialize() ); //return "chair,room,tree,_" PixlibDebug.DEBUG( g.serialize("|", "__") ); //return "chair|room|tree|__"
Parameters:
value in grid. (default "_")
sCharSep :
String separator value (default ",");sUndefined:
String used for undefined or null value in grid. (default "_")
Returns:
Serialization
StringsetContent
function setContent (
a:Array,
sUndefined:String) : Void
Sets content of grid with passed-in
Array of String objects.Can use deserialize method to define content directly with a
String representation content like "chair,room,tree,_"
Used by deserialize to load content after deserialization process.
Example
var g : SGrid = new SGrid(2, 2); var aContent : Array = new Array("chair","room","tree","_"); g.setContent(aContent);
Parameters:
value in grid.
a :
Array structure of String elements.sUndefined:
String used for undefined or null value in grid.
setVal
function setVal (
v:Point,
s:String) : Void
Defines value of grid cell defining by passed-in Point
coordinate.
coordinate.
Concrete implementation of AbstractGrid.setVal method.
Example
var g : SGrid = new SGrid(2, 2); var aElements : Array = new Array("chair", "room", "tree", "carpet"); g.setContent(aElements}; g.setVal( new Point(0,1), "plant"); var r : Number = b.getVal( new Point(0,1) ); //return "plant"
Parameters:
v:
Cell Point position
toString
function toString (
) : String
Returns the string representation of this instance.
Returns:
the string representation of this instance
Overrides: