cambridge-modpack/tetris/randomizers/bag_konoha.lua

29 lines
733 B
Lua
Raw Permalink Normal View History

2020-11-11 21:24:56 -06:00
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 = love.math.random(#self.bag)
2020-11-11 21:24:56 -06:00
local temp = table.remove(self.bag, x)
if temp == self.prev and not self.allowrepeat then
local y = love.math.random(#self.bag)
2020-11-11 21:24:56 -06:00
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