feat: add win counter
parent
76f62a5e59
commit
ce5a238870
|
@ -5,6 +5,7 @@
|
|||
-- license: MIT License (change this to your license of choice)
|
||||
-- version: 0.1
|
||||
-- script: lua
|
||||
-- saveId: sawayama-solitaire
|
||||
|
||||
|
||||
suit_icon={34,35,33,36}
|
||||
|
@ -48,6 +49,9 @@ last_left=false
|
|||
current_stack=8
|
||||
is_clearing=false
|
||||
left_hold={length=1200,length_display=600,start=nil}
|
||||
should_check_for_win=false
|
||||
WIN_COUNT_SLOT=0
|
||||
win_count = pmem(WIN_COUNT_SLOT)
|
||||
|
||||
function create_deck()
|
||||
local cards={}
|
||||
|
@ -326,6 +330,19 @@ function update()
|
|||
if clear_count==0 then is_clearing=false end
|
||||
end
|
||||
last_left=left
|
||||
|
||||
if should_check_for_win then
|
||||
local has_won=true
|
||||
for i=3,6 do
|
||||
local stack=stacks[i]
|
||||
has_won=(has_won and stack[#stack].rank>=13)
|
||||
end
|
||||
if has_won then
|
||||
pmem(WIN_COUNT_SLOT, pmem(WIN_COUNT_SLOT) + 1)
|
||||
win_count = pmem(WIN_COUNT_SLOT)
|
||||
end
|
||||
should_check_for_win=false
|
||||
end
|
||||
end
|
||||
|
||||
-- This finds the largest stack that can be moved
|
||||
|
@ -391,6 +408,9 @@ function move_sel(hand,hover)
|
|||
stacks[hover[1]],
|
||||
table.remove(stacks[hand[1]], hand[2]))
|
||||
end
|
||||
|
||||
should_check_for_win=true
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -450,6 +470,7 @@ end
|
|||
|
||||
function draw()
|
||||
cls(12)
|
||||
print(string.format("Win Count: %4d", win_count),160,4,13)
|
||||
for i=1,#locations do
|
||||
local location=locations[i]
|
||||
if #stacks[location[1]]==0 then
|
||||
|
|
Loading…
Reference in New Issue