gggitfk1976317 2017-02-26 12:56 采纳率: 85.7%
浏览 1072
已采纳

关于俄罗斯方块Shape数据关系

public final class Shape {

private static Random random = new Random();

// 当变换砖块形状时,查询此表
private static final int[] NEXT = { 0, 2, 1, 4, 5, 6, 3, 8, 9, 10, 7, 12,
        13, 14, 11, 16, 15, 18, 17 };

// Shape数组
public static final Shape[] SHAPES = {
        // 0号砖块, 下一个是0号
        // OO
        // OO
        new Shape(0, new int[] { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0,
                0, 0 }, 1, 1, 1, 1),

        // 1号砖块, 下一个是2号
        // OOOO
        new Shape(1, new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
                0, 0 }, 1, 0, 2, 0),

        // 2号砖块, 下一个是1号
        // O
        // O
        // O
        // O
        new Shape(2, new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
                0, 0 }, 0, 2, 0, 1),

        // 3号砖块, 下一个是4号
        // O
        // O
        // OO
        new Shape(3, new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0,
                0, 0 }, 0, 1, 1, 1),

        // 4号砖块,下一个是5号
        // OOO
        // O
        new Shape(4, new int[] { 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0,
                0, 0 }, 1, 1, 1, 0),

        // 5号砖块, 下一个是6号
        // OO
        // O
        // O
        new Shape(5, new int[] { 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 0, 2, 1, 0),

        // 6号砖块, 下一个是3号
        // O
        // OOO
        new Shape(6, new int[] { 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                0, 0 }, 0, 1, 2, 0),

        // 7号砖块, 下一个是8号
        // O
        // O
        // OO
        new Shape(7, new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,
                0, 0 }, 0, 2, 1, 0),

        // 8号砖块, 下一个是9号
        // O
        // OOO
        new Shape(8, new int[] { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                0, 0 }, 0, 1, 2, 0),

        // 9号砖块, 下一个是10号
        // OO
        // O
        // O
        new Shape(9, new int[] { 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 0, 1, 1, 1),

        // 10号砖块, 下一个是7号
        // OOO
        // O
        new Shape(10, new int[] { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,
                0, 0 }, 1, 1, 1, 0),

        // 11号砖块, 下一个是12
        // O
        // OOO
        new Shape(11, new int[] { 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                0, 0 }, 0, 1, 2, 0),

        // 12号砖块, 下一个是13
        // O
        // OO
        // O
        new Shape(12, new int[] { 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 0, 1, 1, 1),

        // 13号砖块, 下一个是14
        // OOO
        // O
        new Shape(13, new int[] { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 1, 1, 1, 0),

        // 14号砖块, 下一个是11
        // O
        // OO
        // O
        new Shape(14, new int[] { 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 0, 2, 1, 0),
        // shape of 15, next=16
        // OO
        // OO
        new Shape(15, new int[] { 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
                0, 0 }, 1, 1, 1, 0),
        // shape of 16, next=15
        // O
        // OO
        // O
        new Shape(16, new int[] { 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0,
                0, 0 }, 0, 1, 1, 1),

        // shape of 17, next=18
        // OO
        // OO
        new Shape(17, new int[] { 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0,
                0, 0 }, 1, 1, 1, 0),

        // shape of 18, next=17
        // O
        // OO
        // O
        new Shape(18, new int[] { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,
                0, 0 }, 0, 1, 1, 1) };

// 砖块的索引
private int index;
// 4*4的二维数组
private int[] data;
// 上下左右的margin
private int marginTop;
private int marginRight;
private int marginBottom;
private int marginLeft;

private Shape(final int index, final int[] data, int mt, int mr, int mb,
        int ml) {
    this.index = index;
    this.data = data;
    this.marginTop = mt;
    this.marginRight = mr;
    this.marginBottom = mb;
    this.marginLeft = ml;
}

// 随机生成一个砖块
public static Shape random() {
    int index = (random.nextInt() >>> 1) % Shape.SHAPES.length;
    return Shape.SHAPES[index];
}

public int getIndex() {
    return index;
}

public int[] getData() {
    return data;
}

public int marginTop() {
    return marginTop;
}

public int marginLeft() {
    return marginLeft;
}

public int marginRight() {
    return marginRight;
}

public int marginBottom() {
    return marginBottom;
}

// 下一个砖块
public Shape next() {
    return SHAPES[NEXT[index]];
}

}

举new Shape(2, new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
0, 0 }, 0, 2, 0, 1)
后面0, 2, 0, 1 是什么数据关系?什么表达式?

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-26 15:48
    关注

    private Shape(final int index, final int[] data, int mt, int mr, int mb,
    int ml) {
    this.index = index;
    this.data = data;
    this.marginTop = mt;
    this.marginRight = mr;
    this.marginBottom = mb;
    this.marginLeft = ml;
    }
    什么mr mb都是下面这些变量的缩写
    根据字面理解,它们表示和上(top)右(right)下(bottom)左(left)的边距。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab