File: Games\GamesByEmail.js

Namespace GamesByEmail

Object
  
 
 
GamesByEmail

GamesByEmail

Namespace for all of GamesByEmail.com's classes.


Interface Summary
static InterfaceHex
An interface for games with a hexagonal board. Has precedent methods to for converting to and from screen points, and board point to value indices, path and looping. A class should also implement either GamesByEmail.HexH or GamesByEmail.HexV.

Class Summary
static ClassGame
Base class for all games.
static ClassGameNotify
The notification flag structure of GamesByEmail.Game.notify. Set appropriate flags for events in the game and players who have suscribed to those events will get notified.
static ClassGameStatus
The status structure of GamesByEmail.Game.status.
static ClassHexH
A background class for games with a hexagonal board having a horizontal axis, such as Triversi. The behind-the-scenes methods support the GamesByEmail.Hex class.
static ClassHexV
A background class for games with a hexagonal board having a vertical axis, such as McCooey Hex Chess. The behind-the-scenes methods support the GamesByEmail.Hex class.
static ClassInfo
A generic repository for key value pairs. Used to save state data in the game and team, and preferences for the player.
static ClassLogSettings
Log settings...
static ClassMove
Information about the last move.
static ClassPiece
A piece class for games like chess. May be used directly or extended.
static ClassPieces
A collection of pieces in a game, like chess. May be used directly or extended. Implemented as an Array.
static ClassPlayer
Information about a player.
static ClassPlayers
A collection of GamesByEmail.Player objects. Implemented as an Array.
static ClassTeam
Information about a team.
static ClassTeamNotify
The notification flag structure of GamesByEmail.Team.notify. Set appropriate flags for events in the game and players who have suscribed to those events will get notified.
static ClassTeamStatus
The status structure of GamesByEmail.Game.status.
static ClassTeams
A collection of GamesByEmail.Team objects. Implemented as an Array.
static ClassTerritories
A collection of territories in a game, like Gambit. May be used directly or extended. Implemented as an Array.
static ClassTerritory
A territory class for games like Gambit. May be used directly or extended.

Enum Summary
static NumberARROW_KEY_CODE
Arrow key codes for use against event.keyCode.
static StringCURSOR
Cross browser hand cursor value for element.style.cursor.
static NumberGAME_TYPE
Type of game, set in the GamesByEmail.Game.type field.

Function Summary
static StringclippedImageHtml(/*String*/ src, /*Rectangle*/ clipRect, /*String*/ styles, /*String*/ attibutes)
Generates the HTML necessary to show an inline clipped image.
static Booleandebug(/*String*/ value)
Writes a message to the first game on the page's message area.
static ObjectdeepCopy(/*Object*/ object)
Makes a simple classless copy of an object. Each sub object is copied as well.
static ArraydiceRolls(/*Number*/ num)
Returns an array of pseudo-random integers from 1 to 6 inclusive.
static NumberdieRoll()
Returns a pseudo-random integer from 1 to 6 inclusive.
static  elementHasIdInHierarchy(element, id)
static PointelementPageOffset(/*Element*/ element)
Gets the top left offset of an element from its layout parent.
static RectangleelementPageRectangle(/*Element*/ element)
Gets the rectangle of an element from its layout parent.
static StringelementTitleAttributes(/*String*/ title)
Generates HTML element attributes necessary to have an HTML hover title on an element.
static StringexpandingTextareaHtml(/*String*/ id, /*String*/ width, /*Number*/ lineHeight, /*Number*/ maxLines, /*String*/ additionalStyle, /*String*/ additionalAttributes)
Generates the HTML necessary for a textarea that displays as a single line, but grows (overlaying elements above it) as the user types. Used to generate the game message chat areas.
static GamefindFirstGame()
Finds the first game in the page.
static StringgetBestBwContrast(/*String*/ color)
Gets the best black or white contrast for a color.
static BooleangetBestBwContrast(/*Number*/ red, /*Number*/ blue, /*Number*/ green)
Tests for best black or white contrast for an r-g-b color triplet.
static StringgetHexString(/*Number*/ value, /*Number*/ minLength)
Converts a numeric value to a 0 padded hex string.
static StringimgSetClip(/*Element*/ Image, /*Number*/ positionX, /*Number*/ positionY, /*Number*/ clipX, /*Number*/ clipY, /*Number*/ clipWidth, /*Number*/ clipHeight)
Clips and positions an image element and/or returns the style properties necessary to clip an element. Low level, you should probably be using positionImage.
static BooleanisLeftButtonEvent(/*Event*/ event, /*Boolean*/ allowKeyboardModifier)
Cross-browser detection whether a mouse event is a left button event. Always pass true for allowKeyboardModifier.
static BooleanisMiddleButtonEvent(/*Event*/ event)
Cross-browser detection whether a mouse event is a middle button event.
static BooleanisRightButtonEvent(/*Event*/ event, /*Boolean*/ allowKeyboardModifier)
Cross-browser detection whether a mouse event is a right button event. Always pass true for allowKeyboardModifier.
static StringpositionImage(/*Element*/ element, /*Point|Rectangle*/ position, /*Rectangle*/ clipRect)
Clips and positions an image element and/or returns the style properties necessary to clip an element.
static Numberrandom(/*Number*/ high, /*Number*/ low)
Returns a pseudo-random integer between a low and a high, inclusive.
static ObjectshallowCopy(/*Object*/ object)
Makes a simple classless copy of an object. Sub object are not copied, but are shared between the instances.

Enum Detail

ARROW_KEY_CODE

static Number ARROW_KEY_CODE

Arrow key codes for use against event.keyCode.

Values:
LEFT - 
Left arrow.
RIGHT - 
Right arrow.
UP - 
Up arrow.
DOWN - 
Down arrow.

CURSOR

static String CURSOR

Cross browser hand cursor value for element.style.cursor.

Values:
HAND - 
Hand cursor.

GAME_TYPE

static Number GAME_TYPE

Type of game, set in the GamesByEmail.Game.type field.

Values:
CHESS - 
Chess.
BACKGAMMON - 
Backgammon.
CHECKERS - 
Checkers.
REVERSI - 
Reversi.
LINK_4 - 
Link 4.
ATAXX - 
Ataxx.
TWIXT - 
Twixt.
XIANGQI - 
Xiangqi.
DARK_CHESS - 
Dark chess.
OMEGA_CHESS - 
Omega Chess.
DARK_OMEGA_CHESS - 
Dark Omega Chess.
CHINESE_CHECKERS - 
Chinese checkers.
TRIVERSI - 
Triversi.
DEADGAMMON - 
Deadgammon.
HYPERGAMMON - 
Hypergammon.
NACKGAMMON - 
Nackgammon.
GAMBIT - 
Gambit.
DARK_GAMBIT - 
Dark Gambit.
BLIND_GAMBIT - 
Blind Gambit.
SPY_GAMBIT - 
Spy Gambit.
GIPF - 
GIPF.
ZERTZ - 
ZERTZ.
DVONN - 
DVONN.
DARK_XIANGQI - 
Dark Xiangqi.
TIC_TAC_TOE - 
Tic Tac Toe.
REFLEKTIT - 
Reflektit.
BLIND_TRIVERSI - 
Blind Triversi.
MCCOOEY_HEX_CHESS - 
Mccooey Hex Chess.
DARK_MCCOOEY_HEX_CHESS - 
Dark Mccooey Hex Chess.
GO - 
Go on an 19x19 board.
GO_13X13 - 
Go on a 13x13 board.
GO_9X9 - 
Go on a 9x9 board.
POLITICS - 
Politics.
WW2 - 
W.W.II
YINSH - 
YINSH.
BLITZ_YINSH - 
Blitz YINSH.
BYTE_8X8 - 
Byte on an 8x8 board.
BYTE_10X10 - 
Byte on a 10x10 board.
SNAG - 
Snag.
ELUDE - 
Elude.
DARK_ELUDE - 
Dark Elude.
PLOT - 
Plot.
DARK_PLOT - 
Dark Plot.
BLIND_PLOT - 
Blind Plot.
MERGERS - 
Mergers.
FIVES - 
Fives.
DARK_ATAXX - 
Dark Ataxx.
NINE_MENS_MORRIS - 
Nine Mens Morris.
TANBO - 
Tanbo.
DIPOLE - 
Dipole.
CEPHALOPOD - 
Cephalopod.
ATOLL - 
Atoll.
RUSH - 
Rush.
CROSSWAY - 
Crossway.
CROSSWAY_PIED - 
Crossway pied.
SCRIBE - 
Scribe.
SUPERGLYPH_SCRIBE - 
Scribe.
DIFFUSION - 
Diffusion.
COPOLYMER - 
Copolymer.
OUST_SQUARE_OLD - 
Oust (square on too big board).
BEGIRD - 
Begird.
BEGIRD_PIED - 
Begird pied.
PALISADE - 
Palisade.
IMPASSE - 
Impasse.
QUADRATURE - 
Quadrature.
MECHA - 
War Mechs.
EMPIRES - 
Empires.
LARIAT - 
Lariat.
LARIAT_PIED - 
Lariat pied.
VIKTORY2 - 
Viktory II.
ATOLL_PIED - 
Atoll pied.
LOOPHOLE_2D - 
Loophole 2D
GOMOKU - 
Gomoku
PLATEAU - 
Plateau
CAPTURE_THE_FLAG - 
Capture the flag.
BATTLE_BOATS - 
Battle Boats.
CAGE - 
Cage
OUST_SQUARE - 
Oust (square).
OUST_HEX - 
Oust (hex).
FLUME_SQUARE - 
Flume (square).
FLUME_SQUARE_PIED - 
Flume (square) pied.
FLUME_HEX - 
Flume (hex).
FLUME_HEX_PIED - 
Flume (hex) pied.
FRACTAL - 
Fractal.
X - 
X.
RIVE - 
Rive.
PHALANX - 
Phalanx

Function Detail

clippedImageHtml

static String clippedImageHtml(/*String*/ src,
                               /*Rectangle*/ clipRect,
                               /*String*/ styles,
                               /*String*/ attibutes)

Generates the HTML necessary to show an inline clipped image.

Parameters:
src - 
The image src.
clipRect - 
The clipping rectangle for the image.
styles - 
(Optional) Additional styles surrounding the image, as a CSS string.
attibutes - 
(Optional) Additional HTML attributes of the image.
Returns:
HTML that will show an inline clipped image.

debug

static Boolean debug(/*String*/ value)

Writes a message to the first game on the page's message area.

Parameters:
value - 
(Optional) The value to display. Call with no parameters to clear the message board.
Returns:
Always returns true.

deepCopy

static Object deepCopy(/*Object*/ object)

Makes a simple classless copy of an object. Each sub object is copied as well.

Parameters:
object - 
The object to copy.
Returns:
A copy of the object passed.
See Also:
shallowCopy

diceRolls

static Array diceRolls(/*Number*/ num)

Returns an array of pseudo-random integers from 1 to 6 inclusive.

Parameters:
num - 
The number of die rolls to return.
Returns:
An array of num numbers number greater than or equal to 1 and less than or equal to 6, generated locally from Math.random.
See Also:
GamesByEmail.Game.diceRolls

dieRoll

static Number dieRoll()

Returns a pseudo-random integer from 1 to 6 inclusive.

Returns:
A number greater than or equal to 1 and less than or equal to 6, generated locally from Math.random.
See Also:
GamesByEmail.Game.dieRoll

elementHasIdInHierarchy

static elementHasIdInHierarchy(element,
                               id)
Parameters:
element - 

id - 


elementPageOffset

static Point elementPageOffset(/*Element*/ element)

Gets the top left offset of an element from its layout parent.

Parameters:
element - 
The document element to check.
Returns:
A point where x is the left offset, and y is the top offset.
See Also:
elementPageRectangle

elementPageRectangle

static Rectangle elementPageRectangle(/*Element*/ element)

Gets the rectangle of an element from its layout parent.

Parameters:
element - 
The document element to check.
Returns:
A rectangle where x is the left offset, and y is the top offset, and the width and height match that of the element.
See Also:
elementPageOffset

elementTitleAttributes

static String elementTitleAttributes(/*String*/ title)

Generates HTML element attributes necessary to have an HTML hover title on an element.

Parameters:
title - 
The HTML to dislpay when the user hovers the mouse over the element.
Returns:
The attributes for the title. These include onmouseover, onmouseout and onmousemove assignments.

Example:

var title="<H1>Big bold hover title!</H1>";
html+="<div "+GamesByEmail.elementTitleAttributes(title)+">Hover here to see big text.</div>";

expandingTextareaHtml

static String expandingTextareaHtml(/*String*/ id,
                                    /*String*/ width,
                                    /*Number*/ lineHeight,
                                    /*Number*/ maxLines,
                                    /*String*/ additionalStyle,
                                    /*String*/ additionalAttributes)

Generates the HTML necessary for a textarea that displays as a single line, but grows (overlaying elements above it) as the user types. Used to generate the game message chat areas.

Parameters:
id - 
The id of the element.
width - 
The width of the element, as a CSS string.
lineHeight - 
The height of a line of text. 16 seems to work well.
maxLines - 
The maximum number of lines to grow. After this size is reached, the contents will start scrolling.
additionalStyle - 
(Optional) Any additional style attributes to add, as a CSS string.
additionalAttributes - 
(Optional) Any additional attributes to add.
Returns:
Cross-browser HTML for a TEXTAREA element that expands when typed into.

findFirstGame

static Game findFirstGame()

Finds the first game in the page.

Returns:
The first game.

getBestBwContrast

static String getBestBwContrast(/*String*/ color)

Gets the best black or white contrast for a color.

Parameters:
color - 
The color to test in '#hhhhhh' format.
Returns:
black or white in '#hhhhhh' format.

getBestBwContrast

static Boolean getBestBwContrast(/*Number*/ red,
                                 /*Number*/ blue,
                                 /*Number*/ green)

Tests for best black or white contrast for an r-g-b color triplet.

Parameters:
red - 
The red component of the color [0-255].
blue - 
The green component of the color [0-255].
green - 
The blue component of the color [0-255].
Returns:
true if black is a better contrast.

getHexString

static String getHexString(/*Number*/ value,
                           /*Number*/ minLength)

Converts a numeric value to a 0 padded hex string.

Parameters:
value - 
The value to convert.
minLength - 
(Optional) The minimum string length returned. Leading 0s are padded if necessary to meet this length.
Returns:
The hex string (without a leading 0x).

imgSetClip

static String imgSetClip(/*Element*/ Image,
                         /*Number*/ positionX,
                         /*Number*/ positionY,
                         /*Number*/ clipX,
                         /*Number*/ clipY,
                         /*Number*/ clipWidth,
                         /*Number*/ clipHeight)

Clips and positions an image element and/or returns the style properties necessary to clip an element. Low level, you should probably be using positionImage.

Parameters:
Image - 
element to clip or null.
positionX - 
The x position of image.
positionY - 
The y position of image.
clipX - 
The x position of the clipping.
clipY - 
The y position of the clipping.
clipWidth - 
The width of the clipping.
clipHeight - 
The height of the clipping.
Returns:
A CSS style string with the attributes necessary to position and clip a image.

Example:

// Both examples will position an image left/top at 20,30 clipped to show only the
//  part of the image from 5,12 to 7,18 (clipped width of 3, height of 7).
 
//To clip an existing image element:
var myImage=game.getElement("myImage");
GamesByEmail.imgSetClip(myImage,20,30,5,12,3,7);
 
//To build HTML for a new image element. Note null passed for first parameter.
html+="<IMG src=\"myImage.gif\" style=\""+GamesByEmail.imgSetClip(null,20,30,5,12,3,7)+"\">";
See Also:
positionImage

isLeftButtonEvent

static Boolean isLeftButtonEvent(/*Event*/ event,
                                 /*Boolean*/ allowKeyboardModifier)

Cross-browser detection whether a mouse event is a left button event. Always pass true for allowKeyboardModifier.

Parameters:
event - 
The document event object.
allowKeyboardModifier - 
Allow a CTRL-Left click equal a right click. Some crappy browsers do not allow capture of right click events.

isMiddleButtonEvent

static Boolean isMiddleButtonEvent(/*Event*/ event)

Cross-browser detection whether a mouse event is a middle button event.

Parameters:
event - 
The document event object.

isRightButtonEvent

static Boolean isRightButtonEvent(/*Event*/ event,
                                  /*Boolean*/ allowKeyboardModifier)

Cross-browser detection whether a mouse event is a right button event. Always pass true for allowKeyboardModifier.

Parameters:
event - 
The document event object.
allowKeyboardModifier - 
Allow a CTRL-Left click to equal a right click. Some crappy browsers do not allow capture of right click events.

positionImage

static String positionImage(/*Element*/ element,
                            /*Point|Rectangle*/ position,
                            /*Rectangle*/ clipRect)

Clips and positions an image element and/or returns the style properties necessary to clip an element.

Parameters:
element - 
Image element to clip or null.
position - 
The center of where to position the image.
clipRect - 
The clipping rectangle for the image.
Returns:
A CSS style string with the attributes necessary to position and clip a image.

Example:

// Both examples will position an image *centered* at 20,30 clipped to show only the
//  part of the image from 5,12 to 7,18 (clipped width of 3, height of 7).
var center=new Foundation.Point(20,30);
var clip=new Foundation.Rectangle(5,12,3,7);
 
//To clip an existing image element:
var myImage=game.getElement("myImage");
GamesByEmail.positionImage(myImage,center,clip);
 
//To build HTML for a new image element. Note null passed for first parameter.
html+="<IMG src=\"myImage.gif\" style=\""+GamesByEmail.positionImage(null,center,clip)+"\">";

random

static Number random(/*Number*/ high,
                     /*Number*/ low)

Returns a pseudo-random integer between a low and a high, inclusive.

Parameters:
high - 
The highest value to be returned.
low - 
(Optional) The lowest value to be returned (defaults to zero).
Returns:
A number greater than or equal to low and less than or equal to high, generated locally from Math.random.
See Also:
GamesByEmail.Game.random

shallowCopy

static Object shallowCopy(/*Object*/ object)

Makes a simple classless copy of an object. Sub object are not copied, but are shared between the instances.

Parameters:
object - 
The object to copy.
Returns:
A copy of the object passed.
See Also:
deepCopy