From ce5a2388705dc54670a74f1296eba2ad9a762e4d Mon Sep 17 00:00:00 2001 From: geemili Date: Thu, 15 Feb 2024 22:56:18 -0700 Subject: [PATCH] feat: add win counter --- solitaire.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solitaire.lua b/solitaire.lua index 66654c2..fa02df6 100644 --- a/solitaire.lua +++ b/solitaire.lua @@ -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