Skip to content

Commit

Permalink
Change code formatting style
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgraham committed Jan 28, 2022
1 parent a75dba0 commit 0352c11
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 81 deletions.
58 changes: 29 additions & 29 deletions Assets/Scripts/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tilemap>();
this.activePiece = GetComponentInChildren<Piece>();
this.nextPiece = this.gameObject.AddComponent<Piece>();
this.nextPiece.enabled = false;
tilemap = GetComponentInChildren<Tilemap>();
activePiece = GetComponentInChildren<Piece>();
nextPiece = gameObject.AddComponent<Piece>();
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();
}
}

Expand All @@ -40,33 +40,33 @@ 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();
}

public void GameOver()
{
this.tilemap.ClearAllTiles();
tilemap.ClearAllTiles();

// Do anything else you want on game over here..
}
Expand All @@ -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);
}
}

Expand All @@ -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++)
Expand All @@ -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;
}
}
Expand All @@ -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
Expand All @@ -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;
}
}
Expand All @@ -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
Expand All @@ -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++;
Expand Down
30 changes: 15 additions & 15 deletions Assets/Scripts/Ghost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class Ghost : MonoBehaviour

private void Awake()
{
this.tilemap = GetComponentInChildren<Tilemap>();
this.cells = new Vector3Int[4];
tilemap = GetComponentInChildren<Tilemap>();
cells = new Vector3Int[4];
}

private void LateUpdate()
Expand All @@ -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);
}
}

Expand Down
Loading

0 comments on commit 0352c11

Please sign in to comment.