mirror of
https://github.com/SashLilac/cambridge-modpack.git
synced 2024-11-22 22:09:02 -06:00
29 lines
723 B
Lua
29 lines
723 B
Lua
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
||
|
|
||
|
local BagKonoha = Randomizer:extend()
|
||
|
|
||
|
function BagKonoha:initialize()
|
||
|
self.bag = {"I", "J", "L", "O", "T"}
|
||
|
self.prev = nil
|
||
|
self.allowrepeat = false
|
||
|
self.generated = 0
|
||
|
end
|
||
|
|
||
|
function BagKonoha:generatePiece()
|
||
|
self.generated = self.generated + 1
|
||
|
if #self.bag == 0 then
|
||
|
self.bag = {"I", "J", "L", "O", "T"}
|
||
|
end
|
||
|
local x = math.random(#self.bag)
|
||
|
local temp = table.remove(self.bag, x)
|
||
|
if temp == self.prev and not self.allowrepeat then
|
||
|
local y = math.random(#self.bag)
|
||
|
table.insert(self.bag, temp) -- should insert at the end of the bag, bag[y] doesnt change
|
||
|
temp = table.remove(self.bag, y)
|
||
|
end
|
||
|
self.prev = temp
|
||
|
return temp
|
||
|
end
|
||
|
|
||
|
return BagKonoha
|