Example #1
0
    /// <summary>
    /// 交换两个gemstone位置
    /// </summary>
    /// <param name="g1">gemstone1</param>
    /// <param name="g2">gemstone2</param>
    private void Exchange(Gemstone g1, Gemstone g2)
    {
        // 交换列表数据中的位置
        var tempG1ColumnIndex = g1.columnIndex;
        var tempG1RowIndex    = g1.rowIndex;
        var tempG2ColumnIndex = g2.columnIndex;
        var tempG2RowIndex    = g2.rowIndex;

        g1.columnIndex = tempG2ColumnIndex;
        g1.rowIndex    = tempG2RowIndex;
        g2.columnIndex = tempG1ColumnIndex;
        g2.rowIndex    = tempG1RowIndex;

        var temp = g1;

        gemstoneList[tempG1RowIndex][tempG1ColumnIndex] = g2;
        gemstoneList[tempG2RowIndex][tempG2ColumnIndex] = temp;
        // 更新视图中的位置
        g1.Move();
        g2.Move();
    }