cambridge/tetris/modes/strategy.lua

158 lines
3.7 KiB
Lua

require 'funcs'
local GameMode = require 'tetris.modes.gamemode'
local Piece = require 'tetris.components.piece'
local History6RollsRandomizer = require 'tetris.randomizers.history_6rolls'
local StrategyGame = GameMode:extend()
StrategyGame.name = "Strategy"
StrategyGame.hash = "Strategy"
StrategyGame.tagline = "You have lots of time to think! Can you use it to place a piece fast?"
StrategyGame.arr = 1
StrategyGame.drop_speed = 1
function StrategyGame:new()
StrategyGame.super:new()
self.level = 0
self.clear = false
self.completed = false
self.roll_frames = 0
self.combo = 1
self.randomizer = History6RollsRandomizer()
self.enable_hold = false
self.next_queue_length = 1
end
function StrategyGame:getARE()
if self.level < 100 then return 60
elseif self.level < 200 then return 54
elseif self.level < 300 then return 48
elseif self.level < 400 then return 42
elseif self.level < 500 then return 36
elseif self.level < 600 then return 30
elseif self.level < 700 then return 24
elseif self.level < 800 then return 21
elseif self.level < 900 then return 18
else return 15 end
end
function StrategyGame:getLineARE()
return self:getARE()
end
function StrategyGame:getDasLimit()
return 6
end
function StrategyGame:getLineClearDelay()
return self:getARE()
end
function StrategyGame:getLockDelay()
if self.level < 500 then return 8
elseif self.level < 700 then return 6
else return 4 end
end
function StrategyGame:getGravity()
return 20
end
function StrategyGame:getNextPiece(ruleset)
return {
skin = "2tie",
shape = self.randomizer:nextPiece(),
orientation = ruleset:getDefaultOrientation(),
}
end
function StrategyGame:advanceOneFrame()
if self.clear then
self.roll_frames = self.roll_frames + 1
if self.roll_frames > 1936 then
switchBGM(nil)
self.completed = true
end
elseif self.ready_frames == 0 then
self.frames = self.frames + 1
end
return true
end
function StrategyGame:onPieceEnter()
if (self.level % 100 ~= 99) and not self.clear and self.frames ~= 0 then
self.level = self.level + 1
end
end
function StrategyGame:onLineClear(cleared_row_count)
if not self.clear then
self.level = math.min(999, self.level + cleared_row_count)
if self.level == 999 then
self.clear = true
end
end
end
function StrategyGame:updateScore(level, drop_bonus, cleared_lines)
if cleared_lines > 0 then
self.score = self.score + (
(math.ceil((level + cleared_lines) / 4) + drop_bonus) *
cleared_lines * (cleared_lines * 2 - 1) * (self.combo * 2 - 1)
)
self.lines = self.lines + cleared_lines
self.combo = self.combo + cleared_lines - 1
else
self.drop_bonus = 0
self.combo = 1
end
end
function StrategyGame:setNextOpacity(i)
if self.are == 0 then love.graphics.setColor(1, 1, 1, 1)
else love.graphics.setColor(1, 1, 1, self.are / self:getARE())
end
end
function StrategyGame:drawGrid()
self.grid:draw()
end
function StrategyGame:drawScoringInfo()
StrategyGame.super.drawScoringInfo(self)
love.graphics.setColor(1, 1, 1, 1)
local text_x = config["side_next"] and 320 or 240
love.graphics.setFont(font_3x5_2)
love.graphics.printf("SCORE", text_x, 200, 40, "left")
love.graphics.printf("LEVEL", text_x, 320, 40, "left")
love.graphics.setFont(font_3x5_3)
love.graphics.printf(self.score, text_x, 220, 90, "left")
love.graphics.printf(self.level, text_x, 340, 50, "right")
if self.clear then
love.graphics.printf(self.level, text_x, 370, 50, "right")
else
love.graphics.printf(math.floor(self.level / 100 + 1) * 100, text_x, 370, 50, "right")
end
end
function StrategyGame:getBackground()
return math.floor(self.level / 100)
end
function StrategyGame:getHighscoreData()
return {
level = self.level,
frames = self.frames,
}
end
return StrategyGame