Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Класс генерации шахматной доски и позиции.
- * @author NFL
- *
- */
- //require 'border.class.php';
- class ChessBorder {
- private $_letters = array(1 => 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
- private $_digits = array('1', '2', '3', '4', '5', '6', '7', '8');
- private $_black = array(
- 'A1', 'A3', 'A5', 'A7',
- 'B2', 'B4', 'B6', 'B8',
- 'C1', 'C3', 'C5', 'C7',
- 'D2', 'D4', 'D6', 'D8',
- 'E1', 'E3', 'E5', 'E7',
- 'F2', 'F4', 'F6', 'F8',
- 'G1', 'G3', 'G5', 'G7',
- 'H2', 'H4', 'H6', 'H8'
- );
- protected $_style = array(
- 'colors' => array(
- 'blackFields' => 'Goldenrod',
- 'whiteFields' => 'lightyellow'
- ),
- 'borderProps' => array(
- 'squareHeight' => '48px',
- 'squareWidth' => '48px'
- ),
- 'fieldProps' => array('pieceSize' => '30px')
- );
- private $_border;
- /**
- *
- * @param int $gameId - Идентификатор игры
- * @param array $positionData - Текущая позиция (массив пар "поле-фигура")
- * @return ChessBorder
- */
- public function init($gameId, $positionData=null) {
- $pieces = array('pwhite' => '♙', 'nwhite' => '♘',
- 'qwhite' => '♕', 'nblack' => ''/* ... NEED IMAGES, FUCKING IMAGES */);
- if ($positionData != null) {
- $class = '';
- $table = '<table border=1px>';
- foreach (array_reverse($this->_digits) as $digit) {
- $table.='<tr>' . "\r\n";
- foreach ($this->_letters as $key => $letter) {
- if (in_array($letter . $digit, $this->_black))
- $class = $this->_style['colors']['blackFields'];
- else
- $class=$this->_style['colors']['whiteFields'];
- $table.='<td id="' . $letter . $digit . '" bgcolor="' .
- $class . '" width=' . $this->_style['borderProps']['squareWidth'] . ' height=' . $this->_style['borderProps']['squareHeight'] . '
- posAttribs="canBePlaced:1,isEmpty:0">' .
- (isset($positionData[strtolower($letter) . $digit]) ?
- '<div align="center" style="font-size:' . $this->_style['fieldProps']['pieceSize'] . '">' . $pieces[$positionData[strtolower($letter) . $digit]] . '</div>' : '') . '</td>';
- }
- $table.='</tr>';
- }
- $table.='</table>';
- $this->_border = $table;
- }
- return $this;
- }
- /**
- *
- * @param string $option - Имя устанавливаемого параметра
- * @param string|int $value - Значение параметра
- * @return ChessBorder
- */
- public function setStyleOption($option, $value) {
- foreach ($this->_style as $key2 => $value2) {
- if (array_key_exists($option, $value2)) {
- foreach ($value2 as $key3 => $value3) {
- if ($option == $key3) {
- $this->_style[$key2][$option] = $value;
- break;
- }
- }
- }
- }
- return $this;
- }
- /**
- * @todo Реализация
- * @param array $options - Массив данных стиля
- */
- public function setStyleOptions(array $options) {
- }
- /**
- * Отображает шахматную доску
- */
- public function showBorder() {
- echo($this->_border);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement