mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 02:09:02 -06:00
21 lines
485 B
Lua
21 lines
485 B
Lua
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
local BagRandomizer = Randomizer:extend()
|
|
|
|
function BagRandomizer:new(piece_table)
|
|
self.bag = {}
|
|
self.possible_pieces = piece_table
|
|
end
|
|
|
|
function BagRandomizer:generatePiece()
|
|
if next(self.bag) == nil then
|
|
for _, v in pairs(self.possible_pieces) do
|
|
table.insert(self.bag, v)
|
|
end
|
|
end
|
|
local x = love.math.random(table.getn(self.bag))
|
|
return table.remove(self.bag, x)
|
|
end
|
|
|
|
return BagRandomizer
|