apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: visualboard

Source Location: /Games_Chess-1.0.1/examples/HTMLChess.php

Class Overview


The primary class - declare one of these at the top of the file


Author(s):

Version:

  • 1.0

Copyright:

  • Copyright 2002, Greg Beaver

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 63]
The primary class - declare one of these at the top of the file

Do it like this:

  1.  setup_game('mygame','x');
  2.  $x $_SESSION['x'];
  3.  if (!isset($x)) $x = new visualboard;



[ Top ]


Class Variables

$promote =  false

[line 74]

Promotion contents

Type:   false|array


[ Top ]



Method Detail

visualboard (Constructor)   [line 84]

visualboard visualboard( [ $fen = false], [ $type = 'Standard'])

Initializes $moves, $board

Parameters:

   $fen   — 
   $type   — 

[ Top ]

castlebutton   [line 490]

void castlebutton( )

Prints the castling buttons after checking castling rights

If castling rights have been taken away by a king or rook move, the button is not displayed. This function uses Games_Chess::canCastleKingside(), Games_Chess::canCastleQueenside() to find out.


[ Top ]

doCaptured   [line 193]

void doCaptured( $captured)


Parameters:

   $captured   — 

[ Top ]

domove   [line 239]

void domove( )

Grabs the next move from form variables start, goto, kingcastle and queencastle

If $_GET['start'] is not used, it checks for $_GET['kingcastle'] and tries to castle kingside if found. Otherwise, it looks for $_GET['queencastle'] and tries to castle queenside


[ Top ]

dopromote   [line 289]

void dopromote( )

This function prints the javascript that will ask the user what to promote the pawn to

Using the alert() function, this method asks the user if they want a queen. If they click Cancel, it asks if they want a rook, then knight, then bishop. If they cancel on bishop, it promotes to queen to avoid any illogical possibilities


[ Top ]

draw   [line 350]

void draw( )

Print out the chess game in its entirety: the board, move list and control buttons

first, it checks for a pawn promotion and adds the promote move to $moves using game::addpromote(). Then it moves the next piece by calling domove(). Then it checks for stalemate and checkmate, and stops the gameplay if either condition is met. It creates a visual representation of the board using abstractboard::createrows(), and displays the chessboard by linking together the display of each row on the chessboard using row::draw(), and finally the movelist using game::draw()


[ Top ]

javascript   [line 100]

void javascript( )

Prints javascript for the function addmove:

  1. function javascript()
  2.     {?>
  3. <script language="JavaScript" type="text/javascript">
  4. <!--
  5. function addMove(move, piece)
  6. {
  7.     if (document.forms[0].start.value == '')
  8.     {
  9.         document.forms[0].start.value = move;
  10.         switch (piece)
  11.         {
  12.             case "P" :
  13.             case "Q" :
  14.             case "R" :
  15.             case "B" :
  16.             case "N" :
  17.             case "K" :
  18.             break;
  19.             default :
  20.                 piece = null;
  21.             break;
  22.         }
  23.         document.forms[0].startpiece.value = piece;
  24.     } else
  25.     {
  26.         if (document.forms[0]["goto"].value == '')
  27.         {
  28.             document.forms[0]["goto"].value = move;
  29.             first = document.forms[0].startpiece.value;
  30.             if (first) {
  31.                 if (first == "P") {
  32.                     first = "";
  33.                     if (piece) {
  34.                         first = document.forms[0].start.value.charAt(0) + "x";
  35.                     }
  36.                 } else {
  37.                     if (piece) {
  38.                         first += "x";
  39.                     }
  40.                 }
  41.             }
  42.             if (confirm("Do this move? (" + first + move + ")"))
  43.             {
  44.                 document.forms[0].submit();
  45.             } else {
  46.                 document.forms[0].start.value = '';
  47.                 document.forms[0].startpiece.values = '';
  48.                 document.forms[0]["goto"].value = '';
  49.                 document.forms[0].SAN.value = '';
  50.             }
  51.         }
  52.     }
  53. }
  54.  
  55. function doPlacement(piece)
  56. {
  57.     switch (piece) {
  58.         case "P" :
  59.             name = "Pawn";
  60.         break;
  61.         case "Q" :
  62.             name = "Queen";
  63.         break;
  64.         case "R" :
  65.             name = "Rook";
  66.         break;
  67.         case "B" :
  68.             name = "Bishop";
  69.         break;
  70.         case "N" :
  71.             name = "Knight";
  72.         break;
  73.     }
  74.     square = prompt("Where should the " + name + " be placed (a1-h8, a1 is lower left)?", "e4");
  75.     if (square) {
  76.         document.forms[0].SAN.value = piece + "@" + square;
  77.         document.forms[0].start.value = "";
  78.         document.forms[0]["goto"].value = "";
  79.         if (square.charAt(1) == "1" || square.charAt(1) == "8") {
  80.             document.forms[0].SAN.value = '';
  81.             document.forms[0].start.value = "";
  82.             document.forms[0]["goto"].value = "";
  83.             alert("Cannot place a pawn on the first or last rank");
  84.         } else {
  85.             document.forms[0].submit();
  86.         }
  87.     }
  88. }
  89. //-->
  90. </script>
  91. <?php
  92.     }


[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:05:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.