Skip to content

Commit

Permalink
Implement changing position
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 25, 2010
1 parent 164f8fa commit d9f7473
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
3 changes: 2 additions & 1 deletion data/dm/i18n/en_fr.yml
Expand Up @@ -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"
"Save": "Enregistrer"
"Change position": "Changer de position"
29 changes: 19 additions & 10 deletions lib/model/doctrine/PluginDmChessPlayer.class.php
@@ -1,15 +1,5 @@
<?php

/**
* PluginDmChessPlayer
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
abstract class PluginDmChessPlayer extends BaseDmChessPlayer
{

Expand Down Expand Up @@ -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();
}
}
12 changes: 12 additions & 0 deletions modules/dmChessGame/actions/actions.class.php
Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions modules/dmChessGame/templates/_board.php
Expand Up @@ -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');
15 changes: 15 additions & 0 deletions web/css/board.css
Expand Up @@ -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;
}
Binary file modified web/images/exchange.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d9f7473

Please sign in to comment.