@@ -15,20 +15,20 @@ public class Board : MonoBehaviour
15
15
public RectInt Bounds {
16
16
get
17
17
{
18
- Vector2Int position = new Vector2Int ( - this . boardSize . x / 2 , - this . boardSize . y / 2 ) ;
19
- return new RectInt ( position , this . boardSize ) ;
18
+ Vector2Int position = new Vector2Int ( - boardSize . x / 2 , - boardSize . y / 2 ) ;
19
+ return new RectInt ( position , boardSize ) ;
20
20
}
21
21
}
22
22
23
23
private void Awake ( )
24
24
{
25
- this . tilemap = GetComponentInChildren < Tilemap > ( ) ;
26
- this . activePiece = GetComponentInChildren < Piece > ( ) ;
27
- this . nextPiece = this . gameObject . AddComponent < Piece > ( ) ;
28
- this . nextPiece . enabled = false ;
25
+ tilemap = GetComponentInChildren < Tilemap > ( ) ;
26
+ activePiece = GetComponentInChildren < Piece > ( ) ;
27
+ nextPiece = gameObject . AddComponent < Piece > ( ) ;
28
+ nextPiece . enabled = false ;
29
29
30
- for ( int i = 0 ; i < this . tetrominoes . Length ; i ++ ) {
31
- this . tetrominoes [ i ] . Initialize ( ) ;
30
+ for ( int i = 0 ; i < tetrominoes . Length ; i ++ ) {
31
+ tetrominoes [ i ] . Initialize ( ) ;
32
32
}
33
33
}
34
34
@@ -40,33 +40,33 @@ private void Start()
40
40
41
41
private void SetNextPiece ( )
42
42
{
43
- if ( this . nextPiece . cells != null ) {
44
- Clear ( this . nextPiece ) ;
43
+ if ( nextPiece . cells != null ) {
44
+ Clear ( nextPiece ) ;
45
45
}
46
46
47
- int random = Random . Range ( 0 , this . tetrominoes . Length ) ;
48
- TetrominoData data = this . tetrominoes [ random ] ;
47
+ int random = Random . Range ( 0 , tetrominoes . Length ) ;
48
+ TetrominoData data = tetrominoes [ random ] ;
49
49
50
- this . nextPiece . Initialize ( this , this . previewPosition , data ) ;
51
- Set ( this . nextPiece ) ;
50
+ nextPiece . Initialize ( this , previewPosition , data ) ;
51
+ Set ( nextPiece ) ;
52
52
}
53
53
54
54
public void SpawnPiece ( )
55
55
{
56
- this . activePiece . Initialize ( this , this . spawnPosition , this . nextPiece . data ) ;
56
+ activePiece . Initialize ( this , spawnPosition , nextPiece . data ) ;
57
57
58
- if ( ! IsValidPosition ( this . activePiece , this . spawnPosition ) ) {
58
+ if ( ! IsValidPosition ( activePiece , spawnPosition ) ) {
59
59
GameOver ( ) ;
60
60
} else {
61
- Set ( this . activePiece ) ;
61
+ Set ( activePiece ) ;
62
62
}
63
63
64
64
SetNextPiece ( ) ;
65
65
}
66
66
67
67
public void GameOver ( )
68
68
{
69
- this . tilemap . ClearAllTiles ( ) ;
69
+ tilemap . ClearAllTiles ( ) ;
70
70
71
71
// Do anything else you want on game over here..
72
72
}
@@ -76,7 +76,7 @@ public void Set(Piece piece)
76
76
for ( int i = 0 ; i < piece . cells . Length ; i ++ )
77
77
{
78
78
Vector3Int tilePosition = piece . cells [ i ] + piece . position ;
79
- this . tilemap . SetTile ( tilePosition , piece . data . tile ) ;
79
+ tilemap . SetTile ( tilePosition , piece . data . tile ) ;
80
80
}
81
81
}
82
82
@@ -85,13 +85,13 @@ public void Clear(Piece piece)
85
85
for ( int i = 0 ; i < piece . cells . Length ; i ++ )
86
86
{
87
87
Vector3Int tilePosition = piece . cells [ i ] + piece . position ;
88
- this . tilemap . SetTile ( tilePosition , null ) ;
88
+ tilemap . SetTile ( tilePosition , null ) ;
89
89
}
90
90
}
91
91
92
92
public bool IsValidPosition ( Piece piece , Vector3Int position )
93
93
{
94
- RectInt bounds = this . Bounds ;
94
+ RectInt bounds = Bounds ;
95
95
96
96
// The position is only valid if every cell is valid
97
97
for ( int i = 0 ; i < piece . cells . Length ; i ++ )
@@ -104,7 +104,7 @@ public bool IsValidPosition(Piece piece, Vector3Int position)
104
104
}
105
105
106
106
// A tile already occupies the position, thus invalid
107
- if ( this . tilemap . HasTile ( tilePosition ) ) {
107
+ if ( tilemap . HasTile ( tilePosition ) ) {
108
108
return false ;
109
109
}
110
110
}
@@ -114,7 +114,7 @@ public bool IsValidPosition(Piece piece, Vector3Int position)
114
114
115
115
public void ClearLines ( )
116
116
{
117
- RectInt bounds = this . Bounds ;
117
+ RectInt bounds = Bounds ;
118
118
int row = bounds . yMin ;
119
119
120
120
// Clear from bottom to top
@@ -132,14 +132,14 @@ public void ClearLines()
132
132
133
133
public bool IsLineFull ( int row )
134
134
{
135
- RectInt bounds = this . Bounds ;
135
+ RectInt bounds = Bounds ;
136
136
137
137
for ( int col = bounds . xMin ; col < bounds . xMax ; col ++ )
138
138
{
139
139
Vector3Int position = new Vector3Int ( col , row , 0 ) ;
140
140
141
141
// The line is not full if a tile is missing
142
- if ( ! this . tilemap . HasTile ( position ) ) {
142
+ if ( ! tilemap . HasTile ( position ) ) {
143
143
return false ;
144
144
}
145
145
}
@@ -149,13 +149,13 @@ public bool IsLineFull(int row)
149
149
150
150
public void LineClear ( int row )
151
151
{
152
- RectInt bounds = this . Bounds ;
152
+ RectInt bounds = Bounds ;
153
153
154
154
// Clear all tiles in the row
155
155
for ( int col = bounds . xMin ; col < bounds . xMax ; col ++ )
156
156
{
157
157
Vector3Int position = new Vector3Int ( col , row , 0 ) ;
158
- this . tilemap . SetTile ( position , null ) ;
158
+ tilemap . SetTile ( position , null ) ;
159
159
}
160
160
161
161
// Shift every row above down one
@@ -164,10 +164,10 @@ public void LineClear(int row)
164
164
for ( int col = bounds . xMin ; col < bounds . xMax ; col ++ )
165
165
{
166
166
Vector3Int position = new Vector3Int ( col , row + 1 , 0 ) ;
167
- TileBase above = this . tilemap . GetTile ( position ) ;
167
+ TileBase above = tilemap . GetTile ( position ) ;
168
168
169
169
position = new Vector3Int ( col , row , 0 ) ;
170
- this . tilemap . SetTile ( position , above ) ;
170
+ tilemap . SetTile ( position , above ) ;
171
171
}
172
172
173
173
row ++ ;
0 commit comments