Page 1 of 2
Klondike Solitaire
Posted: Tue Jul 05, 2011 3:17 am
by Ortzinator
A little proud of this because although I've been programming for years, this is the first thing I've "finished".
http://dl.dropbox.com/u/313489/solitaire.love
Known issues:
- Nothing happens when you win
- You have to restart to start a new game
- Card graphics are ugly
- Possible insufficient shuffling???
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 5:09 am
by ivan
Pretty good. I played it a few times but couldn't beat it either.
Just a minor suggestion: gameplay would 'feel' better if you could actually drag the cards with the mouse.
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 8:35 am
by bartbes
It seems as if I regain my previous card when I put one down, so say I draw a 7 of hearts, then an 8 of spades, if I put the 8 down, I see the 7 again, that's not how it's supposed to work, there should be 3 cards drawn!
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 8:47 am
by ivan
bartbes wrote:that's not how it's supposed to work, there should be 3 cards drawn!
This is 'Vegas' style solitaire where only 1 card is drawn at a time and they do not rotate once you've drawn all of them.
Maybe it's just me, but I find this style of solitaire much more exciting then when 3 cards are drawn.
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 10:13 am
by Robin
I can see why no-one won yet. The diamonds 5 is missing.
And I think you know why. In your code, I can see you counting from 0 in your numeric indices for tables. However, Lua counts from 1. I think something went wrong there.
EDIT: just to be clear, in this case diamonds 5 was missing, but I think it is a different card each time, either because it is at location 0, when Lua starts with 1, or at location #table, and you only count to #table - 1.
EDIT 2: also, I see a few instances of "pairs" where you should use "ipairs".
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 6:57 pm
by Ortzinator
Nice catch
And thanks for taking the time to look at the code. I didn't know about ipairs. You were right about the problem, the shuffle function was nuking one of the cards.
New version is up, same link.
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 7:48 pm
by tentus
Yep, nothing happens when you win. A couple of things:
Could you track/show the number of moves?
And could you remove the ".lua" from line 2 of main.lua? It won't run in the next version of Love if its there.
Also, moving cards from the "finished" stack back into the play area can be a bit tricky. Occasionally you need to resort, so it's something you should probably code an exception for.
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 7:53 pm
by Robin
Happy to help.
It works much better, and now the game is winnable.
One small tip:
Code: Select all
quads = {}
quads["C"] = {}
quads["D"] = {}
quads["H"] = {}
quads["S"] = {}
is the same as:
Code: Select all
quads = {C = {}, D = {}, H = {}, S = {}}
Re: Klondike Solitaire
Posted: Tue Jul 05, 2011 9:00 pm
by Ortzinator
tentus wrote:Could you track/show the number of moves?
What should I consider a move? I'm thinking of omitting moving to the foundations.
And could you remove the ".lua" from line 2 of main.lua? It won't run in the next version of Love if its there.
Done, thanks.
Also, moving cards from the "finished" stack back into the play area can be a bit tricky. Occasionally you need to resort, so it's something you should probably code an exception for.
Can you elaborate? It seems to work fine for me.
Robin wrote:Happy to help.
It works much better, and now the game is winnable.
One small tip:
Code: Select all
quads = {}
quads["C"] = {}
quads["D"] = {}
quads["H"] = {}
quads["S"] = {}
is the same as:
Code: Select all
quads = {C = {}, D = {}, H = {}, S = {}}
That's much cleaner, thanks.
Re: Klondike Solitaire
Posted: Wed Jul 06, 2011 6:23 am
by BlackBulletIV
Robin wrote:One small tip:
Code: Select all
quads = {}
quads["C"] = {}
quads["D"] = {}
quads["H"] = {}
quads["S"] = {}
is the same as:
Code: Select all
quads = {C = {}, D = {}, H = {}, S = {}}
But if you really want to do it line by line, for string keys you can do this:
Code: Select all
quads = {}
quads.C = {}
quads.D = {}
quads.H = {}
quads.S = {}