File: Games\GamesByEmail.js

GamesByEmail
Class Piece

Object
  
 
 
GamesByEmail.Piece

All Implemented Interfaces:

Class


GamesByEmail.Piece

implements Foundation.Class

A piece class for games like chess. May be used directly or extended.

See Also:

GamesByEmail.Pieces

Constructor Summary
GamesByEmail.Piece(/*Pieces*/ pieces, /*Number*/ index, /*Number*/ value, /*Number*/ valueIndex, /*Boolean*/ hidden)
Creates a piece.

Field Summary
PointboardPoint
The piece's position on the board (not on the screen).
Booleanhidden
Whether the piece is visible to the current player or not.
Numberindex
The position of this piece in the parent pieces object.
Piecespieces
The parent pieces object.
NumbervalueIndex
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
StringBuilderappendHtml(/*StringBuilder*/ htmlBuilder)
Adds the pieces HTML to the a string builder. #returns The string builder after appending.
voidcenter(/*Point*/ screenPoint, /*Boolean*/ noConstrain)
Centers the piece on a point.
static  create(/*Pieces*/ pieces, /*Number*/ index, /*Number*/ value, /*Number*/ valueIndex)
Returns a new piece object of the type.
 dispose()
StringelementId(/*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.
Stringevent(/*String*/ code, /*Boolean*/ delayed)
Returns code that can be used in DOM events to invoke methods and properties of the piece.
voidgetBoardValue(/*String*/ value, /*Boolean*/ noReset)
Changes the pieces value (the type of piece it is).
RectanglegetClipRect()
Gets the clipping rectangle for this piece based on its color value. #returns The clipping rectangle.
ElementgetElement(/*String*/ id)
Returns the HTML element that is unique to this piece.
StringgetImageSrc()
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.
RectanglegetScreenRect(/*String*/ boardPoint)
Gets the screen rectangle for this piece based on its boardPoint property.
NumberisColor()
Gets the color of this piece based on its value property. #returns The color.
BooleanisOurs()
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.
voidmove(/*Point*/ boardPoint, /*Boolean*/ hidden)
Moves the piece to a board point. The boardPoint property is updated.
BooleanoccupiesBoardPoint(/*Point*/ boardPoint)
Determines if a piece occupies a board point.
voidremove()
Removes a piece.
voidreset(/*String*/ boardValueOverride, /*String*/ visibilityOverride)
Resets a piece to its boardPoint position and hidden state after a call to snap, center or setVisibility.
voidsetBoardValue(/*String*/ boardValue, /*Boolean*/ noReset)
Changes the piece's board value (the color and type of piece it is).
voidsetColor(/*Number*/ color, /*Boolean*/ noReset)
Changes the piece's color.
voidsetHidden(/*Boolean*/ hidden)
Sets the 'permanent' visibility of a piece.
voidsetValue(/*String*/ value, /*Boolean*/ noReset)
Changes the piece's value (the type of piece it is).
voidsetValueAndColor(/*String*/ value, /*Number*/ color, /*Boolean*/ noReset)
Changes the piece's value and color.
voidsetVisibility(/*Boolean*/ hidden)
Sets the 'temporary' visibility of a piece.
voidsnap(/*Point*/ boardPoint, /*String*/ boardValueOverride)
Centers the piece on a board point. The boardPoint property is not altered.

Methods inherited from Foundation.Class
getTypePath, isInstanceOf

Constructor Detail

Piece

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

boardPoint

Point boardPoint

The piece's position on the board (not on the screen).


hidden

Boolean hidden

Whether the piece is visible to the current player or not.


index

Number index

The position of this piece in the parent pieces object.


pieces

Pieces pieces

The parent pieces object.


valueIndex

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

appendHtml

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.

center

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.

create

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()
Overrides:
dispose in class Class

elementId

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.
Returns:
An ID that unique to this piece.
See Also:
getElement

event

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.
Returns:
The fully qualified code string for the event of the piece.

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>");

getBoardValue

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.

getClipRect

Rectangle getClipRect()

Gets the clipping rectangle for this piece based on its color value. #returns The clipping rectangle.


getElement

Element getElement(/*String*/ id)

Returns the HTML element that is unique to this piece.

Parameters:
id - 
(Optional) The ID unique in the class.
Returns:
The HTML element with the ID.
See Also:
elementId

getImageSrc

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.


getScreenRect

Rectangle getScreenRect(/*String*/ boardPoint)

Gets the screen rectangle for this piece based on its boardPoint property.

Parameters:
boardPoint - 
(Optional) If provided, calculates with this value instead of its internal boardPoint property.

isColor

Number isColor()

Gets the color of this piece based on its value property. #returns The color.


isOurs

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.


move

void move(/*Point*/ boardPoint,
          /*Boolean*/ hidden)

Moves the piece to a board point. The boardPoint property is updated.

Parameters:
boardPoint - 
The board point to which to move.
hidden - 
(Optional) Hide the piece from the current player. Defaults to visible.

occupiesBoardPoint

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.
Returns:
TRUE if the board point is occupied by the piece, and FALSE otherwise.

remove

void remove()

Removes a piece.


reset

void reset(/*String*/ boardValueOverride,
           /*String*/ visibilityOverride)

Resets a piece to its boardPoint position and hidden state after a call to snap, center or setVisibility.

Parameters:
boardValueOverride - 
(Optional) If provided, renders the piece with this value instead of its internal value property.
visibilityOverride - 
(Optional) If provided, renders the piece with this visibility instead of its internal hidden property.

setBoardValue

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.

setColor

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.

setHidden

void setHidden(/*Boolean*/ hidden)

Sets the 'permanent' visibility of a piece.

Parameters:
hidden - 
Hides the piece from the current player.

setValue

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.

setValueAndColor

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.

setVisibility

void setVisibility(/*Boolean*/ hidden)

Sets the 'temporary' visibility of a piece.

Parameters:
hidden - 
Hides the piece.

snap

void snap(/*Point*/ boardPoint,
          /*String*/ boardValueOverride)

Centers the piece on a board point. The boardPoint property is not altered.

Parameters:
boardPoint - 
The board point on which to center.
boardValueOverride - 
(Optional) If provided, renders the piece with this value instead of its internal value property.