Restarting the game for the next round of battle
We now come to the last task—resetting the cards for the next round of battle. At this stage, the battle animation runs once and then the game stalls there. In this task, we reset all the card states so that the player can select another card and trigger another round of battle until either side is dead.
Engage thrusters
Let's continue the battle with the following steps:
- Inside the
gameScene.restartGame
method, we add the following code to toggle theout
andflipped
state for all the cards:/* reset the transition state */ allCardElms.forEach(function(elm){ elm.classList.remove('in'); elm.classList.add('out'); }); allPlayerCardElms.forEach(function(elm){ elm.classList.remove('selected'); elm.classList.add('flipped'); });
- Remember that we have commented out the
restartGame
method calling in the previous task. Now, we can enable this method calling by removing the comments. The battle...