-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpile_discard.lua
71 lines (61 loc) · 1.76 KB
/
pile_discard.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- class Discard, derived from Pile
local Pile = require 'pile'
local Util = require 'util'
local CC = require 'cc'
---@class (exact) Discard : Pile
---@field __index Discard
---@field new function
local Discard = {}
Discard.__index = Discard
setmetatable(Discard, {__index = Pile})
function Discard.new(o)
o.category = 'Discard'
o.fanType = 'FAN_NONE'
o.moveType = 'MOVE_NONE'
o = Pile.prepare(o)
table.insert(_G.BAIZE.piles, o)
table.insert(_G.BAIZE.discards, o)
return setmetatable(o, Discard)
end
function Discard:push(c)
Pile.push(self, c)
-- Discard cards are always prone
c:flipDown()
end
---@return string|nil
function Discard:acceptTailError(tail)
if #self.cards ~= 0 then
return 'Can only move cards to an empty Discard'
end
for _, c in ipairs(tail) do
if c.prone then
return 'Cannot move a face down card to a Discard'
end
end
if #tail ~= #_G.BAIZE.deck / #_G.BAIZE.discards then
return 'Can only move a full set of cards to a Discard'
end
-- added 2023-01
if Util.unsortedPairs(tail, CC.DownSuit) > 0 then
return 'Cards must the the same suit and go down in rank'
end
-- Scorpion tails can always be moved, but Mrs Mop/Simple Simon tails
-- must be conformant to be moved
return _G.BAIZE.script:moveTailError(tail)
end
function Discard:tailTapped(tail)
-- do nothing
end
---@return integer
function Discard:unsortedPairs()
-- you can only put a sorted sequence into a Discard, so this will always be zero
return 0
end
function Discard:draw()
local b = _G.BAIZE
local x, y = self:screenPos()
love.graphics.setColor(1, 1, 1, 0.1)
love.graphics.setLineWidth(1)
love.graphics.rectangle('fill', x, y, b.cardWidth, b.cardHeight, b.cardRadius, b.cardRadius)
end
return Discard