Changeset View
Changeset View
Standalone View
Standalone View
src/activities/clockgame/clockgame.js
Show All 32 Lines | |||||
33 | 33 | | |||
34 | function stop() {} | 34 | function stop() {} | ||
35 | 35 | | |||
36 | function initLevel() { | 36 | function initLevel() { | ||
37 | items.bar.level = currentLevel + 1 | 37 | items.bar.level = currentLevel + 1 | ||
38 | 38 | | |||
39 | items.numberOfTry = items.levels[currentLevel].numberOfSubLevels | 39 | items.numberOfTry = items.levels[currentLevel].numberOfSubLevels | ||
40 | items.currentH = Math.floor(Math.random() * 12) | 40 | items.currentH = Math.floor(Math.random() * 12) | ||
41 | items.targetH = Math.floor(Math.random() * 12) | 41 | items.targetH = Math.floor(Math.random() * 12) | ||
42 | | ||||
jjazeix: it would be easier to do :
```
items.targetH = Math.floor(Math.random() * 12)
if(!items.levels… | |||||
42 | items.minutesHandVisible = items.levels[currentLevel].displayMinutesHand | 43 | items.minutesHandVisible = items.levels[currentLevel].displayMinutesHand | ||
43 | if(!items.minutesHandVisible) { | 44 | if(!items.minutesHandVisible) { | ||
44 | items.currentM = 0 | 45 | items.currentM = 0 | ||
45 | items.targetM = 0 | 46 | items.targetM = 0 | ||
46 | } | 47 | } | ||
47 | else if(items.levels[currentLevel].fixedMinutes !== undefined) { | 48 | else if(items.levels[currentLevel].fixedMinutes !== undefined) { | ||
48 | items.currentM = Math.floor(Math.random() * 60) | 49 | items.currentM = Math.floor(Math.random() * 60) | ||
49 | items.targetM = items.levels[currentLevel].fixedMinutes | 50 | items.targetM = items.levels[currentLevel].fixedMinutes | ||
Show All 29 Lines | 79 | function nextTry() { | |||
79 | if (items.numberOfTry <= ++items.currentTry) { | 80 | if (items.numberOfTry <= ++items.currentTry) { | ||
80 | items.currentTry = 0 | 81 | items.currentTry = 0 | ||
81 | nextLevel() | 82 | nextLevel() | ||
82 | } else { | 83 | } else { | ||
83 | initLevel() | 84 | initLevel() | ||
84 | } | 85 | } | ||
85 | } | 86 | } | ||
86 | 87 | | |||
88 | function checkAnswer() { | ||||
89 | if (items.currentH === items.targetH | ||||
you don't need to duplicate all the function. if (((items.currentH === items.targetH) || (items.currentH === (items.targetH - 12))) && items.currentM === items.targetM && items.currentS === items.targetS) { items.bonus.good("gnu") } else { items.bonus.bad("gnu") } jjazeix: you don't need to duplicate all the function.
Something like:
```
if (((items.currentH ===… | |||||
90 | && items.currentM === items.targetM | ||||
91 | && items.currentS === items.targetS) { | ||||
92 | items.bonus.good("gnu") | ||||
93 | } | ||||
94 | else { | ||||
95 | items.bonus.bad("gnu") | ||||
96 | } | ||||
97 | } | ||||
98 | | ||||
87 | function nextLevel() { | 99 | function nextLevel() { | ||
88 | if (numberOfLevel <= ++currentLevel) { | 100 | if (numberOfLevel <= ++currentLevel) { | ||
89 | currentLevel = 0 | 101 | currentLevel = 0 | ||
90 | } | 102 | } | ||
91 | items.currentTry = 0 | 103 | items.currentTry = 0 | ||
92 | initLevel() | 104 | initLevel() | ||
93 | } | 105 | } | ||
94 | 106 | | |||
Show All 13 Lines |
it would be easier to do :