public Block[] getNeighbours(Block b) { int[] id = b.getPlaygroundID(); int yVal = id[0]; int xVal = id[1]; Block[] ret = { null, null, null }; try { ret[0] = arr[yVal, xVal - 1]; } catch (Exception e) { //skip } try { ret[1] = arr[yVal+1, xVal]; } catch (Exception e) { //skip } try { ret[2] = arr[yVal, xVal + 1]; } catch (Exception e) { //skip } return ret; }
public void addBlock(Block b) { int xVal = (b.X1 / bs); int yVal = (b.Y1 / bs); arr[yVal, xVal] = b; int[] id = {yVal,xVal}; b.savePlaygroundID(id); }
public Block checkNeighbour(Block b,char c) { Block ret = null; switch (c) { case 'l': ret=checkNLeft(b); break; case 'r': ret=checkNRight(b); break; case 'd': ret=checkNDown(b); break; default: ; break; } if(this.trash.Contains(ret)){ return ret; } else { return null; } }
public L(ColorType color, int blocksize, Engine e) : base(color, blocksize, e) { int x1 = 4*e.getBS(); int y1=2*e.getBS(); int x2 = x1+e.getBS()*5; int y2 = e.getBS(); int bs = e.getBS(); this.colframe = new ColFrame(x1 - bs, y1 + bs, x1 + 2*bs, y1 - 2*bs); b1 = new Block(x1, y1, x1 + bs, y1 - bs,color); b2 = new Block(x1, y1-bs, x1+bs, y1 - 2*bs, color); b3 = new Block(x1, y1+bs, x1, y1, color); b4 = new Block(x1+bs, y1+bs, x1+2*bs, y1, color); this.blocks = new Block[4]; blocks[0] = b1; blocks[1] = b2; blocks[2] = b3; blocks[3] = b4; this.rotpos = 0; }
public override void posChangePrepPaint(int x1N, int y1N) { this.x1 = x1N; this.y1 = y1N; int bs = 20; b1 = new Block(x1, y1, x1 + bs, y1 - bs, color); b2 = new Block(x1, y1 - bs, x1 + bs, y1 - 2 * bs, color); b3 = new Block(x1, y1 + bs, x1, y1, color); b4 = new Block(x1 + bs, y1 + bs, x1 + 2 * bs, y1, color); this.blocks = new Block[4]; blocks[0] = b1; blocks[1] = b2; blocks[2] = b3; blocks[3] = b4; }
private Block checkNRight(Block b) { Block[] sur = pg.getNeighbours(b); return sur[2]; }
private Block checkNLeft(Block b) { Block[] sur = pg.getNeighbours(b); return sur[0]; }
private Block checkNDown(Block b) { Block[] sur = pg.getNeighbours(b); return sur[1]; }
private void checkCollision(Block block) { Block n = engine.checkNeighbour(block, 'd'); if (n != null) { terminate = true; if (n.Y2 == 80) engine.notifyGameEnd(); } if (block.Y1 == maxY) terminate = true; }
private bool checkBlockFamily(Block a, Block b) { if (this.blocks.Contains(a) && this.blocks.Contains(b)) return true; return false; }
internal void updateFigure(Figure figure) { Block[] tmp = new Block[4]; Array.Copy(figure.blocks, tmp, 4); Array.Sort(tmp, delegate(Block b1, Block b2) { return -b1.Y1.CompareTo(b2.Y1); }); foreach (Block b in tmp) { updateBlock(b); } }
public void updateBlock(Block b) { int[] id = b.getPlaygroundID(); arr[id[0], id[1]] = null; addBlock(b); }