diff --git a/solitaire.lua b/solitaire.lua index a214389..8ef4320 100644 --- a/solitaire.lua +++ b/solitaire.lua @@ -321,17 +321,16 @@ function update() for i=3,6 do if #stacks[1]~=0 and move_sel({1,#stacks[1]}, {i,#stacks[i]}) then clear_count=clear_count+1 - break end if #stacks[2]~=0 and move_sel({2,#stacks[2]}, {i,#stacks[i]}) then clear_count=clear_count+1 - break end for a=7,13 do - if #stacks[a]==0 then break end - if move_sel({a,#stacks[a]}, {i,#stacks[i]}) then - clear_count=clear_count+1 - break + if #stacks[a]~=0 then + if move_sel({a,#stacks[a]}, {i,#stacks[i]}) then + clear_count=clear_count+1 + break + end end end end @@ -353,6 +352,15 @@ function update() end end +function check_has_won() + local has_won=true + for i=3,6 do + local stack=stacks[i] + has_won=(has_won and #stack>0 and stack[#stack].rank>=13) + end + return has_won +end + -- This finds the largest stack that can be moved function find_top_of_stack(stack, position) local i=position @@ -524,6 +532,9 @@ function draw() if is_clearing then rect(200,0,40,8,6) end + if check_has_won() then + print("You Win!", 112, 70, 0) + end end function render_card(c,x,y,state,below)