Beispiel #1
0
    //returns the possible move location in ChessBoard::BoardSlot position
    std::vector<sf::Vector2i> King::getPossibleMoveLocation(ChessBoard& gameBoard)const{
        std::vector<sf::Vector2i> possibleLocations;
        using sf::Vector2i;
        Vector2i spritePos( int(m_sprite.GetPosition().x),int(m_sprite.GetPosition().y));
        Vector2i slotPos = gameBoard.convertToBoardIndex(spritePos.x,spritePos.y);
        
        Vector2i tmp(slotPos.x - 1, slotPos.y - 1);
        //check possible moves in previous row if any 
        if(tmp.x >= 0)
        {   
            for(int i = 0; i < 3; ++i, ++tmp.y )
            {
                if(tmp.y >= 0 && tmp.y < ChessBoard::BOARD_WIDTH){
                    //if not occupied highlight it
                    if(_canHighlightSlot(gameBoard, tmp) != NOT_HIGHLIGHTED){
                        possibleLocations.push_back(tmp);
                    }
                }
            }
        }
        //check possible moves in forward row if any
        tmp = Vector2i(slotPos.x + 1, slotPos.y - 1);
        if(tmp.x < ChessBoard::BOARD_HEIGHT)
        {
            for(int i = 0; i < 3; ++i, ++tmp.y )
            {
                if(tmp.y >= 0 && tmp.y < ChessBoard::BOARD_WIDTH){
                    if(_canHighlightSlot(gameBoard, tmp) != NOT_HIGHLIGHTED){
                        possibleLocations.push_back(tmp);
                    }
                }
            }
        }
        //check left slot
        tmp = Vector2i(slotPos.x, slotPos.y - 1);
        if(tmp.y >= 0)
        {
            if(_canHighlightSlot(gameBoard, tmp) != NOT_HIGHLIGHTED){
                possibleLocations.push_back(tmp);
            }
        }
        //check right slot
        tmp = Vector2i(slotPos.x, slotPos.y + 1);
        if(tmp.y < ChessBoard::BOARD_WIDTH)
        {
            if(_canHighlightSlot(gameBoard, tmp) != NOT_HIGHLIGHTED){
                possibleLocations.push_back(tmp);
            }
        }

        return possibleLocations;

    }
Beispiel #2
0
 //returns the possible move location in ChessBoard::BoardSlot position
 std::vector<sf::Vector2i> Knight::getPossibleMoveLocation(ChessBoard& gameBoard)const{
     std::vector<sf::Vector2i> possibleLocations;
     using sf::Vector2i;
     Vector2i spritePos( int(m_sprite.GetPosition().x),int(m_sprite.GetPosition().y));
     Vector2i slotPos = gameBoard.convertToBoardIndex(spritePos.x,spritePos.y);
     Vector2i tmp;
     
     //front mid left
     tmp = Vector2i(slotPos.x + 1, slotPos.y - 2);
     if(tmp.x  < ChessBoard::BOARD_HEIGHT && tmp.y  >= 0){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //front mid right
     tmp = Vector2i(slotPos.x + 1, slotPos.y + 2);
     if(tmp.x  < ChessBoard::BOARD_HEIGHT && tmp.y < ChessBoard::BOARD_WIDTH){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //back mid left
     tmp = Vector2i(slotPos.x - 1 , slotPos.y - 2);
     if(tmp.x >= 0 &&  tmp.y >= 0){
        if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //back mid right
     tmp = Vector2i(slotPos.x - 1, slotPos.y + 2);
     if(tmp.x >= 0 && tmp.y  < ChessBoard::BOARD_WIDTH){
        if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //front top left
     tmp = Vector2i(slotPos.x + 2 , slotPos.y - 1);
     if(tmp.x < ChessBoard::BOARD_HEIGHT && tmp.y >= 0){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }            
     }
     //front top right
     tmp = Vector2i(slotPos.x + 2, slotPos.y + 1);
     if(tmp.x < ChessBoard::BOARD_WIDTH && tmp.y < ChessBoard::BOARD_WIDTH ){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //back bottom left
     tmp = Vector2i(slotPos.x - 2, slotPos.y - 1);
     if(tmp.x  >= 0 && tmp.y >= 0){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     //back bottom right
     tmp = Vector2i(slotPos.x - 2 , slotPos.y + 1);
     if(tmp.x  >= 0 && tmp.y < ChessBoard::BOARD_WIDTH){
         if(_canHighlightSlot(gameBoard,tmp) != NOT_HIGHLIGHTED){
             possibleLocations.push_back(tmp);
         }
     }
     return possibleLocations;
 }