diff --git a/data/dm/i18n/en_fr.yml b/data/dm/i18n/en_fr.yml index 1c8f7b9..16fb8e0 100644 --- a/data/dm/i18n/en_fr.yml +++ b/data/dm/i18n/en_fr.yml @@ -15,4 +15,5 @@ "Creating a new game...": "Création d'une nouvelle partie..." "Play with a friend": "Jouer avec un ami" "Play with the machine": "Jouer avec la machine" -"Save": "Enregistrer" \ No newline at end of file +"Save": "Enregistrer" +"Change position": "Changer de position" \ No newline at end of file diff --git a/lib/model/doctrine/PluginDmChessPlayer.class.php b/lib/model/doctrine/PluginDmChessPlayer.class.php index 37ffae2..8601a45 100644 --- a/lib/model/doctrine/PluginDmChessPlayer.class.php +++ b/lib/model/doctrine/PluginDmChessPlayer.class.php @@ -1,15 +1,5 @@ - * @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $ - */ abstract class PluginDmChessPlayer extends BaseDmChessPlayer { @@ -345,4 +335,23 @@ protected function createPiece($type, $x) { $this->get('Pieces')->add(dmDb::table('DmChess'.ucfirst($type))->create()->set('x', $x)->set('Player', $this)); } + + public function exchangePosition() + { + if($this->Opponent) + { + throw new dmChessException('Can not exchange position'); + } + + $this->color = $this->isWhite() ? 'black' : 'white'; + + foreach($this->Pieces as $piece) + { + $piece->set('y', 9 - $piece->get('y')); + } + + $this->Pieces->save(); + + $this->save(); + } } \ No newline at end of file diff --git a/modules/dmChessGame/actions/actions.class.php b/modules/dmChessGame/actions/actions.class.php index 08e0c74..debb880 100755 --- a/modules/dmChessGame/actions/actions.class.php +++ b/modules/dmChessGame/actions/actions.class.php @@ -69,6 +69,18 @@ public function executeSetAiLevel(dmWebRequest $request) return $this->renderText('ok'); } + + public function executeChangePosition(dmWebRequest $request) + { + $this->forward404Unless( + ($player = $this->compilePlayer(dmDb::table('DmChessPlayer')->findOneByCode($request->getParameter('player')))) && + (!$player->Opponent) + ); + + $player->exchangePosition(); + + $this->redirect($this->getHelper()->link($this->getPage())->param('p', $player->code)->getHref()); + } public function executeResign(dmWebRequest $request) { diff --git a/modules/dmChessGame/templates/_board.php b/modules/dmChessGame/templates/_board.php index 9e91a0b..cfffb10 100644 --- a/modules/dmChessGame/templates/_board.php +++ b/modules/dmChessGame/templates/_board.php @@ -36,4 +36,13 @@ } } +if(!$player->Game->isStarted) +{ + echo _link('+/dmChessGame/changePosition') + ->param('player', $player->code) + ->set('a.dm_chess_exchange_position') + ->title(__('Change position')) + ->text(''); +} + echo _close('div'); \ No newline at end of file diff --git a/web/css/board.css b/web/css/board.css index a74a034..c2eed2d 100644 --- a/web/css/board.css +++ b/web/css/board.css @@ -110,4 +110,19 @@ div.dm_chess_piece.queen.black{ } div.dm_chess_piece.king.black{ background-position: -320px +64px; +} + +a.dm_chess_exchange_position { + background: url(../images/exchange.png) top left no-repeat; + width: 128px; + height: 128px; + display: block; + position: absolute; + top: 191px; + left: 191px; + cursor: pointer; +} + +a.dm_chess_exchange_position:hover { + background-position: 0 -128px; } \ No newline at end of file diff --git a/web/images/exchange.png b/web/images/exchange.png index 5f13ef6..6781bdc 100644 Binary files a/web/images/exchange.png and b/web/images/exchange.png differ