demos/declarative/snake/content/snake.js
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    33         return;
    33         return;
    34 
    34 
    35     if (heartbeat.running) {
    35     if (heartbeat.running) {
    36         endGame();
    36         endGame();
    37         startNewGameTimer.running = true;
    37         startNewGameTimer.running = true;
    38         return;
    38         state = "";
    39     }
    39         return;
       
    40     }
       
    41 
       
    42     state = "starting";
    40 
    43 
    41     numRows = numRowsAvailable;
    44     numRows = numRowsAvailable;
    42     numColumns = numColumnsAvailable;
    45     numColumns = numColumnsAvailable;
    43     board = new Array(numRows * numColumns);
    46     board = new Array(numRows * numColumns);
    44     snake = new Array;
    47     snake = new Array;
    78     linksToGrow = 5;
    81     linksToGrow = 5;
    79     linksToDie = 0;
    82     linksToDie = 0;
    80     waitForCookie = 5;
    83     waitForCookie = 5;
    81     score = 0;
    84     score = 0;
    82     startHeartbeatTimer.running = true;
    85     startHeartbeatTimer.running = true;
    83     heartbeat.running = true;
       
    84 }
    86 }
    85 
    87 
    86 function endGame()
    88 function endGame()
    87 {
    89 {
    88     heartbeat.running = false;
    90     heartbeat.running = false;
    92         cookie.dying = true;
    94         cookie.dying = true;
    93         cookie = 0;
    95         cookie = 0;
    94     }
    96     }
    95     lastScore = score;
    97     lastScore = score;
    96     highScores.saveScore(lastScore);
    98     highScores.saveScore(lastScore);
       
    99     state = "";
    97 }
   100 }
    98 
   101 
    99 function move() {
   102 function move() {
   100 
   103 
   101     if (!head)
   104     if (!head)