State Machines
The use of state machines is thanks to Recursoft and their Logic Driver Pro plugin. This is not the only way to create a 'state machine' but it is the one I use. It is amazing and I've barely scratched the surface of its functionality.
Pick Cards State Machine
This State Machine is initiated at the start of the 'Pick Cards' level and has two states: pick cards and its final state.
Pick Cards State: Pick Cards
It starts by shuffling the player's deck. This additional shuffle is good for when the player chooses to play again from the quit menu.
On State Update waits for the 'selection' array to reach a length of three. When it does, it saves the player's choices and sets the 'Cards Picked' boolean to true, which allows entry into the final state.
Pick Cards State: Save Game and Load Battle Board
The final state in Pick Cards State Machine calls the 'Save Game Event' and the 'Go to Battle Board' from the LDA.
AI Attack State Machine
This is the most complex state machine in the game. If you look at the image above, the state machine can be broken into five columns: AI starts an attack, checks its card slots, chooses one of its card to attack with, chooses one of the player's cards to attack, and checks if it won the battle.
Winner State Machine
The Winner State Machine sets the battle in motion and switches turns between the player and the AI. Its last few states declare the outcome of the game.
Winner State Machine State: Player's Turn
The Player and the AI turn states are very similar. First it checks for a tie or a winner, then enables or disables the mouse depending on whose turn it is, and starts the Player or AI attack events. The AI and Player turn states go back and forth until there is tie game or a winner.
Winner State Machine State: AI Wins
Both the AI Wins and the Player Wins states do something similar. The mouse gets disabled, the camera is moved to its final destination and the 'Fade in End Game' event is fired off. If the player wins, an additional 'Player Wins' event is launched.
Winner State Machine State: Quit
If the player wins, there is an additional 'Quit' state which dissolves the on screen cards before re-enabling the mouse and firing off the 'Fade in End Game' event.