Advertisement
NFL

Ы...

NFL
Jul 16th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.69 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Класс генерации шахматной доски и позиции.
  5.  * @author NFL
  6.  *
  7.  */
  8. //require 'border.class.php';
  9. class ChessBorder {
  10.  
  11.     private $_letters = array(1 => 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
  12.     private $_digits = array('1', '2', '3', '4', '5', '6', '7', '8');
  13.     private $_black = array(
  14.         'A1', 'A3', 'A5', 'A7',
  15.         'B2', 'B4', 'B6', 'B8',
  16.         'C1', 'C3', 'C5', 'C7',
  17.         'D2', 'D4', 'D6', 'D8',
  18.         'E1', 'E3', 'E5', 'E7',
  19.         'F2', 'F4', 'F6', 'F8',
  20.         'G1', 'G3', 'G5', 'G7',
  21.         'H2', 'H4', 'H6', 'H8'
  22.     );
  23.     protected $_style = array(
  24.         'colors' => array(
  25.             'blackFields' => 'Goldenrod',
  26.             'whiteFields' => 'lightyellow'
  27.         ),
  28.         'borderProps' => array(
  29.             'squareHeight' => '48px',
  30.             'squareWidth' => '48px'
  31.         ),
  32.         'fieldProps' => array('pieceSize' => '30px')
  33.     );
  34.     private $_border;
  35.  
  36.     /**
  37.      *
  38.      * @param int $gameId - Идентификатор игры
  39.      * @param array $positionData - Текущая позиция (массив пар "поле-фигура")
  40.      * @return ChessBorder
  41.      */
  42.     public function init($gameId, $positionData=null) {
  43.  
  44.         $pieces = array('pwhite' => '&#9817;', 'nwhite' => '&#9816;',
  45.             'qwhite' => '&#9813;', 'nblack' => ''/* ... NEED IMAGES, FUCKING IMAGES */);
  46.         if ($positionData != null) {
  47.             $class = '';
  48.             $table = '<table border=1px>';
  49.             foreach (array_reverse($this->_digits) as $digit) {
  50.                 $table.='<tr>' . "\r\n";
  51.                 foreach ($this->_letters as $key => $letter) {
  52.                     if (in_array($letter . $digit, $this->_black))
  53.                         $class = $this->_style['colors']['blackFields'];
  54.                     else
  55.                         $class=$this->_style['colors']['whiteFields'];
  56.  
  57.                     $table.='<td id="' . $letter . $digit . '" bgcolor="' .
  58.                             $class . '" width=' . $this->_style['borderProps']['squareWidth'] . ' height=' . $this->_style['borderProps']['squareHeight'] . '
  59.                                posAttribs="canBePlaced:1,isEmpty:0">' .
  60.                             (isset($positionData[strtolower($letter) . $digit]) ?
  61.                                     '<div align="center" style="font-size:' . $this->_style['fieldProps']['pieceSize'] . '">' . $pieces[$positionData[strtolower($letter) . $digit]] . '</div>' : '') . '</td>';
  62.                 }
  63.                 $table.='</tr>';
  64.             }
  65.             $table.='</table>';
  66.             $this->_border = $table;
  67.         }
  68.         return $this;
  69.     }
  70.     /**
  71.      *
  72.      * @param string $option - Имя устанавливаемого параметра
  73.      * @param string|int $value - Значение параметра
  74.      * @return ChessBorder
  75.      */
  76.     public function setStyleOption($option, $value) {
  77.         foreach ($this->_style as $key2 => $value2) {
  78.             if (array_key_exists($option, $value2)) {
  79.                 foreach ($value2 as $key3 => $value3) {
  80.                     if ($option == $key3) {
  81.                         $this->_style[$key2][$option] = $value;
  82.                         break;
  83.                     }
  84.                 }
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89.  
  90.     /**
  91.      * @todo Реализация
  92.      * @param array $options - Массив данных стиля
  93.      */
  94.     public function setStyleOptions(array $options) {
  95.        
  96.     }
  97.  
  98.     /**
  99.      * Отображает шахматную доску
  100.      */
  101.     public function showBorder() {
  102.         echo($this->_border);
  103.     }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement