Changed row initialization to also use parametrized width.

This commit is contained in:
Joe Zeng 2021-01-10 22:52:56 -05:00 committed by GitHub
parent 0f09d47e60
commit 2d63ca8ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,8 +129,12 @@ function Grid:clearClearedRows()
self.grid[above_row] = self.grid[above_row - 1] self.grid[above_row] = self.grid[above_row - 1]
self.grid_age[above_row] = self.grid_age[above_row - 1] self.grid_age[above_row] = self.grid_age[above_row - 1]
end end
self.grid[1] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[1] = {}
self.grid_age[1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[1] = {}
for i = 1, self.width do
self.grid[1][i] = empty
self.grid_age[1][i] = 0
end
end end
end end
return true return true
@ -141,10 +145,11 @@ function Grid:copyBottomRow()
self.grid[row] = self.grid[row+1] self.grid[row] = self.grid[row+1]
self.grid_age[row] = self.grid_age[row+1] self.grid_age[row] = self.grid_age[row+1]
end end
self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {}
for col = 1, self.width do for i = 1, self.width do
self.grid[24][col] = (self.grid[23][col] == empty) and empty or block self.grid[24][i] = (self.grid[23][i] == empty) and empty or block
self.grid_age[24][i] = 0
end end
return true return true
end end
@ -154,10 +159,11 @@ function Grid:garbageRise(row_vals)
self.grid[row] = self.grid[row+1] self.grid[row] = self.grid[row+1]
self.grid_age[row] = self.grid_age[row+1] self.grid_age[row] = self.grid_age[row+1]
end end
self.grid[24] = {empty, empty, empty, empty, empty, empty, empty, empty, empty, empty} self.grid[24] = {}
self.grid_age[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} self.grid_age[24] = {}
for col = 1, self.width do for i = 1, self.width do
self.grid[24][col] = (row_vals[col] == "e") and empty or block self.grid[24][i] = (row_vals[i] == "e") and empty or block
self.grid_age[24][i] = 0
end end
end end