skylight_animation

Web Storage - localStorage | game.js

Aug 19th, 2020
2,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var time = 60; //set default time
  2.  
  3. function game(){
  4.     loadScore();
  5.     $('#homepage').show();
  6.     $('#gameplay').hide();
  7.     $('#afterplay').hide();
  8. }
  9.  
  10. function play(){
  11.     $('#homepage').hide();
  12.     $('#afterplay').hide();
  13.     $('#gameplay').show();
  14.     timeCount();
  15. }
  16.  
  17. function scoreExecute(){
  18.     $('#gameplay').hide();
  19.     $('#afterplay').show();
  20.     var score = $('#score').text();
  21.     console.log(score);
  22.     $('#finalscore').text(score);
  23. }
  24.  
  25. function timeCount() {
  26.     timePlay = time;
  27.     var counter=setInterval(timer, 1000);
  28.  
  29.     function timer(){
  30.         timePlay = timePlay-1;
  31.    
  32.         if (timePlay == 0){
  33.             clearInterval(counter);
  34.             console.log('Finish');
  35.             $('#timer').text(timePlay);
  36.             scoreExecute();
  37.  
  38.             timePlay = time;
  39.             return;
  40.         }else {
  41.             $('#timer').text(timePlay);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment