Klondike Solitaire

Show off your games, demos and other (playable) creations.
Ortzinator
Prole
Posts: 5
Joined: Wed Mar 16, 2011 5:27 am

Klondike Solitaire

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???
Last edited by Ortzinator on Fri Jul 22, 2011 3:58 pm, edited 1 time in total.

ivan
Party member
Posts: 1549
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Klondike Solitaire

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.

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Klondike Solitaire

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!

ivan
Party member
Posts: 1549
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Klondike Solitaire

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.

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Klondike Solitaire

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".
Attachments
Look for it. It isn't there.
no-diamonds-5.png (99.01 KiB) Viewed 3319 times

Ortzinator
Prole
Posts: 5
Joined: Wed Mar 16, 2011 5:27 am

Re: Klondike Solitaire

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.

tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Klondike Solitaire

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.
Kurosuke needs beta testers

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Klondike Solitaire

Happy to help.

It works much better, and now the game is winnable.

One small tip:

Code: Select all

quads = {}
quads["S"] = {}
is the same as:

Code: Select all

quads = {C = {}, D = {}, H = {}, S = {}}

Ortzinator
Prole
Posts: 5
Joined: Wed Mar 16, 2011 5:27 am

Re: Klondike Solitaire

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["S"] = {}
is the same as:

Code: Select all

quads = {C = {}, D = {}, H = {}, S = {}}
That's much cleaner, thanks.

BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Klondike Solitaire

Robin wrote:One small tip:

Code: Select all

quads = {}
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.S = {}