コード例 #1
0
ファイル: board.cpp プロジェクト: jose809/2048-1
void Board::collapse(Direction dir)
{
    dir = reversePosition(dir);
    int currLoc;
    int nextLoc = initPos(dir);

    for(int i = 0; i < 4; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            currLoc = nextLoc;
            nextLoc = next(dir, nextLoc);
            if((m_state[nextLoc] != 0) && (m_state[currLoc] == m_state[nextLoc]))
            {
                m_state[nextLoc] *= 2;
                m_state[currLoc] = 0;
            }
        }
        nextLoc = nextRow(dir, next(dir, currLoc));
    }
}
コード例 #2
0
size_t PositionComputer::delta(size_t pos, size_t originalDelta) const {
    assert(position(reversePosition(pos)) == pos);
    return position(reversePosition(pos) + originalDelta) - pos;
}