xxxxxxxxxxxxxxxxxxx

来源:互联网 发布:晋城网络电视台导视5 编辑:程序博客网 时间:2024/06/04 19:14

void getPos(Pos* around,int row,int column,int index){

    

    int flag;

    if (row % 2 == 0) {

        flag = 0;

    }else{

        flag = 1;

    }

    

    // 先获取 row

    int cursor = 0;

    

    around[cursor].row = row;

    around[cursor].column = column - index;

    ++cursor;

    

    around[cursor].row = row;

    around[cursor].column = column + index;

    ++cursor;

    

    // row 上一行

    around[cursor].row = row-1;

    around[cursor].column = around[0].column + flag;

    ++cursor;

    

    around[cursor].row = row-1;

    around[cursor].column = around[cursor-1].column + (2*index-1);

    ++cursor;

    


    int counter = 1 + flag;

    if (counter == 2) {

        counter = 0;

    }

    int lastCursor = 2;

    for (int i = 2; i <= index; ++i) {

        if (i == index) {

            

            around[cursor].row = row - i;

            around[cursor].column = around[lastCursor].column + counter;

            ++cursor;

            

            for (int k =1; k < index + 1; ++k) {

                around[cursor].row = row - i;

                around[cursor].column = around[cursor-1].column +1;

                ++cursor;

            }

            break;

        }else{

            around[cursor].row = row - i;

            around[cursor].column = around[lastCursor].column + counter;

            ++cursor;

            

            around[cursor].row = row - i;

            around[cursor].column = around[cursor-1].column + (2 * index - i);

            ++cursor;

            

            lastCursor += 2;

        }

        

        ++counter;

        if (counter == 2) {

            counter = 0;

        }

    }

    

    /////////////////////////////////////////

    /// 中间行的下一行

    around[cursor].row = row + 1;

    around[cursor].column = around[0].column + flag;

    ++cursor;

    

    around[cursor].row = row + 1;

    around[cursor].column = around[cursor-1].column + (2*index-1);

    ++cursor;

    

    counter = 1 + flag;

    if (counter == 2) {

        counter = 0;

    }

    lastCursor = index * 3 + 1;

    for (int i = 2; i <= index ; ++i) {

        if (i == index) {

            

            around[cursor].row = row + i;

            around[cursor].column = around[lastCursor].column + counter;

            ++cursor;

            

            for (int k =1; k < index + 1; ++k) {

                around[cursor].row = row + i;

                around[cursor].column = around[cursor-1].column +1;

                ++cursor;

            }

            break;

            

        }else{

            around[cursor].row = row + i;

            around[cursor].column = around[lastCursor].column + counter;

            ++cursor;

            

            around[cursor].row = row + i;

            around[cursor].column = around[cursor-1].column + (2 * index - i);

            ++cursor;

            

            lastCursor += 2;

        }

        

        ++counter;

        if (counter == 2) {

            counter = 0;

        }

    }

}

0 0