The project we're going to build in this tutorial is simple enough, but it shows how permutation tables can work nicely. You'll need to add eight objects to your project (although one of them is for decorative purposes only and is therefore optional.)
- AdvancedRandom – we need this plugin to actually create the permutation table
- AJAX – in order to show the permutation table is working correctly, we need to load an array containing the names of the cards. AJAX is used for this.
- Array – we hold the names of the cards in an array so we can call them later to make sure the current card number matches the one on display.
- CardPile – this is an optional sprite of the card back. All it does is make it look a little bit like there's a pile of cards underneath our face-up card.
- FaceUpCard – this sprite holds all of the cards as animation frames and is used to show the current card in the permutation table. It uses the Tween behavior to animate swapping the current card.
- Mouse – the project is controlled with the mouse, could be interchanged with the Touch plugin.
- NextCard – clicking this sprite calls the next card in the permutation table.
- Text – this is used to show what the current card being displayed should be (it should match FaceUpCard's animation frame) and how many cards are left in the deck.
Because the project is very small and pretty simple, I've set both the viewport size and the layout size 640x640 just to reduce excess space, but again, totally optional. The FaceUpCard is stacked on top of the CardPile sprite in the top half of the viewport with the NextCard button underneath. The Text object is placed on the left-hand side as an information display.
The final bits to add before the events are a pair of global variables and a project file. The two variables are CardNumber, which is a global number with an initial value of 0 and FirstCard which is a global Boolean, initially set to True. The project file is an array with the names of each card in a standard 52 card deck in the Y=0 row.