Compare commits
No commits in common. "f7b10ca35912dd7eb590be0d4a2f986b36485b1c" and "4555a95357a9d04fab0c284571386bd8cb557345" have entirely different histories.
f7b10ca359
...
4555a95357
130
solitaire.lua
130
solitaire.lua
|
@ -111,6 +111,15 @@ function BOOT()
|
|||
end
|
||||
return
|
||||
end
|
||||
|
||||
stacks[1] = create_deck()
|
||||
shuffle(stacks[1])
|
||||
table.insert(locations,{1,2,2})
|
||||
-- Set up stacks
|
||||
for i=1,7 do
|
||||
stacks[i+6]=draw_cards(stacks[1], i)
|
||||
table.insert(locations,{i+6,i*30,30})
|
||||
end
|
||||
end
|
||||
|
||||
function TIC()
|
||||
|
@ -150,19 +159,7 @@ aces of each suite.
|
|||
]], 4, 78, 15)
|
||||
|
||||
local mx,my,mleft,middle,mright,scrollx,scrolly=mouse()
|
||||
if btnp(4) or btnp(5) or mleft then
|
||||
game_state='PLAY'
|
||||
|
||||
-- draw cards
|
||||
stacks[1] = create_deck()
|
||||
shuffle(stacks[1])
|
||||
table.insert(locations,{1,2,2})
|
||||
-- Set up stacks
|
||||
for i=1,7 do
|
||||
stacks[i+6]=draw_cards(stacks[1], i)
|
||||
table.insert(locations,{i+6,i*30,30})
|
||||
end
|
||||
end
|
||||
if btnp(4) or btnp(5) or mleft then game_state='PLAY' end
|
||||
end
|
||||
|
||||
function update()
|
||||
|
@ -215,11 +212,6 @@ function update()
|
|||
end
|
||||
if si>=3 and si<7 and c_right then
|
||||
c_hover[1]=7
|
||||
if hand then
|
||||
c_hover[2]=#stacks[c_hover[1]]
|
||||
else
|
||||
c_hover[2]=find_top_of_stack(stacks[c_hover[1]], #stacks[c_hover[1]])
|
||||
end
|
||||
end
|
||||
if si>7 and c_left then
|
||||
c_hover[1]=si-1
|
||||
|
@ -279,23 +271,67 @@ function update()
|
|||
end
|
||||
mouse_pos={mx,my}
|
||||
|
||||
local mouse_hover=card_at_point(mx,my)
|
||||
local mouse_location=location_at_point(mx,my)
|
||||
local hover=card_at_point(mx,my)
|
||||
local location=location_at_point(mx,my)
|
||||
|
||||
if mouse_moved then c_hover=nil end
|
||||
|
||||
if mright or c_back then hand=nil end
|
||||
|
||||
if c_hover then
|
||||
if #stacks[c_hover[1]]~=0 then
|
||||
update_selected(c_sel, c_sel_last, c_hover, nil)
|
||||
hover=c_hover
|
||||
elseif #stacks[c_hover[1]]==0 then
|
||||
update_selected(c_sel, c_sel_last, nil, c_hover)
|
||||
location=c_hover
|
||||
end
|
||||
else
|
||||
update_selected(mleft, mleft_last, mouse_hover, mouse_location)
|
||||
end
|
||||
|
||||
local left=false
|
||||
if mleft or c_sel then
|
||||
left=true
|
||||
end
|
||||
|
||||
local right=false
|
||||
if mright or c_back then
|
||||
right=true
|
||||
end
|
||||
|
||||
if right then hand=nil end
|
||||
|
||||
if not last_left and hover then
|
||||
if not exhausted and hover[1]==1 and left then
|
||||
hand=nil
|
||||
draw_cards_to(stacks[1],stacks[2],3)
|
||||
if #stacks[1]==0 then
|
||||
exhausted=true
|
||||
end
|
||||
elseif hand and hover and
|
||||
hand[1]==hover[1] and hand[2]==hover[2] and left
|
||||
then
|
||||
for i=3,6 do
|
||||
if move_sel(hand, {i,#stacks[i]}) then
|
||||
break
|
||||
end
|
||||
end
|
||||
hand=nil
|
||||
elseif hand and hover and left then
|
||||
move_sel(hand,hover)
|
||||
hand=nil
|
||||
elseif not hand and left then
|
||||
if sel_can_move(hover) then
|
||||
stacks[hover[1]][hover[2]].state=2
|
||||
hand={hover[1],hover[2]}
|
||||
end
|
||||
elseif stacks[hover[1]][hover[2]].state==0 then
|
||||
if sel_can_move(hover) then
|
||||
for i=hover[2],#stacks[hover[1]] do
|
||||
stacks[hover[1]][i].state=1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if left and location and hand then
|
||||
move_sel(hand,location)
|
||||
hand=nil
|
||||
end
|
||||
for j,stack in ipairs(stacks) do
|
||||
local stack=stacks[j]
|
||||
local stackx=0
|
||||
|
@ -336,8 +372,7 @@ function update()
|
|||
end
|
||||
if clear_count==0 then is_clearing=false end
|
||||
end
|
||||
mleft_last=mleft
|
||||
c_sel_last=c_sel
|
||||
last_left=left
|
||||
|
||||
if should_check_for_win then
|
||||
local has_won=true
|
||||
|
@ -353,45 +388,6 @@ function update()
|
|||
end
|
||||
end
|
||||
|
||||
function update_selected(select_input, last_select_input, hovered, location)
|
||||
if not last_select_input and hovered then
|
||||
if not exhausted and hovered[1]==1 and select_input then
|
||||
hand=nil
|
||||
draw_cards_to(stacks[1],stacks[2],3)
|
||||
if #stacks[1]==0 then
|
||||
exhausted=true
|
||||
end
|
||||
elseif hand and hovered and
|
||||
hand[1]==hovered[1] and hand[2]==hovered[2] and select_input
|
||||
then
|
||||
for i=3,6 do
|
||||
if move_sel(hand, {i,#stacks[i]}) then
|
||||
break
|
||||
end
|
||||
end
|
||||
hand=nil
|
||||
elseif hand and hovered and select_input then
|
||||
move_sel(hand,hovered)
|
||||
hand=nil
|
||||
elseif not hand and select_input then
|
||||
if sel_can_move(hovered) then
|
||||
stacks[hovered[1]][hovered[2]].state=2
|
||||
hand={hovered[1],hovered[2]}
|
||||
end
|
||||
elseif hovered and stacks[hovered[1]][hovered[2]].state==0 then
|
||||
if sel_can_move(hovered) then
|
||||
for i=hovered[2],#stacks[hovered[1]] do
|
||||
stacks[hovered[1]][i].state=1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if select_input and location and hand then
|
||||
move_sel(hand,location)
|
||||
hand=nil
|
||||
end
|
||||
end
|
||||
|
||||
function check_has_won()
|
||||
local has_won=true
|
||||
for i=3,6 do
|
||||
|
|
Loading…
Reference in New Issue