File: Games\Chess\Game.js

GamesByEmail
Class ChessGame

Object
  
 
 
GamesByEmail.Game
 
 
GamesByEmail.ChessGame

All Implemented Interfaces:

Class, Elemental, Resourceful, Server


GamesByEmail.ChessGame

extends Game

Nested Class Summary
static ClassChessGame.MoveData

Constructor Summary
GamesByEmail.ChessGame()

Field Summary
static ObjectresourcePack
Resources for most of the game. Override to add resources specific to game.

Fields inherited from GamesByEmail.Game
board, canPie, constrainer, font, id, info, isLog, lastMove, logSettings, maxMoveNumber, message, move, notify, onLeftMouseDown, onLeftMouseUp, onMiddleMouseDown, onMiddleMouseUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onRightMouseDown, onRightMouseUp, pieces, previewing, rotation, status, teams, territories, testing, title, type, verbose

Fields inherited from Foundation.Elemental
$Foundation_$registry_index

Method Summary
 canMove(moveData, color)
 canMoveFrom(fromPoint, moveData, color)
 canMoveFromTo(toPoint, fromPoint, moveData, color)
 checkForCheck(point, moveData, color)
 checkForKing(board, color)
BooleancheckMove(/*Point*/ toPoint, /*Point*/ fromPoint)
Checks to see if a move is legal. By default calls isMoveLegal.
 checkPieceVisibility(piecePoint, toPoint, moveData, color)
 checkPointThreat(piecePoint, toPoint, moveData, color)
 checkVisibility(point, moveData, color)
StringcompleteYourTurnHtml(/*String*/ resourceName)
Called when needing the complete-your-turn game prompt HTML (typically a short sentence about the move and a Send This Move button). Override and set mouse events here. Internally uses the "completeYourTurn" resource.
StringcontinueYourTurnHtml(/*String*/ resourceName)
Called when needing the continue-your-turn game prompt HTML (typically a short sentence about the move, no send move button yet). Override and set mouse events here. Internally uses the "continueYourTurn" resource.
 dispose()
 dragByClicks(up, origPoint, screenPoint)
StringdrawDeclinedHeaderHtml(/*String*/ resourceName)
Called when needing the draw-declined header HTML. Override to set. Internally uses the "drawDeclinedHeader" resource.
StringdrawOfferedHeaderHtml(/*String*/ resourceName)
Called when needing the draw-offered header HTML. Override to set. Internally uses the "drawOfferedHeader" resource.
 getMoveData(board)
StringgetTeamTitleHtml(/*Team*/ team, /*Boolean*/ top)
Gets the HTML for the team title on the board. By default uses resources 'turnTeamTitle' or 'teamTitle'.
 hideSquares(point, moveData, color, htmlBuilder)
 hideSquaresShowHilites(moveData, hilites, color)
voidinitialize(/*Number*/ numPlayers, /*Number*/ turnTeamIndex)
The first method to be called when a game is created, override to set up teams, players and the game state.
 isBishopMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
PointisBoardPointHidden(/*Point*/ boardPoint)
Returns whether the board point is hidden from the current player, for games like Dark Chess.
 isInCheck(moveData, color)
 isKingMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
 isKnightMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
 isMoveLegal(toPoint, fromPoint, moveData, checkCheck, visibility)
 isOurKing(point, board, color)
 isOurRook(point, board, color)
 isPawnMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
 isPointThreatened(point, moveData, color)
 isQueenMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
 isRookMoveLegal(toPoint, fromPoint, moveData, piece, color, movement, visibility)
StringitsYourTurnHtml(/*String*/ resourceName)
Called when needing the it-is-your-turn game prompt HTML (typically a short sentence about the move). Override and set mouse events here. Internally uses the "itIsYourTurnToMove" resource.
 makeLegalMove(toPoint, fromPoint, moveData, piece)
 mouseDown(screenPoint)
 mouseMove(screenPoint)
 mouseUp(screenPoint)
 mustPromotePiece(piece)
StringnotYourTurnHtml(/*String*/ resourceName)
Called when needing the it-is-not-your-turn game prompt HTML (typically a short sentence with Send Reminder, Refresh Game and Close Window buttons Start Another Game button). Override to set. Internally uses the "notYourTurn" resource.
 pieceNotation(pieceChar)
 promoteHtml()
 promotePiece(value)
 promotingPieceHtml(piece)
voidresign()
Resignes the current player. Clears mouse events, sets the player as resigned, and sends the move.
BooleansendMove(/*Boolean*/ sendNow, /*Player*/ player)
Gets called when the Send Move button is pushed. Override and set the game state, then call Super.sendMove.
 setMoveData(moveData)
voidsetPerspective(/*Team*/ team)
Called when synchronizing, sets the perspective of the board based on the player. By default sets the rotation property to 0.
 spaceNotation(x, y)
voidsynch()
Called when the game should synchronize with info properties from the server.
voidsynchTeam(/*Team*/ team)
Called to synchronize the team properties with the raw team data. Just the color and title properties are set by default, override to set more.
 takenValueFromPointBoard(point, board)
StringtieGameHeaderHtml(/*String*/ resourceName)
Called when needing the tie-game header HTML. Override to set. Internally uses the "tieGameHeader" resource.
StringturnHeaderHtml(/*String*/ resourceName)
Called when needing the it's-your-turn header HTML. Override to set. Internally uses the "turnHeader" resource.
StringwonHeaderHtml(/*String*/ resourceName)
Called when needing the won-game header HTML. Override to set. Internally uses the "wonHeader" resource.
StringyouLoseHtml(/*String*/ resourceName)
Called when needing the you-lose game prompts HTML. Override to set. Internally uses the "youLose" resource.
StringyouTiedHtml(/*String*/ resourceName)
Called when needing the you-tied game prompts HTML. Override to set. Internally uses the "youTie" resource.

Methods inherited from GamesByEmail.Game
aboveTeamTitleRowHtml, acceptDeclineDrawHtml, acceptDraw, acceptDrawButtonHtml, addNote, addToPage, appendAdditionalPreferencesHtml, appendBoardHtml, beginTurnHtml, belowTeamTitleRowHtml, boardPointFromScreenPoint, boardPointFromScreenXY, boardPointFromValueIndex, boardValueFromValueColor, cancelGameButtonHtml, cancelGameHtml, clearHilites, clearMouseEvents, closeWindowButtonHtml, closeWindowHtml, colorFromBoardValue, colorFromPointBoard, colorFromXYBoard, completeTurnHtml, constrainPoint, constrainRectangle, continueTurnHtml, debug, diceRolls, dieRoll, drawAcceptedHeaderHtml, drawAcceptedHtml, drawDeclinedHtml, elementTitleAttributes, findNextPlayer, findPlayer, findWinningTeam, forEachBoardPoint, forEachTeam, gameInProgressHeaderHtml, gameOverHeaderHtml, gameOverHtml, getActionLinksHtml, getAnchorHtml, getButtonHtml, getCheckboxHtml, getGamePromptsHtml, getHeaderHtml, getHtml, getHtmlButtonHtml, getImageSrc, getNewGamePlayerOrder, getNextGamesTitle, getOptionHtml, getPieType, getPieceRect, getPieceSrc, getRadioHtml, getSelectHtml, getSpectatorAnchorHtml, getSpectatorUrl, getTeamAtDistance, getTeamFontColor, getTeamLogFontBgColor, getTeamLogFontColor, getTeamTitleAlignment, getTeamTitlesHtml, getTeamsForTitles, getTextHtml, getTextareaHtml, getTurnHtml, getTurnTeam, getVButtonHtml, handleMoveCollision, hiliteImageHtml, initializeNewGameForm, isColorAtPoint, isColorAtXY, isMyTurn, isPathClear, isPointBoardClear, isPointOnBoard, isValueColorAtPoint, isValueColorAtXY, isXYBoardClear, isXYOnBoard, maybePie, maybeResign, movePiece, nextTeam, numInPath, numTeamsPlaying, offerDrawCheckBoxHtml, offerDrawHtml, openLogAnchorHtml, openPlayerChatAnchorHtml, openPreferencesAnchorHtml, openRulesAnchorHtml, pie, pieButtonHtml, pieHtml, processSecureMove, refreshGame, refreshGameButtonHtml, reportProblemAnchorHtml, resignButtonHtml, resignHtml, resignedHeaderHtml, screenRectFromBoardPoint, screenRectFromBoardXY, sendMoveButtonHtml, sendMoveHtml, sendReminderButtonHtml, setConstrainer, setEnded, setFloatHtml, setInnerHtml, setMouseHtml, setPlayerPrefs, setValueAtPoint, setValueAtXY, showTransactionPrompt, spectatingHtml, startAnotherGameButtonHtml, startAnotherGameHtml, teamColorFromTeam, theyResignedHtml, titleFromTeamColor, transformHashLinksToOnClicks, undo, undoButtonHtml, undoMoveHtml, update, updateTeamTitles, valueFromBoardValue, valueFromPointBoard, valueFromXYBoard, valueIndexFromBoardPoint, valueIndexFromBoardXY, youResignedHtml, youWinHtml

Methods inherited from Foundation.Class
getTypePath, isInstanceOf

Methods inherited from Foundation.Elemental
attachEvent, detachEvent, elementId, event, getById, getElement, getElementValue, getElements, getFirst, getNext, parseElementId, processHtml, processHtml

Methods inherited from Foundation.Resourceful
resource, resource, resourceUrl, resourceUrl

Methods inherited from Foundation.Server
server, serverSerialized, serverSynchronous

Constructor Detail

ChessGame

GamesByEmail.ChessGame()

Field Detail

resourcePack

static Object resourcePack

Resources for most of the game. Override to add resources specific to game.

Overrides:
resourcePack in class Game
See Also:
Foundation.Resourceful.resource

Method Detail

canMove

canMove(moveData,
        color)
Parameters:
moveData - 

color - 


canMoveFrom

canMoveFrom(fromPoint,
            moveData,
            color)
Parameters:
fromPoint - 

moveData - 

color - 


canMoveFromTo

canMoveFromTo(toPoint,
              fromPoint,
              moveData,
              color)
Parameters:
toPoint - 

fromPoint - 

moveData - 

color - 


checkForCheck

checkForCheck(point,
              moveData,
              color)
Parameters:
point - 

moveData - 

color - 


checkForKing

checkForKing(board,
             color)
Parameters:
board - 

color - 


checkMove

Boolean checkMove(/*Point*/ toPoint,
                  /*Point*/ fromPoint)

Checks to see if a move is legal. By default calls isMoveLegal.

Overrides:
checkMove in class Game
Parameters:
toPoint - 
The board point moving to.
fromPoint - 
The board point moving from.
Returns:
true if the move is legal.
See Also:
isMoveLegal

checkPieceVisibility

checkPieceVisibility(piecePoint,
                     toPoint,
                     moveData,
                     color)
Parameters:
piecePoint - 

toPoint - 

moveData - 

color - 


checkPointThreat

checkPointThreat(piecePoint,
                 toPoint,
                 moveData,
                 color)
Parameters:
piecePoint - 

toPoint - 

moveData - 

color - 


checkVisibility

checkVisibility(point,
                moveData,
                color)
Parameters:
point - 

moveData - 

color - 


completeYourTurnHtml

String completeYourTurnHtml(/*String*/ resourceName)

Called when needing the complete-your-turn game prompt HTML (typically a short sentence about the move and a Send This Move button). Override and set mouse events here. Internally uses the "completeYourTurn" resource.

Overrides:
completeYourTurnHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the game prompts.

continueYourTurnHtml

String continueYourTurnHtml(/*String*/ resourceName)

Called when needing the continue-your-turn game prompt HTML (typically a short sentence about the move, no send move button yet). Override and set mouse events here. Internally uses the "continueYourTurn" resource.

Overrides:
continueYourTurnHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the game prompts.

dispose

dispose()
Overrides:
dispose in class Game

dragByClicks

dragByClicks(up,
             origPoint,
             screenPoint)
Parameters:
up - 

origPoint - 

screenPoint - 


drawDeclinedHeaderHtml

String drawDeclinedHeaderHtml(/*String*/ resourceName)

Called when needing the draw-declined header HTML. Override to set. Internally uses the "drawDeclinedHeader" resource.

Overrides:
drawDeclinedHeaderHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

drawOfferedHeaderHtml

String drawOfferedHeaderHtml(/*String*/ resourceName)

Called when needing the draw-offered header HTML. Override to set. Internally uses the "drawOfferedHeader" resource.

Overrides:
drawOfferedHeaderHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

getMoveData

getMoveData(board)
Parameters:
board - 


getTeamTitleHtml

String getTeamTitleHtml(/*Team*/ team,
                        /*Boolean*/ top)

Gets the HTML for the team title on the board. By default uses resources 'turnTeamTitle' or 'teamTitle'.

Overrides:
getTeamTitleHtml in class Game
Parameters:
team - 
The team to get the color for.
top - 
Whether this team's title will be displayed above the board or below.
Returns:
The log background color.

hideSquares

hideSquares(point,
            moveData,
            color,
            htmlBuilder)
Parameters:
point - 

moveData - 

color - 

htmlBuilder - 


hideSquaresShowHilites

hideSquaresShowHilites(moveData,
                       hilites,
                       color)
Parameters:
moveData - 

hilites - 

color - 


initialize

void initialize(/*Number*/ numPlayers,
                /*Number*/ turnTeamIndex)

The first method to be called when a game is created, override to set up teams, players and the game state.

Overrides:
initialize in class Game
Parameters:
numPlayers - 
The number of players from the game form.
turnTeamIndex - 
The index of the team to set the initial turn. Call the Super with -1 to set all teams turn.

Example:

// Override initialize
   initialize:function(numPlayers,turnTeamIndex)
   {
      // Call the Super.initialize to add default teams.
      Super.initialize(numPlayers,turnTeamIndex);
 
      // Initialize the board state.
      this.info["board"]="rnbqkbnrpppppppp                                PPPPPPPPRNBQKBNR";
      var team=this.teams[0];
      team.info["i_ep"]=-1;
      team.info["b_cs"]=true;
      team.info["b_cl"]=true;
      team=this.teams[1];
      team.info["i_ep"]=-1;
      team.info["b_cs"]=true;
      team.info["b_cl"]=true;
      
      // Log the start of game.
      this.move.log=this.logEntry(44);
   }

isBishopMoveLegal

isBishopMoveLegal(toPoint,
                  fromPoint,
                  moveData,
                  piece,
                  color,
                  movement,
                  visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


isBoardPointHidden

Point isBoardPointHidden(/*Point*/ boardPoint)

Returns whether the board point is hidden from the current player, for games like Dark Chess.

Overrides:
isBoardPointHidden in class Game
Parameters:
boardPoint - 
The board point.
Returns:
The board point.

isInCheck

isInCheck(moveData,
          color)
Parameters:
moveData - 

color - 


isKingMoveLegal

isKingMoveLegal(toPoint,
                fromPoint,
                moveData,
                piece,
                color,
                movement,
                visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


isKnightMoveLegal

isKnightMoveLegal(toPoint,
                  fromPoint,
                  moveData,
                  piece,
                  color,
                  movement,
                  visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


isMoveLegal

isMoveLegal(toPoint,
            fromPoint,
            moveData,
            checkCheck,
            visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

checkCheck - 

visibility - 


isOurKing

isOurKing(point,
          board,
          color)
Parameters:
point - 

board - 

color - 


isOurRook

isOurRook(point,
          board,
          color)
Parameters:
point - 

board - 

color - 


isPawnMoveLegal

isPawnMoveLegal(toPoint,
                fromPoint,
                moveData,
                piece,
                color,
                movement,
                visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


isPointThreatened

isPointThreatened(point,
                  moveData,
                  color)
Parameters:
point - 

moveData - 

color - 


isQueenMoveLegal

isQueenMoveLegal(toPoint,
                 fromPoint,
                 moveData,
                 piece,
                 color,
                 movement,
                 visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


isRookMoveLegal

isRookMoveLegal(toPoint,
                fromPoint,
                moveData,
                piece,
                color,
                movement,
                visibility)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 

color - 

movement - 

visibility - 


itsYourTurnHtml

String itsYourTurnHtml(/*String*/ resourceName)

Called when needing the it-is-your-turn game prompt HTML (typically a short sentence about the move). Override and set mouse events here. Internally uses the "itIsYourTurnToMove" resource.

Overrides:
itsYourTurnHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the game prompts.

makeLegalMove

makeLegalMove(toPoint,
              fromPoint,
              moveData,
              piece)
Parameters:
toPoint - 

fromPoint - 

moveData - 

piece - 


mouseDown

mouseDown(screenPoint)
Parameters:
screenPoint - 


mouseMove

mouseMove(screenPoint)
Parameters:
screenPoint - 


mouseUp

mouseUp(screenPoint)
Parameters:
screenPoint - 


mustPromotePiece

mustPromotePiece(piece)
Parameters:
piece - 


notYourTurnHtml

String notYourTurnHtml(/*String*/ resourceName)

Called when needing the it-is-not-your-turn game prompt HTML (typically a short sentence with Send Reminder, Refresh Game and Close Window buttons Start Another Game button). Override to set. Internally uses the "notYourTurn" resource.

Overrides:
notYourTurnHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the game prompts.

pieceNotation

pieceNotation(pieceChar)
Parameters:
pieceChar - 


promoteHtml

promoteHtml()

promotePiece

promotePiece(value)
Parameters:
value - 


promotingPieceHtml

promotingPieceHtml(piece)
Parameters:
piece - 


resign

void resign()

Resignes the current player. Clears mouse events, sets the player as resigned, and sends the move.

Overrides:
resign in class Game

sendMove

Boolean sendMove(/*Boolean*/ sendNow,
                 /*Player*/ player)

Gets called when the Send Move button is pushed. Override and set the game state, then call Super.sendMove.

Overrides:
sendMove in class Game
Parameters:
sendNow - 
(Optional) Send the moves to the server now. Else, save the move for sending later. Defaults to true.
player - 
(Optional) The player responsible for the move. Defaults to the current player (game.player).
Returns:
true.

setMoveData

setMoveData(moveData)
Parameters:
moveData - 


setPerspective

void setPerspective(/*Team*/ team)

Called when synchronizing, sets the perspective of the board based on the player. By default sets the rotation property to 0.

Overrides:
setPerspective in class Game
Parameters:
team - 
The team to synchronize.

spaceNotation

spaceNotation(x,
              y)
Parameters:
x - 

y - 


synch

void synch()

Called when the game should synchronize with info properties from the server.

Overrides:
synch in class Game
Notes:
The game should set tangible properties or states for each custom property set in the info collection. The info collection should not be referenced outside the scope of the synch or sendMove methods.

synchTeam

void synchTeam(/*Team*/ team)

Called to synchronize the team properties with the raw team data. Just the color and title properties are set by default, override to set more.

Overrides:
synchTeam in class Game
Parameters:
team - 
The team to synchronize.

takenValueFromPointBoard

takenValueFromPointBoard(point,
                         board)
Parameters:
point - 

board - 


tieGameHeaderHtml

String tieGameHeaderHtml(/*String*/ resourceName)

Called when needing the tie-game header HTML. Override to set. Internally uses the "tieGameHeader" resource.

Overrides:
tieGameHeaderHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

turnHeaderHtml

String turnHeaderHtml(/*String*/ resourceName)

Called when needing the it's-your-turn header HTML. Override to set. Internally uses the "turnHeader" resource.

Overrides:
turnHeaderHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

wonHeaderHtml

String wonHeaderHtml(/*String*/ resourceName)

Called when needing the won-game header HTML. Override to set. Internally uses the "wonHeader" resource.

Overrides:
wonHeaderHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

youLoseHtml

String youLoseHtml(/*String*/ resourceName)

Called when needing the you-lose game prompts HTML. Override to set. Internally uses the "youLose" resource.

Overrides:
youLoseHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.

youTiedHtml

String youTiedHtml(/*String*/ resourceName)

Called when needing the you-tied game prompts HTML. Override to set. Internally uses the "youTie" resource.

Overrides:
youTiedHtml in class Game
Parameters:
resourceName - 
(Optional) A resource name to override the default resource to use.
Returns:
HTML for the header.