Solitaire Card Game Code, anyone? :)

Hello, all… Corona SDK is a blast, there is no arguing that!

The past year has been tough on this newbie, but I’m gaining!

Can anyone direct me to some corona game code for a solitaire card game, so that I may follow the code and see how such games have been approached?

I was going to take a stab at coding a card game from the dark, (being a newbie) and seeing what approach I would stumble through myself, but, I was thinking about what Horacebury said, “Ask questions early.”

So, it’s been a year.  :slight_smile:

Thanks in advance.

Chris

Does anyone have a solitaire card game that they are currently selling, preferably on Amazon; and if so, would said person(s) be willing to share the game code if a person were to purchase the app?

Being new to this “Shtuff” I would like to wrap my mind around some game code, so as to have that “birds eye” view of a project.

Being new, and self-taught, the learning curve has been, and, is still steep and lengthy.

Far from wanting to cut any corners, I am not trying to piggy back on any one’s code, I just do not want to reinvent the wheel.

I am just curious how card games are approached in a program.

I actually do not like the game solitaire, but I want to learn how it can be coded, for the learning experience.

Anyone? Anyone? Solitaire? Anyone? I am willing to buy the app, I just want to learn how to code it too.

Is that wrong to ask?

Thanks anyway, even if no reply is forth coming.

:slight_smile:

PEACEAGE

Chris

Ok, let’s try this. :slight_smile:

Can anyone direct me to a book that I may purchase that discusses the ins and outs of programming “the nuances of a card game”?; preferably in LUA, or Corona; but I guess, I could stumble through a book written in C.

I just need a place to start, a template of sorts, to see how card games “can be” handled.

I assume these exercises are as in-disposable as the “Hello world” programs force-fed to every Computer Science Major?

Any leads would be appreciated. Otherwise, I will reinvent the wheel, and see how round she turns out. 

Chris

I don’t know how useful these are, but found from a quick google search:

https://github.com/david-torres/Corona-Card-Game-Template

https://www.youtube.com/watch?v=zwaT_gb9D5s

http://www.coronaforums.org/Thread-Card-Game-Sample-Include-All-Basic-Animation-Operation

As for solitaire, I guess the basic structure would be:

  1. A table containing 52 cards, which is then shuffled. Each card is a display group and has a a suit, red/black, rank, and face-up/down property.

i.e. for ace of clubs

[lua]

local c = display.newGroup()

c.suit = “clubs”

c.red = false

c.rank = 1

c.faceUp = false

c.card = display.newImageRect(c, “card1.png”, 100,50)

c.back = display.newImageRect(c, “cardback.png”, 100, 50)

cards[1] = c

[/lua]

You can then show or hide the cardback using c.back.alpha == 1 or c.back.alpha == 0 depending on the value of c.faceUp.

  1. A master table, containing a sub-table for each column of cards. Each entry in the table will either be 0, or refer to a card ID. The rule being that a card can only be inserted onto the stack if the card being dragged has a rank 1 lower than the card at the top of the stack, and is of the opposite colour, or if the stack is empty and the card being dragged is a king.

3) Two table containing those cards that aren’t in the columns and haven’t been placed in the suit stacks yet. Clicking the left stack moves the card from the top of that stack to the top of the right stack, until the left stack is empty.

  1. A final table, containing a table for each of the suit stacks, with the rule that a card can only be placed on the stack if its rank is one higher than the top of the stack and it’s of the same suit, or the stack is empty and the card is an Ace.

Steps 1 through 4, are very inspirational, Nick.

Thank you! :slight_smile:

This will keep me quiet for a while.

PEACE

Nick,

Your assistance has proved very absolutely valuable to me.

I had one question, that I seem to be a bit confused about.

A display group is merely a table, if I am not misunderstanding; also, when assigning an image to the card.spriteInstance,

WHICH I NAMED, card.faceCard, I am assuming I use newSprite() for that image?

And for the back of the card, I can use card.backCard = newImageRect()

The confusion arose in my brain, when I tried applying a newSprite() to both card.spriteInstance, and to the card.backCard.

I just felt as though I was stepping on toes having TWO SPRITE INSTANCES for one card.

It hit me that I could probably use newImage(), newImageRect, or newSprite() for both.

As, newSprite() mainly has the ability to animate graphics.

I am confusing myself aren’t I?

Also, am I completely on the wrong path for attempting to OOP a card game?

I would like to use an OOP mindset, for learning purposes, as I have READ a lot about it.

I am sure a card game could be be done either way.

Is it ridiculous to use an OOP approach?

Please say, NO!

Thanks for your help, you really gave my creativity a bust!

:slight_smile:

Chris

Does anyone have a solitaire card game that they are currently selling, preferably on Amazon; and if so, would said person(s) be willing to share the game code if a person were to purchase the app?

Being new to this “Shtuff” I would like to wrap my mind around some game code, so as to have that “birds eye” view of a project.

Being new, and self-taught, the learning curve has been, and, is still steep and lengthy.

Far from wanting to cut any corners, I am not trying to piggy back on any one’s code, I just do not want to reinvent the wheel.

I am just curious how card games are approached in a program.

I actually do not like the game solitaire, but I want to learn how it can be coded, for the learning experience.

Anyone? Anyone? Solitaire? Anyone? I am willing to buy the app, I just want to learn how to code it too.

Is that wrong to ask?

Thanks anyway, even if no reply is forth coming.

:slight_smile:

PEACEAGE

Chris

Ok, let’s try this. :slight_smile:

Can anyone direct me to a book that I may purchase that discusses the ins and outs of programming “the nuances of a card game”?; preferably in LUA, or Corona; but I guess, I could stumble through a book written in C.

I just need a place to start, a template of sorts, to see how card games “can be” handled.

I assume these exercises are as in-disposable as the “Hello world” programs force-fed to every Computer Science Major?

Any leads would be appreciated. Otherwise, I will reinvent the wheel, and see how round she turns out. 

Chris

I don’t know how useful these are, but found from a quick google search:

https://github.com/david-torres/Corona-Card-Game-Template

https://www.youtube.com/watch?v=zwaT_gb9D5s

http://www.coronaforums.org/Thread-Card-Game-Sample-Include-All-Basic-Animation-Operation

As for solitaire, I guess the basic structure would be:

  1. A table containing 52 cards, which is then shuffled. Each card is a display group and has a a suit, red/black, rank, and face-up/down property.

i.e. for ace of clubs

[lua]

local c = display.newGroup()

c.suit = “clubs”

c.red = false

c.rank = 1

c.faceUp = false

c.card = display.newImageRect(c, “card1.png”, 100,50)

c.back = display.newImageRect(c, “cardback.png”, 100, 50)

cards[1] = c

[/lua]

You can then show or hide the cardback using c.back.alpha == 1 or c.back.alpha == 0 depending on the value of c.faceUp.

  1. A master table, containing a sub-table for each column of cards. Each entry in the table will either be 0, or refer to a card ID. The rule being that a card can only be inserted onto the stack if the card being dragged has a rank 1 lower than the card at the top of the stack, and is of the opposite colour, or if the stack is empty and the card being dragged is a king.

3) Two table containing those cards that aren’t in the columns and haven’t been placed in the suit stacks yet. Clicking the left stack moves the card from the top of that stack to the top of the right stack, until the left stack is empty.

  1. A final table, containing a table for each of the suit stacks, with the rule that a card can only be placed on the stack if its rank is one higher than the top of the stack and it’s of the same suit, or the stack is empty and the card is an Ace.

Steps 1 through 4, are very inspirational, Nick.

Thank you! :slight_smile:

This will keep me quiet for a while.

PEACE

Nick,

Your assistance has proved very absolutely valuable to me.

I had one question, that I seem to be a bit confused about.

A display group is merely a table, if I am not misunderstanding; also, when assigning an image to the card.spriteInstance,

WHICH I NAMED, card.faceCard, I am assuming I use newSprite() for that image?

And for the back of the card, I can use card.backCard = newImageRect()

The confusion arose in my brain, when I tried applying a newSprite() to both card.spriteInstance, and to the card.backCard.

I just felt as though I was stepping on toes having TWO SPRITE INSTANCES for one card.

It hit me that I could probably use newImage(), newImageRect, or newSprite() for both.

As, newSprite() mainly has the ability to animate graphics.

I am confusing myself aren’t I?

Also, am I completely on the wrong path for attempting to OOP a card game?

I would like to use an OOP mindset, for learning purposes, as I have READ a lot about it.

I am sure a card game could be be done either way.

Is it ridiculous to use an OOP approach?

Please say, NO!

Thanks for your help, you really gave my creativity a bust!

:slight_smile:

Chris