public Tetromino(bool[,] pieces, Tetro type) { this.pieces = pieces;//Might cause problems since it is a shallow copy this.type = type; Random rand = new Random(); int r = rand.Next(0, 255); int g = rand.Next(0, 255); int b = rand.Next(0, 255); this.colour = new Color(r, g, b); }
public void rotate() { if (type == Tetro.O) { //Don't rotate } else if (type == Tetro.I2 || type == Tetro.Z2 || type == Tetro.S2) { type = (Tetro)(int)type - 1; } else if (type == Tetro.J4 || type == Tetro.L4 || type == Tetro.T4) { type = (Tetro)(int)type - 3; } else { type = (Tetro)(int)type + 1; } }
public bool canRotate() { //Go through all fallenBlocks and cycle through all Rotations and if any of them are inside the fallenBlocks return false var rotations = Enum.GetValues(typeof(Tetro)); Tetro ogType = currentTetromino.Type; int[,] currentTetroPos; for (int i = 0; i < fallenBlocks.GetLength(0); i++) { for (int c = 0; c < fallenBlocks.GetLength(1); c++) { foreach (Tetro rotation in rotations) { currentTetromino.Type = rotation; currentTetromino.updateBlockNoRestriction(); try { currentTetroPos = findTetroPositionInField(currentTetromino); } catch { currentTetromino.Type = ogType; currentTetromino.updateBlockNoRestriction(); return(false); } for (int pos = 0; pos < currentTetroPos.GetLength(0); pos++) { if (currentTetroPos[pos, 0] == i && fallenBlocks[i, c] && currentTetroPos[pos, 1] == c) { currentTetromino.Type = ogType; currentTetromino.updateBlockNoRestriction(); return(false); } } } } } currentTetromino.Type = ogType; currentTetromino.updateBlockNoRestriction(); return(true); }
void createNewTetro() { int r = (random.Next(70) / 10); switch (r) { case 0: currentTetro = new Tetro(gameField, TetroType.T); break; case 1: currentTetro = new Tetro(gameField, TetroType.I); break; case 2: currentTetro = new Tetro(gameField, TetroType.J); break; case 3: currentTetro = new Tetro(gameField, TetroType.L); break; case 4: currentTetro = new Tetro(gameField, TetroType.O); break; case 5: currentTetro = new Tetro(gameField, TetroType.S); break; case 6: currentTetro = new Tetro(gameField, TetroType.Z); break; } //t = new Tetro(gameField, TetroType.O); }