mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-16 23:29:03 -06:00
24 lines
516 B
Lua
24 lines
516 B
Lua
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
||
|
|
||
|
local BagRandomizer = Randomizer:extend()
|
||
|
|
||
|
function BagRandomizer:new(pieces)
|
||
|
self.bag = {}
|
||
|
self.pieces = pieces
|
||
|
for i = 1, self.pieces do
|
||
|
table.insert(self.bag, i)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function BagRandomizer:generatePiece()
|
||
|
if next(self.bag) == nil then
|
||
|
for i = 1, self.pieces do
|
||
|
table.insert(self.bag, i)
|
||
|
end
|
||
|
end
|
||
|
local x = math.random(table.getn(self.bag))
|
||
|
return table.remove(self.bag, x)
|
||
|
end
|
||
|
|
||
|
return BagRandomizer
|