File: Games\CaptureTheFlag\Game.js

GamesByEmail
Class CaptureTheFlagGame

Object
  
 
 
GamesByEmail.Game
 
 
GamesByEmail.CaptureTheFlagGame

All Implemented Interfaces:

Class, Elemental, Resourceful, Server


GamesByEmail.CaptureTheFlagGame

extends Game

Constructor Summary
GamesByEmail.CaptureTheFlagGame()

Enum Summary
static  PIECE_TYPE

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

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
 addToTaken(team, piece)
 apparentValueFromMove(fromPoint, toPoint, publicBoard, privateBoard)
 areThereMultipleUnknownPieces(defaultValue, publicBoard, privateBoard)
 canMoveFrom(fromPoint, board, color)
BooleancheckMove(/*Point*/ toPoint, /*Point*/ fromPoint)
Checks to see if a move is legal. By default calls isMoveLegal.
 checkSetupMove(toPoint, fromPoint)
 clearSetup()
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.
 convertBoardValueToSetup(boardValue)
 convertSetupToBoardValue(setup, color)
 dispose()
 dragByClicks(up, origPoint, screenPoint)
 flipSetup()
 getAttackBoardHtml(attackerColor, attackerPoint, defenderPoint, newAttack, forceResolution)
 getAttackInfo(team, boardPoint)
 getAttackPiece()
 getCombinedBoardState()
 getStartBoard(color)
StringgetTeamTitleHtml(/*Team*/ team, /*Boolean*/ top)
Gets the HTML for the team title on the board. By default uses resources 'turnTeamTitle' or 'teamTitle'.
voidhandleMoveCollision(/*Object*/ gameData, /*Array*/ collisionMoves)
Override to handle move collisions from concurrent turns.
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.
 isExactValueUnknown(value)
 isLake(boardPoint)
 isMoveLegal(toPoint, fromPoint, board, color)
 isMoveablePiece(piece)
 isSetupChoked(board, color)
 isSetupComplete(board, color)
 isSetupFilled(board, color)
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.
 makeColorHidden(value, color)
 mouseDown(screenPoint)
 mouseMove(screenPoint)
 mouseUp(screenPoint)
 noteAttackResults(attackerInfo, defenderInfo)
StringofferDrawHtml(/*String*/ resourceName)
Called when needing the offer-a-draw-with-this-move prompts HTML (typically a short sentence and a Offer A Draw checkbox). Override to set. Internally uses the "youMayOfferDraw" and "offerDrawWithThisMove" resources.
 offsetStartBoard(board, color)
 parsePlayOptions(optionString)
 pathThroughLake(fromPoint, toPoint)
 pieceNotation(pieceChar)
 pieceTypeRange(pieceType, diagonal)
BooleanprocessSecureMove(/*GamesByEmail*/ game)
Gets called when the sending moves, fir processing secure move data on the client. Override to process secure data.
 rankApparentValue(value)
 resolveAttack(index, color1, remove1, color2, remove2)
 resolveAttackHtml()
 resolveAttackPart(index, piece, color, remove)
 reverseString(value)
BooleansendMove(/*Boolean*/ sendNow, /*Player*/ player)
Gets called when the Send Move button is pushed. Override and set the game state, then call Super.sendMove.
voidsetPerspective(/*Team*/ team)
Called when synchronizing, sets the perspective of the board based on the player. By default sets the rotation property to 0.
voidsetPerspective(/*Team*/ team)
Called when synchronizing, sets the perspective of the board based on the player. By default sets the rotation property to 0.
 settingUpHtml()
 setupDragByClicks(up, origPoint, screenPoint)
 setupMouseDown(screenPoint)
 setupMouseMove(screenPoint)
 setupMouseUp(screenPoint)
 showHilites()
 sortSetupForDisplay(setup)
 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.
 teamCanMove(team)
 teamsNeedToSetup()
voidundo(/*Boolean*/ skipUpdate)
Undos all moves since the last synch method call. The synch and update methods will be called again.
StringundoMoveHtml(/*String*/ resourceName)
Called when needing the undo-this-move prompts HTML (typically a short sentence and an Undo button). Override to set. Internally uses the "youMayUndoYourMove" resource.
 unshiftSetup(board, color)
voidupdate()
Updates the team titles, the game header, the game title, all prompts and action links.
 updateAttackBoard()
 updateRescuerIndices(team, fromIndex, toIndex)
 useSetupSuggestion(setup)

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, continueYourTurnHtml, debug, diceRolls, dieRoll, drawAcceptedHeaderHtml, drawAcceptedHtml, drawDeclinedHeaderHtml, drawDeclinedHtml, drawOfferedHeaderHtml, 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, hiliteImageHtml, initializeNewGameForm, isBoardPointHidden, isColorAtPoint, isColorAtXY, isMyTurn, isPathClear, isPointBoardClear, isPointOnBoard, isValueColorAtPoint, isValueColorAtXY, isXYBoardClear, isXYOnBoard, maybePie, maybeResign, movePiece, nextTeam, notYourTurnHtml, numInPath, numTeamsPlaying, offerDrawCheckBoxHtml, openLogAnchorHtml, openPlayerChatAnchorHtml, openPreferencesAnchorHtml, openRulesAnchorHtml, pie, pieButtonHtml, pieHtml, refreshGame, refreshGameButtonHtml, reportProblemAnchorHtml, resign, resignButtonHtml, resignHtml, resignedHeaderHtml, screenRectFromBoardPoint, screenRectFromBoardXY, sendMoveButtonHtml, sendMoveHtml, sendReminderButtonHtml, setConstrainer, setEnded, setFloatHtml, setInnerHtml, setMouseHtml, setPlayerPrefs, setValueAtPoint, setValueAtXY, showTransactionPrompt, spectatingHtml, startAnotherGameButtonHtml, startAnotherGameHtml, teamColorFromTeam, theyResignedHtml, tieGameHeaderHtml, titleFromTeamColor, transformHashLinksToOnClicks, turnHeaderHtml, undoButtonHtml, updateTeamTitles, valueFromBoardValue, valueFromPointBoard, valueFromXYBoard, valueIndexFromBoardPoint, valueIndexFromBoardXY, wonHeaderHtml, youLoseHtml, youResignedHtml, youTiedHtml, 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

CaptureTheFlagGame

GamesByEmail.CaptureTheFlagGame()

Enum Detail

PIECE_TYPE

static PIECE_TYPE
Values:
HIDDEN - 

MOVED - 

MOVED_2 - 

MOVED_2_PLUS - 

MOVED_3_PLUS - 

FLAG - 

BOMB - 

MARSHAL - 

GENERAL - 

COLONEL - 

MAJOR - 

CAPTAIN - 

LIEUTENANT - 

SERGEANT - 

MINER - 

SCOUT - 

SPY - 

ATTACK - 

UNKNOWN - 

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

setupSuggestions

static setupSuggestions

unsetupLayout

static unsetupLayout

Method Detail

addToTaken

addToTaken(team,
           piece)
Parameters:
team - 

piece - 


apparentValueFromMove

apparentValueFromMove(fromPoint,
                      toPoint,
                      publicBoard,
                      privateBoard)
Parameters:
fromPoint - 

toPoint - 

publicBoard - 

privateBoard - 


areThereMultipleUnknownPieces

areThereMultipleUnknownPieces(defaultValue,
                              publicBoard,
                              privateBoard)
Parameters:
defaultValue - 

publicBoard - 

privateBoard - 


canMoveFrom

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

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

checkSetupMove

checkSetupMove(toPoint,
               fromPoint)
Parameters:
toPoint - 

fromPoint - 


clearSetup

clearSetup()

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.

convertBoardValueToSetup

convertBoardValueToSetup(boardValue)
Parameters:
boardValue - 


convertSetupToBoardValue

convertSetupToBoardValue(setup,
                         color)
Parameters:
setup - 

color - 


dispose

dispose()
Overrides:
dispose in class Game

dragByClicks

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

origPoint - 

screenPoint - 


flipSetup

flipSetup()

getAttackBoardHtml

getAttackBoardHtml(attackerColor,
                   attackerPoint,
                   defenderPoint,
                   newAttack,
                   forceResolution)
Parameters:
attackerColor - 

attackerPoint - 

defenderPoint - 

newAttack - 

forceResolution - 


getAttackInfo

getAttackInfo(team,
              boardPoint)
Parameters:
team - 

boardPoint - 


getAttackPiece

getAttackPiece()

getCombinedBoardState

getCombinedBoardState()

getStartBoard

getStartBoard(color)
Parameters:
color - 


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.

handleMoveCollision

void handleMoveCollision(/*Object*/ gameData,
                         /*Array*/ collisionMoves)

Override to handle move collisions from concurrent turns.

Overrides:
handleMoveCollision in class Game
Parameters:
gameData - 
The most current gameData on the server. This is the state the collision moves must be merged into.
collisionMoves - 
The list of moves that generated the collision.

Example:

handleMoveCollision:function(gameData,collisionMoves)
{
   var lastCollisionMove=collisionMoves[collisionMoves.length-1];
   this.importRawGame(gameData);
   
   //make same moves as lastCollisionMove
   
   this.sendMove();
}

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

isExactValueUnknown

isExactValueUnknown(value)
Parameters:
value - 


isLake

isLake(boardPoint)
Parameters:
boardPoint - 


isMoveLegal

isMoveLegal(toPoint,
            fromPoint,
            board,
            color)
Parameters:
toPoint - 

fromPoint - 

board - 

color - 


isMoveablePiece

isMoveablePiece(piece)
Parameters:
piece - 


isSetupChoked

isSetupChoked(board,
              color)
Parameters:
board - 

color - 


isSetupComplete

isSetupComplete(board,
                color)
Parameters:
board - 

color - 


isSetupFilled

isSetupFilled(board,
              color)
Parameters:
board - 

color - 


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.

makeColorHidden

makeColorHidden(value,
                color)
Parameters:
value - 

color - 


mouseDown

mouseDown(screenPoint)
Parameters:
screenPoint - 


mouseMove

mouseMove(screenPoint)
Parameters:
screenPoint - 


mouseUp

mouseUp(screenPoint)
Parameters:
screenPoint - 


noteAttackResults

noteAttackResults(attackerInfo,
                  defenderInfo)
Parameters:
attackerInfo - 

defenderInfo - 


offerDrawHtml

String offerDrawHtml(/*String*/ resourceName)

Called when needing the offer-a-draw-with-this-move prompts HTML (typically a short sentence and a Offer A Draw checkbox). Override to set. Internally uses the "youMayOfferDraw" and "offerDrawWithThisMove" resources.

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

offsetStartBoard

offsetStartBoard(board,
                 color)
Parameters:
board - 

color - 


parsePlayOptions

parsePlayOptions(optionString)
Parameters:
optionString - 


pathThroughLake

pathThroughLake(fromPoint,
                toPoint)
Parameters:
fromPoint - 

toPoint - 


pieceNotation

pieceNotation(pieceChar)
Parameters:
pieceChar - 


pieceTypeRange

pieceTypeRange(pieceType,
               diagonal)
Parameters:
pieceType - 

diagonal - 


processSecureMove

Boolean processSecureMove(/*GamesByEmail*/ game)

Gets called when the sending moves, fir processing secure move data on the client. Override to process secure data.

Overrides:
processSecureMove in class Game
Parameters:
game - 
The game object to process.
Returns:
false.

rankApparentValue

rankApparentValue(value)
Parameters:
value - 


resolveAttack

resolveAttack(index,
              color1,
              remove1,
              color2,
              remove2)
Parameters:
index - 

color1 - 

remove1 - 

color2 - 

remove2 - 


resolveAttackHtml

resolveAttackHtml()

resolveAttackPart

resolveAttackPart(index,
                  piece,
                  color,
                  remove)
Parameters:
index - 

piece - 

color - 

remove - 


reverseString

reverseString(value)
Parameters:
value - 


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.

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.

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.

settingUpHtml

settingUpHtml()

setupDragByClicks

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

origPoint - 

screenPoint - 


setupMouseDown

setupMouseDown(screenPoint)
Parameters:
screenPoint - 


setupMouseMove

setupMouseMove(screenPoint)
Parameters:
screenPoint - 


setupMouseUp

setupMouseUp(screenPoint)
Parameters:
screenPoint - 


showHilites

showHilites()

sortSetupForDisplay

sortSetupForDisplay(setup)
Parameters:
setup - 


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.

teamCanMove

teamCanMove(team)
Parameters:
team - 


teamsNeedToSetup

teamsNeedToSetup()

undo

void undo(/*Boolean*/ skipUpdate)

Undos all moves since the last synch method call. The synch and update methods will be called again.

Overrides:
undo in class Game
Parameters:
skipUpdate - 
(Optional) Skips the update call if true. Defaults to false.

undoMoveHtml

String undoMoveHtml(/*String*/ resourceName)

Called when needing the undo-this-move prompts HTML (typically a short sentence and an Undo button). Override to set. Internally uses the "youMayUndoYourMove" resource.

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

unshiftSetup

unshiftSetup(board,
             color)
Parameters:
board - 

color - 


update

void update()

Updates the team titles, the game header, the game title, all prompts and action links.

Overrides:
update in class Game

updateAttackBoard

updateAttackBoard()

updateRescuerIndices

updateRescuerIndices(team,
                     fromIndex,
                     toIndex)
Parameters:
team - 

fromIndex - 

toIndex - 


useSetupSuggestion

useSetupSuggestion(setup)
Parameters:
setup -