예제 #1
0
 void GraphicsHandler::drawTrajectory(piece::Piece const &p, bool enemy)
 {
     {
         auto &sprite = (enemy? enemy_move : valid_move);
         for(auto const &it : p.board.pieceTrajectory(p))
         {
             if(!p.board.occupied(it.second))
             {
                 if(std::find_if(p.board.pieceCapturables().begin(),
                                 p.board.pieceCapturables().end(),
                                 [&](board::Board::Movements_t::value_type const &m)
                                 {
                                     return m.second == it.second && (*m.first)->suit != p.suit;
                                 }) == p.board.pieceCapturables().end())
                 {
                     drawSpriteAtCell(sprite, it.second.x, it.second.y);
                 }
             }
         }
     }
     {
         auto &sprite = (enemy? enemy_capture : valid_capture);
         for(auto const &it : p.board.pieceCapturing(p))
         {
             for(auto const &c : p.board.pieceCapturables())
             {
                 if(c.second == it.second && (*c.first)->suit != p.suit)
                 {
                     drawSpriteAtCell(sprite, it.second.x, it.second.y);
                     auto jt = std::find_if(p.board.pieceTrajectories().begin(),
                                            p.board.pieceTrajectories().end(),
                                            [&](board::Board::Movements_t::value_type const &m)
                                            {
                                                return (*m.first)->pos == it.second;
                                            });
                     if(jt != p.board.pieceTrajectories().end())
                     {
                         drawPiece(**(jt->first)); //redraw
                     }
                     break;
                 }
             }
         }
     }
 }
예제 #2
0
void GraphicsHandler::drawValidMove(const int x, const int y)
{
    drawSpriteAtCell(validMove, x, y);
}
예제 #3
0
 void GraphicsHandler::drawPiece(piece::Piece const &p)
 {
     sf::Sprite piece {res.from_config<Texture_res>("board", "pieces", p.suit, p.pclass)};
     drawSpriteAtCell(piece, p.pos.x, p.pos.y);
 }
예제 #4
0
void GraphicsHandler::drawPiece(board::Piece *p)
{
    pieces.setTextureRect(sf::IntRect(p->getType()*cell_size, p->getColor()*cell_size, cell_size, cell_size));
    drawSpriteAtCell(pieces, p->getBoardPos().getX(), p->getBoardPos().getY());
}