From 971151e21003e241230948a6c2821f4db70f27a7 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 4 Oct 2020 22:49:17 -0400 Subject: [PATCH] Added 5 bag randomizer --- tetris/randomizers/bag5.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tetris/randomizers/bag5.lua diff --git a/tetris/randomizers/bag5.lua b/tetris/randomizers/bag5.lua new file mode 100644 index 0000000..7344bcb --- /dev/null +++ b/tetris/randomizers/bag5.lua @@ -0,0 +1,17 @@ +local Randomizer = require 'tetris.randomizers.randomizer' + +local Bag5Randomizer = Randomizer:extend() + +function Bag5Randomizer:initialize() + self.bag = {"I", "J", "L", "O", "T"} +end + +function Bag5Randomizer:generatePiece() + if next(self.bag) == nil then + self.bag = {"I", "J", "L", "O", "T"} + end + local x = math.random(table.getn(self.bag)) + return table.remove(self.bag, x) +end + +return Bag5Randomizer