feat: lay-off cards onto existing melds
parent
2166ea47cf
commit
e87b3c75bf
81
rummy.lua
81
rummy.lua
|
@ -94,12 +94,12 @@ function TIC()
|
|||
-- render melds on tabletop
|
||||
local meld_x=2
|
||||
for j,meld in ipairs(melds_on_tabletop) do
|
||||
for i,card in ipairs(meld) do
|
||||
local sel_state = nil
|
||||
if hovered and hovered.interest == card then
|
||||
if hovered and hovered.interest == meld then
|
||||
sel_state = 1
|
||||
end
|
||||
|
||||
for i,card in ipairs(meld) do
|
||||
card:render(meld_x, 10, false, sel_state)
|
||||
meld_x=meld_x + 8
|
||||
end
|
||||
|
@ -249,6 +249,17 @@ player_state_action = {
|
|||
hovered = nil
|
||||
return player_state_discard_confirm
|
||||
end
|
||||
elseif table_index_of(melds_on_tabletop, point_of_interest.interest) then
|
||||
local meld=point_of_interest.interest
|
||||
local meld_with_draft=meld:with(cards_in_meld_draft)
|
||||
if rummy_is_valid_meld(meld_with_draft) then
|
||||
for i,card in ipairs(cards_in_meld_draft) do
|
||||
table.remove(cards_in_hand, cards_in_hand:index_of(card))
|
||||
table.insert(meld, card)
|
||||
end
|
||||
meld:sort(rummy_hand_sort_comparison)
|
||||
cards_in_meld_draft=CardStack:new()
|
||||
end
|
||||
end
|
||||
return player_state_action
|
||||
end,
|
||||
|
@ -279,6 +290,19 @@ player_state_action = {
|
|||
})
|
||||
end
|
||||
|
||||
if #cards_in_meld_draft>0 then
|
||||
for i,meld in ipairs(melds_on_tabletop) do
|
||||
local meld_with_draft=meld:with(cards_in_meld_draft)
|
||||
if rummy_is_valid_meld(meld_with_draft) then
|
||||
table.insert(points_of_interest, {
|
||||
x=i * 36,
|
||||
y=10,
|
||||
interest=meld
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return points_of_interest
|
||||
end
|
||||
}
|
||||
|
@ -287,7 +311,12 @@ player_state_action = {
|
|||
player_state_secondary_action = {
|
||||
update=function(point_of_interest)
|
||||
if cards_in_hand:contains(point_of_interest.interest) then
|
||||
cards_in_meld_draft=CardStack:new({ point_of_interest.interest })
|
||||
if cards_in_meld_draft:contains(point_of_interest.interest) then
|
||||
table.remove(cards_in_meld_draft, cards_in_meld_draft:index_of(point_of_interest.interest))
|
||||
else
|
||||
table.insert(cards_in_meld_draft, point_of_interest.interest)
|
||||
cards_in_meld_draft:sort(rummy_hand_sort_comparison)
|
||||
end
|
||||
elseif point_of_interest.interest=="Discard" then
|
||||
if #cards_in_meld_draft==1 then
|
||||
table.remove(cards_in_hand, cards_in_hand:index_of(cards_in_meld_draft[1]))
|
||||
|
@ -296,6 +325,17 @@ player_state_secondary_action = {
|
|||
hovered = nil
|
||||
return player_state_discard_confirm
|
||||
end
|
||||
elseif table_index_of(melds_on_tabletop, point_of_interest.interest) then
|
||||
local meld=point_of_interest.interest
|
||||
local meld_with_draft=meld:with(cards_in_meld_draft)
|
||||
if rummy_is_valid_meld(meld_with_draft) then
|
||||
for i,card in ipairs(cards_in_meld_draft) do
|
||||
table.remove(cards_in_hand, cards_in_hand:index_of(card))
|
||||
table.insert(meld, card)
|
||||
end
|
||||
meld:sort(rummy_hand_sort_comparison)
|
||||
cards_in_meld_draft=CardStack:new()
|
||||
end
|
||||
end
|
||||
return player_state_secondary_action
|
||||
end,
|
||||
|
@ -318,6 +358,19 @@ player_state_secondary_action = {
|
|||
})
|
||||
end
|
||||
|
||||
if #cards_in_meld_draft>0 then
|
||||
for i,meld in ipairs(melds_on_tabletop) do
|
||||
local meld_with_draft=meld:with(cards_in_meld_draft)
|
||||
if rummy_is_valid_meld(meld_with_draft) then
|
||||
table.insert(points_of_interest, {
|
||||
x=i * 36,
|
||||
y=10,
|
||||
interest=meld
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return points_of_interest
|
||||
end
|
||||
}
|
||||
|
@ -422,6 +475,15 @@ function create_deck()
|
|||
return cards
|
||||
end
|
||||
|
||||
function table_index_of(table, value)
|
||||
for i,v in ipairs(table) do
|
||||
if v==value then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- CardStack
|
||||
CardStack = {}
|
||||
function CardStack:new(obj)
|
||||
|
@ -484,6 +546,19 @@ function CardStack:index_of(card_sought)
|
|||
return nil
|
||||
end
|
||||
|
||||
-- returns a new CardStack containing the cards from self and other. Does not remove the cards from self and other.
|
||||
function CardStack:with(other)
|
||||
local new_stack=CardStack:new()
|
||||
for i,card in ipairs(self) do
|
||||
table.insert(new_stack, card)
|
||||
end
|
||||
for i,card in ipairs(other) do
|
||||
table.insert(new_stack, card)
|
||||
end
|
||||
return new_stack
|
||||
end
|
||||
|
||||
|
||||
-- Card rendering stuff
|
||||
suit_icon={34,35,33,36}
|
||||
suit_color={0,0,2,2}
|
||||
|
|
Loading…
Reference in New Issue