예제 #1
0
// Checks if the game field is playable
// if the tiles on the two given positions are swapped
const bool GameField::isPlayable(const FieldPos& pos1, const FieldPos& pos2) const
{
    bool playable = false;

    // check if two fields are inside array boundaries
    if ( pos1.x() < FIELD_WIDTH && pos1.y() < FIELD_HEIGHT &&
         pos2.x() < FIELD_WIDTH && pos2.y() < FIELD_HEIGHT )
    {
        // check if next to each other
        if ( ( (pos1.x() == pos2.x()) && ((pos1.y() == pos2.y()+1 || pos1.y()+1 == pos2.y())) ) ||
             ( (pos1.y() == pos2.y()) && ((pos1.x() == pos2.x()+1 || pos1.x()+1 == pos2.x())) ) )
        {
            // copy game field
            GameField tempField(*this); 

            // swap tiles
            tempField.getTile(pos1).swap( tempField.getTile(pos2) );

            // std::cout << "GameField::isPlayable() swap "
            //           << pos1.x() << " "
            //           << pos1.y() << " with "
            //           << pos2.x() << " "
            //           << pos2.y() << std::endl;
            
            // TODO: it would be a little bit faster if we only check
            // the swapped columns/rows
            
            // check if there are same tiles to remove
            ScoredTileArray tArray;
            if ( tempField.findSameTiles(tArray) )
            {
                playable = true;
            }
        }
        else
        {
            std::cout << "GameField::isPlayable() error: tiles not next to each other"
                      << std::endl;
        }
    }
    else
    {
        std::cout << "GameField::isPlayable() error: pos out of boundaries"
                  << std::endl;
    }
    
    return playable;
}
예제 #2
0
    InertialDataFields InertialParser::parseFields(InertialPacket& packet)
    {
        InertialDataFields result;

        uint8 fieldDescriptor;
        uint16 fieldType;
        uint32 fieldLen;

        uint8 descriptorSet = packet.descriptorSet();

        //create a DataBuffer to make parsing easier
        DataBuffer payloadData(packet.payload());

        while(payloadData.moreToRead())
        {
            Bytes fieldBytes;

            //read the field length byte
            fieldLen = payloadData.read_uint8();

            //read the field descriptor byte
            fieldDescriptor = payloadData.read_uint8();

            //read all the bytes for the current field (up to the field length)
            for(uint32 itr = 0; itr < fieldLen - 2; itr++)
            {
                //add the field bytes to a container
                fieldBytes.push_back(payloadData.read_uint8());
            } 

            fieldType = Utils::make_uint16(descriptorSet, fieldDescriptor);

            //add the field to the m_dataFields vector
            InertialDataField tempField(fieldType, fieldBytes);
            result.push_back(tempField);
        }

        return result;
    }