Example #1
0
void TetrisCup::putFigure(const Figure &_figure)
{
    m_clearedLines = 0;
    Matrix figMatrix = _figure.getContent();
    for (int i = 0; i < figMatrix.getWidth(); i++)
        for (int j = 0; j < figMatrix.getHeight(); j++)
            if (figMatrix.getValue(i, j) > 0)
                m_content.setValue(_figure.getX() + i, _figure.getY() + j, figMatrix.getValue(i, j));

    int i = 0;
    while (i < m_content.getHeight()) {
        bool filled = true;
        for (int j = 0; j < m_content.getWidth(); j++)
            if (m_content.getValue(j, i) == 0) {
                filled = false;
                break;
            }
        if (filled) {
            m_content.delRow(i);
            m_clearedLines++;
        }
        else
            i++;
    }
}
Example #2
0
bool TetrisCup::hasPlace(const Figure &_figure)
{
    Matrix fContent(_figure.getContent());

    for (int i = 0; i < 4; ++i)
        for (int j = 0; j < 4; ++j)
            if ((fContent.getValue(j, i) == 1)) {
                if (j + _figure.getX() < 0 ||
                        i + _figure.getY() < 0 ||
                        j + _figure.getX() >= m_content.getWidth() ||
                        i + _figure.getY() >= m_content.getHeight() ||
                        (m_content.getValue(j + _figure.getX(), i + _figure.getY()) == 1))
                    return false;
            }

    return true;
}