|
So here are the API details on the Card Shuffle API:
// Default URL
// 1 is the version # of the API
http://onflex.org/api/games/cards/shuffle/1/
// Decks Parameter - Shuffle 3 decks of 52 cards each
http://onflex.org/api/games/cards/shuffle/1/3
// Jokers Parameter - Shuffle 2 decks of 52 and add in 2 jokers per deck
http://onflex.org/api/games/cards/shuffle/1/2/2/
The logic shuffles an array of cards randomly between 5-20 times and each shuffle uses a new random seed value. This makes it easy to build the game logic client side without having to worry about shuffle randomness and allows for multi-user. More on the multi-user behavior in a later post.
In Flex 3 I wrote a simple API Test client that shows the decks visually. The card graphics are loaded from a Flash CS3 SWF9 file dynamically (more on the technique here) so that I can swap the card designs at runtime as a user preference. So here is the example with full source:
Card Shuffle API Tester in Flex 3
Card Shuffle API Tester in Flex 3 Source
I used a simple HTTPService tag like so:
resultFormat="text"
result="shuffleServiceResult( String( event.result ).split('|') )"
url="{'http://onflex.org/api/games/cards/shuffle/1/' + decks.value + '/' + jokers.value}"
/>
Note that the resultFormat is set to 'text' and when the result event is fired I used String.split to parse the result into an Array. I used the "|" as the delimiter. If you look at the raw text results you will see a number in the first array position, this is milliseconds from 1/1/1970 (Epoch) and makes it easy to transform into a Date object via the constructor like so:
// shift a value off the array, turn it into a number and pass it to the Date constructor
shuffleTime = new Date( Number( data.shift() ) );
Basically this simple API allows me to get shuffled decks of cards for my upcoming AIR game. I will be posting more about the making of as things progress.