mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-12-23 11:19:03 -06:00
25 lines
550 B
Lua
25 lines
550 B
Lua
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
local BagRandomizer = Randomizer:extend()
|
|
|
|
function BagRandomizer:new(pieces)
|
|
self.bag = {}
|
|
self.possible_pieces = pieces
|
|
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
|