Games\GamesByEmail.jsGamesByEmailObject
All Implemented Interfaces:
GamesByEmail.Piece
implementsFoundation.Class
A piece class for games like chess. May be used directly or extended.
See Also:
| Constructor Summary |
Creates a piece.
|
| Field Summary | |
| boardPoint
The piece's position on the board (not on the screen).
|
| hidden
Whether the piece is visible to the current player or not.
|
| index
The position of this piece in the parent pieces object.
|
| pieces
The parent pieces object.
|
| valueIndex
The position of this piece's value in the result of the pieces getValue call. Based on the position. Set to -1 to not include in getValue.
|
| Method Summary | |
|
Adds the pieces HTML to the a string builder.
#returns The string builder after appending.
|
|
Centers the piece on a point.
|
static |
Returns a new piece object of the type.
|
|
|
|
Returns an ID that is unique to this piece that can be used as HTML element IDs. No other piece of any class will generate the same ID even when passed the same parameter. The same piece will always generate the same ID when passed the same parameter.
|
|
Returns code that can be used in DOM events to invoke methods and properties of the piece.
|
|
Changes the pieces value (the type of piece it is).
|
|
Gets the clipping rectangle for this piece based on its color value.
#returns The clipping rectangle.
|
|
Returns the HTML element that is unique to this piece.
|
|
Gets the image file source for pieces in the game. Pieces should all be in the same file, with clipping rectangles defined.
#returns The full path to the image file.
|
|
Gets the screen rectangle for this piece based on its
boardPoint property. |
|
Gets the color of this piece based on its
value property.
#returns The color. |
|
Determines if the piece color is the same as the current player's team color.
#returns True if the colors are the same, else false.
|
|
Moves the piece to a board point. The
boardPoint property is updated. |
|
Determines if a piece occupies a board point.
|
|
Removes a piece.
|
|
Resets a piece to its
boardPoint position and hidden state after a call to snap, center or setVisibility. |
|
Changes the piece's board value (the color and type of piece it is).
|
|
Changes the piece's color.
|
|
Sets the 'permanent' visibility of a piece.
|
|
Changes the piece's value (the type of piece it is).
|
|
Changes the piece's value and color.
|
|
Sets the 'temporary' visibility of a piece.
|
|
Centers the piece on a board point. The
boardPoint property is not altered. |
Methods inherited from Foundation.Class |
getTypePath, isInstanceOf |
| Constructor Detail |
GamesByEmail.Piece(/*Pieces*/ pieces,
/*Number*/ index,
/*Number*/ value,
/*Number*/ valueIndex,
/*Boolean*/ hidden)
Creates a piece.
Parameters:pieces -The parent pieces object.
index -The position of this piece in the parent pieces object.
value -The value of this piece.
valueIndex -The position of this piece's value in the result of the pieces getValue call. Set to -1 to not include in getValue.
hidden -Whether the piece is visible to the current player or not.
| Field Detail |
Point boardPoint
The piece's position on the board (not on the screen).
Boolean hidden
Whether the piece is visible to the current player or not.
Number index
The position of this piece in the parent pieces object.
Pieces pieces
The parent pieces object.
Number valueIndex
The position of this piece's value in the result of the pieces getValue call. Based on the position. Set to -1 to not include in getValue.
| Method Detail |
StringBuilder appendHtml(/*StringBuilder*/ htmlBuilder)
Adds the pieces HTML to the a string builder. #returns The string builder after appending.
Parameters:htmlBuilder -The string builder to append to.
void center(/*Point*/ screenPoint,
/*Boolean*/ noConstrain)
Centers the piece on a point.
Parameters:screenPoint -The screen point on which to center.
noConstrain -(Optional) Override the game's
GamesByEmail.Game.constrainer rectangle.
static create(/*Pieces*/ pieces,
/*Number*/ index,
/*Number*/ value,
/*Number*/ valueIndex)
Returns a new piece object of the type.
Parameters:pieces -The parent pieces object.
index -The position of this piece in the parent pieces object.
value -The value of this piece.
valueIndex -The position of this piece's value in the result of the pieces getValue call. Set to -1 to not include in getValue.
dispose()
dispose in class Class
String elementId(/*String*/ id)
Returns an ID that is unique to this piece that can be used as HTML element IDs. No other piece of any class will generate the same ID even when passed the same parameter. The same piece will always generate the same ID when passed the same parameter.
Parameters:id -(Optional) The ID unique in the class to append to the globaly unique ID.
String event(/*String*/ code,
/*Boolean*/ delayed)
Returns code that can be used in DOM events to invoke methods and properties of the piece.
Parameters:code -The code of this piece to be executed. If no parameters passed, returns the fully qualified piece (to this).
delayed -Delay the event using window.setTimeout. Set to true if the HTML element invoking the event will be destroyed during the event.
Example:
// The following div will call the reset method of the piece when clicked.
htmlBuilder.append("<div onclick=\""+this.event("reset()")+"\">click here to reset piece</div>");
void getBoardValue(/*String*/ value,
/*Boolean*/ noReset)
Changes the pieces value (the type of piece it is).
Parameters:value -The new value of the piece.
noReset -(Optional) If true, the piece is not redrawn.
Rectangle getClipRect()
Gets the clipping rectangle for this piece based on its color value. #returns The clipping rectangle.
Element getElement(/*String*/ id)
Returns the HTML element that is unique to this piece.
Parameters:id -(Optional) The ID unique in the class.
String getImageSrc()
Gets the image file source for pieces in the game. Pieces should all be in the same file, with clipping rectangles defined. #returns The full path to the image file.
Rectangle getScreenRect(/*String*/ boardPoint)
Gets the screen rectangle for this piece based on its boardPoint property.
boardPoint -(Optional) If provided, calculates with this value instead of its internal
boardPoint property.
Number isColor()
Gets the color of this piece based on its value property.
#returns The color.
Boolean isOurs()
Determines if the piece color is the same as the current player's team color. #returns True if the colors are the same, else false.
void move(/*Point*/ boardPoint,
/*Boolean*/ hidden)
Moves the piece to a board point. The boardPoint property is updated.
boardPoint -The board point to which to move.
hidden -(Optional) Hide the piece from the current player. Defaults to visible.
Boolean occupiesBoardPoint(/*Point*/ boardPoint)
Determines if a piece occupies a board point.
Parameters:boardPoint -(Optional) The board point to check, or NULL if looking for an unplaced piece.
void remove()
Removes a piece.
void reset(/*String*/ boardValueOverride,
/*String*/ visibilityOverride)
Resets a piece to its boardPoint position and hidden state after a call to snap, center or setVisibility.
void setBoardValue(/*String*/ boardValue,
/*Boolean*/ noReset)
Changes the piece's board value (the color and type of piece it is).
Parameters:boardValue -The new board value of the piece.
noReset -(Optional) If true, the piece is not redrawn.
void setColor(/*Number*/ color,
/*Boolean*/ noReset)
Changes the piece's color.
Parameters:color -The new color of the piece.
noReset -(Optional) If true, the piece is not redrawn.
void setHidden(/*Boolean*/ hidden)
Sets the 'permanent' visibility of a piece.
Parameters:hidden -Hides the piece from the current player.
void setValue(/*String*/ value,
/*Boolean*/ noReset)
Changes the piece's value (the type of piece it is).
Parameters:value -The new value of the piece.
noReset -(Optional) If true, the piece is not redrawn.
void setValueAndColor(/*String*/ value,
/*Number*/ color,
/*Boolean*/ noReset)
Changes the piece's value and color.
Parameters:value -The new value of the piece.
color -The new color of the piece.
noReset -(Optional) If true, the piece is not redrawn.
void setVisibility(/*Boolean*/ hidden)
Sets the 'temporary' visibility of a piece.
Parameters:hidden -Hides the piece.
void snap(/*Point*/ boardPoint,
/*String*/ boardValueOverride)
Centers the piece on a board point. The boardPoint property is not altered.
boardPoint -The board point on which to center.
boardValueOverride -(Optional) If provided, renders the piece with this value instead of its internal
value property.