From 0352c115f41a3f48adb27bff3bae6fb980cb2882 Mon Sep 17 00:00:00 2001 From: Adam Graham Date: Thu, 27 Jan 2022 21:43:51 -0600 Subject: [PATCH] Change code formatting style --- Assets/Scripts/Board.cs | 58 +++++++++++++++--------------- Assets/Scripts/Ghost.cs | 30 ++++++++-------- Assets/Scripts/Piece.cs | 70 ++++++++++++++++++------------------- Assets/Scripts/Tetromino.cs | 4 +-- 4 files changed, 81 insertions(+), 81 deletions(-) diff --git a/Assets/Scripts/Board.cs b/Assets/Scripts/Board.cs index 2c48c8e..fb814f5 100644 --- a/Assets/Scripts/Board.cs +++ b/Assets/Scripts/Board.cs @@ -15,20 +15,20 @@ public class Board : MonoBehaviour public RectInt Bounds { get { - Vector2Int position = new Vector2Int(-this.boardSize.x / 2, -this.boardSize.y / 2); - return new RectInt(position, this.boardSize); + Vector2Int position = new Vector2Int(-boardSize.x / 2, -boardSize.y / 2); + return new RectInt(position, boardSize); } } private void Awake() { - this.tilemap = GetComponentInChildren(); - this.activePiece = GetComponentInChildren(); - this.nextPiece = this.gameObject.AddComponent(); - this.nextPiece.enabled = false; + tilemap = GetComponentInChildren(); + activePiece = GetComponentInChildren(); + nextPiece = gameObject.AddComponent(); + nextPiece.enabled = false; - for (int i = 0; i < this.tetrominoes.Length; i++) { - this.tetrominoes[i].Initialize(); + for (int i = 0; i < tetrominoes.Length; i++) { + tetrominoes[i].Initialize(); } } @@ -40,25 +40,25 @@ private void Start() private void SetNextPiece() { - if (this.nextPiece.cells != null) { - Clear(this.nextPiece); + if (nextPiece.cells != null) { + Clear(nextPiece); } - int random = Random.Range(0, this.tetrominoes.Length); - TetrominoData data = this.tetrominoes[random]; + int random = Random.Range(0, tetrominoes.Length); + TetrominoData data = tetrominoes[random]; - this.nextPiece.Initialize(this, this.previewPosition, data); - Set(this.nextPiece); + nextPiece.Initialize(this, previewPosition, data); + Set(nextPiece); } public void SpawnPiece() { - this.activePiece.Initialize(this, this.spawnPosition, this.nextPiece.data); + activePiece.Initialize(this, spawnPosition, nextPiece.data); - if (!IsValidPosition(this.activePiece, this.spawnPosition)) { + if (!IsValidPosition(activePiece, spawnPosition)) { GameOver(); } else { - Set(this.activePiece); + Set(activePiece); } SetNextPiece(); @@ -66,7 +66,7 @@ public void SpawnPiece() public void GameOver() { - this.tilemap.ClearAllTiles(); + tilemap.ClearAllTiles(); // Do anything else you want on game over here.. } @@ -76,7 +76,7 @@ public void Set(Piece piece) for (int i = 0; i < piece.cells.Length; i++) { Vector3Int tilePosition = piece.cells[i] + piece.position; - this.tilemap.SetTile(tilePosition, piece.data.tile); + tilemap.SetTile(tilePosition, piece.data.tile); } } @@ -85,13 +85,13 @@ public void Clear(Piece piece) for (int i = 0; i < piece.cells.Length; i++) { Vector3Int tilePosition = piece.cells[i] + piece.position; - this.tilemap.SetTile(tilePosition, null); + tilemap.SetTile(tilePosition, null); } } public bool IsValidPosition(Piece piece, Vector3Int position) { - RectInt bounds = this.Bounds; + RectInt bounds = Bounds; // The position is only valid if every cell is valid for (int i = 0; i < piece.cells.Length; i++) @@ -104,7 +104,7 @@ public bool IsValidPosition(Piece piece, Vector3Int position) } // A tile already occupies the position, thus invalid - if (this.tilemap.HasTile(tilePosition)) { + if (tilemap.HasTile(tilePosition)) { return false; } } @@ -114,7 +114,7 @@ public bool IsValidPosition(Piece piece, Vector3Int position) public void ClearLines() { - RectInt bounds = this.Bounds; + RectInt bounds = Bounds; int row = bounds.yMin; // Clear from bottom to top @@ -132,14 +132,14 @@ public void ClearLines() public bool IsLineFull(int row) { - RectInt bounds = this.Bounds; + RectInt bounds = Bounds; for (int col = bounds.xMin; col < bounds.xMax; col++) { Vector3Int position = new Vector3Int(col, row, 0); // The line is not full if a tile is missing - if (!this.tilemap.HasTile(position)) { + if (!tilemap.HasTile(position)) { return false; } } @@ -149,13 +149,13 @@ public bool IsLineFull(int row) public void LineClear(int row) { - RectInt bounds = this.Bounds; + RectInt bounds = Bounds; // Clear all tiles in the row for (int col = bounds.xMin; col < bounds.xMax; col++) { Vector3Int position = new Vector3Int(col, row, 0); - this.tilemap.SetTile(position, null); + tilemap.SetTile(position, null); } // Shift every row above down one @@ -164,10 +164,10 @@ public void LineClear(int row) for (int col = bounds.xMin; col < bounds.xMax; col++) { Vector3Int position = new Vector3Int(col, row + 1, 0); - TileBase above = this.tilemap.GetTile(position); + TileBase above = tilemap.GetTile(position); position = new Vector3Int(col, row, 0); - this.tilemap.SetTile(position, above); + tilemap.SetTile(position, above); } row++; diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs index e4b8112..23573ca 100644 --- a/Assets/Scripts/Ghost.cs +++ b/Assets/Scripts/Ghost.cs @@ -13,8 +13,8 @@ public class Ghost : MonoBehaviour private void Awake() { - this.tilemap = GetComponentInChildren(); - this.cells = new Vector3Int[4]; + tilemap = GetComponentInChildren(); + cells = new Vector3Int[4]; } private void LateUpdate() @@ -27,49 +27,49 @@ private void LateUpdate() private void Clear() { - for (int i = 0; i < this.cells.Length; i++) + for (int i = 0; i < cells.Length; i++) { - Vector3Int tilePosition = this.cells[i] + this.position; - this.tilemap.SetTile(tilePosition, null); + Vector3Int tilePosition = cells[i] + position; + tilemap.SetTile(tilePosition, null); } } private void Copy() { - for (int i = 0; i < this.cells.Length; i++) { - this.cells[i] = this.trackingPiece.cells[i]; + for (int i = 0; i < cells.Length; i++) { + cells[i] = trackingPiece.cells[i]; } } private void Drop() { - Vector3Int position = this.trackingPiece.position; + Vector3Int position = trackingPiece.position; int current = position.y; - int bottom = -this.mainBoard.boardSize.y / 2 - 1; + int bottom = -mainBoard.boardSize.y / 2 - 1; - this.mainBoard.Clear(this.trackingPiece); + mainBoard.Clear(trackingPiece); for (int row = current; row >= bottom; row--) { position.y = row; - if (this.mainBoard.IsValidPosition(this.trackingPiece, position)) { + if (mainBoard.IsValidPosition(trackingPiece, position)) { this.position = position; } else { break; } } - this.mainBoard.Set(this.trackingPiece); + mainBoard.Set(trackingPiece); } private void Set() { - for (int i = 0; i < this.cells.Length; i++) + for (int i = 0; i < cells.Length; i++) { - Vector3Int tilePosition = this.cells[i] + this.position; - this.tilemap.SetTile(tilePosition, this.tile); + Vector3Int tilePosition = cells[i] + position; + tilemap.SetTile(tilePosition, tile); } } diff --git a/Assets/Scripts/Piece.cs b/Assets/Scripts/Piece.cs index 4ba8c89..fd48364 100644 --- a/Assets/Scripts/Piece.cs +++ b/Assets/Scripts/Piece.cs @@ -21,28 +21,28 @@ public void Initialize(Board board, Vector3Int position, TetrominoData data) this.data = data; this.board = board; this.position = position; - this.rotationIndex = 0; - this.stepTime = Time.time + this.stepDelay; - this.moveTime = Time.time + this.moveDelay; - this.lockTime = 0f; + rotationIndex = 0; + stepTime = Time.time + stepDelay; + moveTime = Time.time + moveDelay; + lockTime = 0f; - if (this.cells == null) { - this.cells = new Vector3Int[data.cells.Length]; + if (cells == null) { + cells = new Vector3Int[data.cells.Length]; } - for (int i = 0; i < this.cells.Length; i++) { - this.cells[i] = (Vector3Int)data.cells[i]; + for (int i = 0; i < cells.Length; i++) { + cells[i] = (Vector3Int)data.cells[i]; } } private void Update() { - this.board.Clear(this); + board.Clear(this); // We use a timer to allow the player to make adjustments to the piece // before it locks in place - this.lockTime += Time.deltaTime; + lockTime += Time.deltaTime; // Handle rotation if (Input.GetKeyDown(KeyCode.Q)) { @@ -58,16 +58,16 @@ private void Update() // Allow the player to hold movement keys but only after a move delay // so it does not move too fast - if (Time.time > this.moveTime) { + if (Time.time > moveTime) { HandleMoveInputs(); } // Advance the piece to the next row every x seconds - if (Time.time > this.stepTime) { + if (Time.time > stepTime) { Step(); } - this.board.Set(this); + board.Set(this); } private void HandleMoveInputs() @@ -77,7 +77,7 @@ private void HandleMoveInputs() { if (Move(Vector2Int.down)) { // Update the step time to prevent double movement - this.stepTime = Time.time + this.stepDelay; + stepTime = Time.time + stepDelay; } } @@ -91,13 +91,13 @@ private void HandleMoveInputs() private void Step() { - this.stepTime = Time.time + this.stepDelay; + stepTime = Time.time + stepDelay; // Step down to the next row Move(Vector2Int.down); // Once the piece has been inactive for too long it becomes locked - if (this.lockTime >= this.lockDelay) { + if (lockTime >= lockDelay) { Lock(); } } @@ -113,25 +113,25 @@ private void HardDrop() private void Lock() { - this.board.Set(this); - this.board.ClearLines(); - this.board.SpawnPiece(); + board.Set(this); + board.ClearLines(); + board.SpawnPiece(); } private bool Move(Vector2Int translation) { - Vector3Int newPosition = this.position; + Vector3Int newPosition = position; newPosition.x += translation.x; newPosition.y += translation.y; - bool valid = this.board.IsValidPosition(this, newPosition); + bool valid = board.IsValidPosition(this, newPosition); // Only save the movement if the new position is valid if (valid) { - this.position = newPosition; - this.moveTime = Time.time + this.moveDelay; - this.lockTime = 0f; // reset + position = newPosition; + moveTime = Time.time + moveDelay; + lockTime = 0f; // reset } return valid; @@ -141,16 +141,16 @@ private void Rotate(int direction) { // Store the current rotation in case the rotation fails // and we need to revert - int originalRotation = this.rotationIndex; + int originalRotation = rotationIndex; // Rotate all of the cells using a rotation matrix - this.rotationIndex = Wrap(this.rotationIndex + direction, 0, 4); + rotationIndex = Wrap(rotationIndex + direction, 0, 4); ApplyRotationMatrix(direction); // Revert the rotation if the wall kick tests fail - if (!TestWallKicks(this.rotationIndex, direction)) + if (!TestWallKicks(rotationIndex, direction)) { - this.rotationIndex = originalRotation; + rotationIndex = originalRotation; ApplyRotationMatrix(-direction); } } @@ -160,13 +160,13 @@ private void ApplyRotationMatrix(int direction) float[] matrix = Data.RotationMatrix; // Rotate all of the cells using the rotation matrix - for (int i = 0; i < this.cells.Length; i++) + for (int i = 0; i < cells.Length; i++) { - Vector3 cell = this.cells[i]; + Vector3 cell = cells[i]; int x, y; - switch (this.data.tetromino) + switch (data.tetromino) { case Tetromino.I: case Tetromino.O: @@ -183,7 +183,7 @@ private void ApplyRotationMatrix(int direction) break; } - this.cells[i] = new Vector3Int(x, y, 0); + cells[i] = new Vector3Int(x, y, 0); } } @@ -191,9 +191,9 @@ private bool TestWallKicks(int rotationIndex, int rotationDirection) { int wallKickIndex = GetWallKickIndex(rotationIndex, rotationDirection); - for (int i = 0; i < this.data.wallKicks.GetLength(1); i++) + for (int i = 0; i < data.wallKicks.GetLength(1); i++) { - Vector2Int translation = this.data.wallKicks[wallKickIndex, i]; + Vector2Int translation = data.wallKicks[wallKickIndex, i]; if (Move(translation)) { return true; @@ -211,7 +211,7 @@ private int GetWallKickIndex(int rotationIndex, int rotationDirection) wallKickIndex--; } - return Wrap(wallKickIndex, 0, this.data.wallKicks.GetLength(0)); + return Wrap(wallKickIndex, 0, data.wallKicks.GetLength(0)); } private int Wrap(int input, int min, int max) diff --git a/Assets/Scripts/Tetromino.cs b/Assets/Scripts/Tetromino.cs index 6807488..d3b43bc 100644 --- a/Assets/Scripts/Tetromino.cs +++ b/Assets/Scripts/Tetromino.cs @@ -17,8 +17,8 @@ public struct TetrominoData public void Initialize() { - this.cells = Data.Cells[this.tetromino]; - this.wallKicks = Data.WallKicks[this.tetromino]; + cells = Data.Cells[tetromino]; + wallKicks = Data.WallKicks[tetromino]; } }