Ruleset and randomizer refactoring (Read comments)
You can now specify an arbitrary number of pieces for a ruleset. The randomizers will adjust accordingly. Expect a pento ruleset in the modpack soon! Also, gamemode skin selection has been refactored.
This commit is contained in:
23
tetris/randomizers/bag.lua
Normal file
23
tetris/randomizers/bag.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user