Solitaire game with Construct 2

Get help using Construct 2

Post » Fri Dec 14, 2012 7:10 pm

You'll definitely need arrays. Maths, well not sure about the maths behind it, but you can easily find tutorials / source code for solitaire games.

Yes arrays can be frightening at first, but surely after all these years they shouldn't be scaring you off so much? I do remember you from the CC days ;)

The only way to truly learn arrays is by trying stuff using them.

Simplest way I can think of to learn them is using a 1D array to store hiscores or names, since you'll need to implement sorting. If you can sort through an array, then you can easily shuffle a deck of cards stored in an array.

I'd say a solitaire game would be quite advanced. Don't you have to place them a certain way so that it's not impossible to win? Never attempted it as it never interested me, and I usually don't know the best way to go about things unless I try it.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Dec 14, 2012 7:28 pm

I am familiar with arrays for puzzle games and i can do the shuffling decks thing , It's that placement thing which gives me a headache.I suppose i could use some variables or booleans to sort the order of the cards in a way.Maybe i am just overworked , 21 hours straight doing fine art on a car for a local racing game can be quite exhausting.

at least i got 3 hours off sleep
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Fri Dec 14, 2012 7:42 pm

I've played some solitaire games in the past and sometimes I couldn't win, sometimes I could. Not sure if the placement was random or what, but it won't hurt to just use random placement and go from there. Once you get the placement in, it'll be easy to change it up using an algorithm which allows strategic placement. You just need to get the basic framework going.

As I said, when the mood takes me, I'll have a bash at something as it is something I've often thought about, but never attempted.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Dec 14, 2012 8:24 pm

It shouldn't be too difficult. I'd agree that you'd want to start with a random order. Other than that from what I'd know you'd have to make some simple array operations. The staggering of the cards will be interesting to figure out but it is certainly not impossible. Just a bit brain bending ;)
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Dec 14, 2012 10:03 pm

I can work it out without array I think, but it would be a real pain (tonnes of conditions)
I think a good start is to have a kind of conversion table.
[code]cardConversion.At(0,0) = "ace"
cardConversion.At(0,1) = "hearts"

cardConversion.At(1,0) = "ace"
cardConversion.At(1,1) = "diamonds"

...

cardConversion.At(52,0) = "king"
cardConversion.At(52,1) = "spades"[/code]


What would you use that for?
Well the idea is that you would have all the card images in 52 frames of a card sprite in exactly the same order.

And thanks to this cardConversion array you'll be able to know the rank of the suit of any given card through it's animation frame.
cardConversion.At(card.AnimationFrame,0) will give you the rank of the card
cardConversion.At(card.AnimationFrame,1) will give you the suit of the card

Now you can just lay down the starting position of the cards in the layout.
And you'll just have to find a way to randomize the animation frame of each card without duplication.
But it might become a pain to maintain the deck itself.
So maybe yeah, an array just for the shuffling of every cards,
Then you distribute the card in this shuffled array by changing the frame of the cards laid out, and deleting the value in the array each time (with the delete function so your array shrinks at the same time) and then you'll be left with your randomized starting cards plus a cool deck array to cycle in (:

Then it's just a matter of coding the rules of the game.
like if you drop a card on a given column, check that the rank or the last card of the column (highest Y position)is the current card's rank + 1 and that the suit is the other color (you can try another kind of conversion table to answer this question or work it out with just conditions)
Then valid the move or not.

Same kind of thing to move the card on the 4 suit slots on the top right.

So yeah you'll need array and some bits of good knowledges of C2, but no complex math (:

So yeah good luck

(An yeah, power bumping makes you look like a jerk, and also often makes people not willing to answer you... So be carefull)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 14, 2012 10:07 pm

There's also the Creating a memory match game that contains some answers to most your questions.

And indeed, power bumping is not a good way to go when requiring help.
"Threatening" of switching to a competitor isn't either.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Dec 14, 2012 10:16 pm

thank you for the help everyone and sorry for being such a jerk.I just get so angry at myself sometimes and that's when i usually turn into a complete jerk/idiot.I know i should not power bump so please forgive my moronic behaviour.Now to get some sleep .Maybe things will work better if i get some rest.
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Fri Dec 14, 2012 11:30 pm

[QUOTE=sqiddster] It shouldn't be too difficult. I'd agree that you'd want to start with a random order. Other than that from what I'd know you'd have to make some simple array operations. The staggering of the cards will be interesting to figure out but it is certainly not impossible. Just a bit brain bending ;)[/QUOTE]

@sqiddster how is possible to use drag an drop over the cards which are pinned to other cards?
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Fri Dec 14, 2012 11:47 pm

@DravenX
I actually made a solitarie game with Construct2 that I will TRY to finish when I release my current project.
The real answer is that Construct2 is not the best tool for card games.
Solitaire logis would be better handled with "real" code, writing array tables with c2 is a real pain.
I suggest to write a custom plugin if you are serious about this that will handle your particular situation, I know I was doing one and no I will never release it because each solitaire game requires its own logic.
Ideally you should "feed" all the card position to a class that will keep track of them and calculate the value and return true/false if the card you moving can be placed in a particular column.
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Dec 15, 2012 12:15 am

@0plus1 This may be true, but not everyone has the time to learn a 'real' programming language, and doing this brings up other issues that the beginner may not be equipped to deal with.

I agree that this will be on the more difficult side in C2, but it can nonetheless be done.

That being said, now that I realize some of the finer complexities, I might suggest starting with a simpler card game.

(Regarding possible jerkiness - don't worry, we all have our grumpy days ;) )
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: makkancs, Matthew de and 40 guests