2021-01-06 21:53:44 -06:00
|
|
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
|
|
|
|
local BagRandomizer = Randomizer:extend()
|
|
|
|
|
2021-10-16 19:35:47 -05:00
|
|
|
function BagRandomizer:new(piece_table)
|
2021-01-06 21:53:44 -06:00
|
|
|
self.bag = {}
|
2021-10-16 19:35:47 -05:00
|
|
|
self.possible_pieces = piece_table
|
2021-01-06 21:53:44 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function BagRandomizer:generatePiece()
|
|
|
|
if next(self.bag) == nil then
|
2021-10-16 19:35:47 -05:00
|
|
|
for _, v in pairs(self.possible_pieces) do
|
|
|
|
table.insert(self.bag, v)
|
2021-01-06 21:53:44 -06:00
|
|
|
end
|
|
|
|
end
|
2021-12-08 20:23:00 -06:00
|
|
|
local x = love.math.random(table.getn(self.bag))
|
2021-01-06 21:53:44 -06:00
|
|
|
return table.remove(self.bag, x)
|
|
|
|
end
|
|
|
|
|
|
|
|
return BagRandomizer
|