public Block(int block) { cells = new Cell[ROW_SIZE, COL_SIZE]; int mask = block; for (int i = COL_SIZE - 1; i >= 0; i--) { for (int j = ROW_SIZE - 1; j >= 0; j--) { cells[i, j] = new BlockCell((CellColor)(mask & 7)); mask >>= 3; } } }
public Block(int blockCellCnt, int colorCnt) { if (blockCellCnt < 1 || ROW_SIZE * COL_SIZE < blockCellCnt) { throw new Exception("Can't MakeRandomBlock"); } cells = new Cell[ROW_SIZE, COL_SIZE]; int cnt = COL_SIZE * ROW_SIZE - 1; int remain = blockCellCnt - 1; int numberOfColors = 2; CellColor[] blockColorCand = new CellColor[numberOfColors]; for (int i = 0; i < numberOfColors; i++) { bool dupFlg; do { dupFlg = false; blockColorCand[i] = (CellColor)Core.Random.rand(1, colorCnt + 1); for (int j = 0; j < i; j++) { if (blockColorCand[i] == blockColorCand[j]) { dupFlg = true; } } } while (dupFlg); } for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { if (i == ROW_SIZE / 2 && j == COL_SIZE / 2) { cells[i, j] = new BlockCell(blockColorCand[Core.Random.rand(0, numberOfColors)]); continue; } if (Core.Random.rand(cnt) < remain) { cells[i, j] = new BlockCell(blockColorCand[Core.Random.rand(0, numberOfColors)]); remain--; } else { cells[i, j] = new BlankCell(); } cnt--; } } }