/// <summary> /// Creates a new custom tetrimino. /// </summary> /// <param name="blocks">What block(s) does the tetrimino has initially.</param> /// <param name="matrix"></param> public CustomTetrimino(List<TetrisBlock> blocks, TetrisBlock[,] matrix) { this.blocks = blocks; foreach (TetrisBlock block in blocks) { matrix[block.X, block.Y] = null; } }
/// <summary> /// Construct a new O Shaped Tetrinimo. /// </summary> /// <param name="matrix">Please pass the matrix field of the TetrisBoard object.</param> public OShapedTetrimino(TetrisBlock[,] matrix, TetrisWindow form) : base(matrix, form) { blocks = new List<TetrisBlock> () { new TetrisBlock (Color.Cyan, 7, 0, form), new TetrisBlock (Color.Cyan, 7, 1,form), new TetrisBlock (Color.Cyan, 8, 0, form), new TetrisBlock (Color.Cyan, 8, 1, form) }; }
/// <summary> /// Adds all the tetris blocks of this tetrmino to a matrix. /// </summary> /// <param name="matrix">Where to add the tetris blocks</param> public void AddTetrisBlocksToMatrix(TetrisBlock[,] matrix) { foreach (var block in blocks) { if (matrix[block.X, block.Y] == null) { matrix[block.X, block.Y] = block; } else { throw new ArgumentException ("The Tetrimino has landed incorrectly."); } } }
/// <summary> /// Constructs a new L shaped tetrimino. /// </summary> /// <param name="matrix">Please pass the matrix field of the TetrisBoard object.</param> public LShapedTetrimino(int rotationIndex, TetrisBlock[,] matrix, TetrisWindow form) : base(matrix, form) { blocks = new List<TetrisBlock> () { new TetrisBlock (Color.Yellow, 7, 0, form), new TetrisBlock (Color.Yellow, 7, 1, form), new TetrisBlock (Color.Yellow, 7, 2, form), new TetrisBlock (Color.Yellow, 8, 2, form) }; RotationIndex = 0; for (int i = 0 ; i < rotationIndex ; i++) { Rotate (); } }
/// <summary> /// Constructs a new S shaped tetrimino. /// </summary> /// <param name="matrix">Please pass the matrix field of the TetrisBoard object.</param> public SShapedTetrimino(int rotationIndex, TetrisBlock[,] matrix, TetrisWindow form) : base(matrix, form) { if (rotationIndex == 0) { blocks = new List<TetrisBlock> () { new TetrisBlock (Color.Lime, 6, 1, form), new TetrisBlock (Color.Lime, 7, 1, form), new TetrisBlock (Color.Lime, 7, 0, form), new TetrisBlock (Color.Lime, 8, 0, form) }; } else if (rotationIndex == 1) { blocks = new List<TetrisBlock> () { new TetrisBlock (Color.Lime, 7, 0, form), new TetrisBlock (Color.Lime, 7, 1, form), new TetrisBlock (Color.Lime, 8, 1, form), new TetrisBlock (Color.Lime, 8, 2, form) }; } RotationIndex = rotationIndex; }
private void FindAdjacentBlocks(TetrisBlock[,] matrix, out List<TetrisBlock> adjBlocks) { adjBlocks = new List<TetrisBlock> (); try { adjBlocks.Add (matrix[X - 1, Y - 1]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X, Y - 1]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X + 1, Y - 1]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X - 1, Y]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X + 1, Y]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X - 1, Y + 1]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X, Y + 1]); } catch (IndexOutOfRangeException) { } try { adjBlocks.Add (matrix[X + 1, Y + 1]); } catch (IndexOutOfRangeException) { } }
/// <summary> /// Adds all the tetris blocks that belong to this tetrimio to a matrix. /// </summary> /// <param name="matrix">The matrix.</param> public void AddTetrisBlocksToMatrix(TetrisBlock[,] matrix) { foreach (TetrisBlock block in blocks) { matrix[block.X, block.Y] = block; } }
protected Tetrimino(TetrisBlock[,] matrix, TetrisWindow form) { tetrisBlockMatrix = matrix; timer = new Timer () { Interval = 1000, Enabled = true }; timer.Tick += timer_Elapsed; }