Email conversation
From | Maurice de Regt |
To | Me |
Subject | solitaire automatic card flip question |
Date | 6 June 2010 15:06 |
Dear Wilton-Jones,
Thanks for the great solitaire script. I've read all the documentation, but
cannot figure at to let the cards auto flip when no cards lay on top of
them. I know there is a card event for this, but I have no clue how to use
this correctly. To be clear, it's not the card pile I want to autoflip, just
the cards in the game.
Call me lazy, but I hate it to click every card so that it flips over. On
card drop I want to flip cards that show their backs and have no cards on
top of them, instead of clicking them.
How to do this?
Hope you have the time to help me out with this request.
Kind regards,
Maurice
From | Me |
To | Maurice de Regt |
Subject | Re: solitaire automatic card flip question |
Date | 7 June 2010 17:31 |
Maurice,
> let the cards auto flip when no cards lay on top of them.
There are several moves that could lead to an empty card being face down on
top of a tableau. These all fire the onmovecard event, immediately *before*
the card moves.
So you need to:
1. Detect the onmovecard event.
2. Store the event.target.cardStack (eg. as 'fStack').
2. Wait for a very short timeout like 10ms (just to allow the move to
complete).
3. Make the event handler return true so the move is not cancelled.
4. After the timeout, check:
if( fStack.cardsInStack.length )
and then flip the top one:
fStack.cardsInStack[fStack.cardsInStack.length-1].showFace(true)
There's no need to check if the top one is face down.
That should end up something like this:
game1.onmovecard = function (e) {
var fStack = e.target.cardStack;
setTimeout(function () {
if( fStack.cardsInStack.length ) {
fStack.cardsInStack[fStack.cardsInStack.length-1].showFace(true);
}
},10);
return true;
};
I tested it and it does seem to work without producing errors. In theory you
could also check that the fStack is the right type to be a tableau (not the
waste pile or a foundation stack), but that's not needed, since in all cases
where the onmovecard event fires, the card below it is one that is allowed
to be face-up.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Maurice de Regt |
To | Me |
Subject | Re: solitaire automatic card flip question |
Date | 7 June 2010 17:42 |
Hi Wilton,
Thank you for the reply. I am not at home right now so I cant test
things atm, but reading your description, isnt it netter to use the
oncarddrop/release event (if it exists) rather then the oncardmove?
Cause how i see it now, people can sneakpeak the cards by moving a
card and hold it for a view seconds. Making the blinded cards turn?
Or did I misunderstood your explaination?
Kind regards,
Maurice
From | Me |
To | Maurice de Regt |
Subject | Re: solitaire automatic card flip question |
Date | 7 June 2010 18:08 |
Maurice,
> isnt it netter to use the
> oncarddrop/release event (if it exists) rather then the oncardmove?
No, there is no such event. The onmovecard event does what you want. It
fires when the card is *about to move* to a new stack. Not when the user is
still in the process of dragging it, but when they drop it onto a new pile
(or move it there by any other means, like double clicking, etc.).
Read up on the event details if you need further clarification.
Tarquin
From | Maurice de Regt |
To | Me |
Subject | Re: solitaire automatic card flip question |
Date | 7 June 2010 19:11 |
Hi,
Okay I will try this. Thank you for your time and explanation.
Kind regards,
Maurice