Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Inside the gameScene.restartGame method, we add the following code to toggle the out and flipped 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');
    });
  2. 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 round then repeats until the game ends:

    gameScene.restartGame...