feat: print you win

fix clearing
main
Louis Pearson 2024-02-16 00:54:02 -07:00
parent ab202c758e
commit 0a3d6d4f24
1 changed files with 17 additions and 6 deletions

View File

@ -321,20 +321,19 @@ function update()
for i=3,6 do for i=3,6 do
if #stacks[1]~=0 and move_sel({1,#stacks[1]}, {i,#stacks[i]}) then if #stacks[1]~=0 and move_sel({1,#stacks[1]}, {i,#stacks[i]}) then
clear_count=clear_count+1 clear_count=clear_count+1
break
end end
if #stacks[2]~=0 and move_sel({2,#stacks[2]}, {i,#stacks[i]}) then if #stacks[2]~=0 and move_sel({2,#stacks[2]}, {i,#stacks[i]}) then
clear_count=clear_count+1 clear_count=clear_count+1
break
end end
for a=7,13 do for a=7,13 do
if #stacks[a]==0 then break end if #stacks[a]~=0 then
if move_sel({a,#stacks[a]}, {i,#stacks[i]}) then if move_sel({a,#stacks[a]}, {i,#stacks[i]}) then
clear_count=clear_count+1 clear_count=clear_count+1
break break
end end
end end
end end
end
if clear_count==0 then is_clearing=false end if clear_count==0 then is_clearing=false end
end end
last_left=left last_left=left
@ -353,6 +352,15 @@ function update()
end end
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 -- This finds the largest stack that can be moved
function find_top_of_stack(stack, position) function find_top_of_stack(stack, position)
local i=position local i=position
@ -524,6 +532,9 @@ function draw()
if is_clearing then if is_clearing then
rect(200,0,40,8,6) rect(200,0,40,8,6)
end end
if check_has_won() then
print("You Win!", 112, 70, 0)
end
end end
function render_card(c,x,y,state,below) function render_card(c,x,y,state,below)