mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 18:49:03 -06:00
6f4adf5aad
...number of pieces (fixes #31)
21 lines
480 B
Lua
21 lines
480 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 = math.random(table.getn(self.bag))
|
|
return table.remove(self.bag, x)
|
|
end
|
|
|
|
return BagRandomizer
|