Changeset View
Changeset View
Standalone View
Standalone View
src/activities/clockgame/clockgame.js
Show All 15 Lines | |||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | 17 | * GNU General Public License for more details. | ||
18 | * | 18 | * | ||
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | 20 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | ||
21 | */ | 21 | */ | ||
22 | var currentLevel = 0 | 22 | var currentLevel = 0 | ||
23 | var numberOfLevel = 10 | 23 | var numberOfLevel = 10 | ||
24 | var minHours | ||||
25 | var maxHours | ||||
24 | var items | 26 | var items | ||
25 | var selectedArrow | 27 | var selectedArrow | ||
26 | 28 | | |||
27 | function start(items_) { | 29 | function start(items_) { | ||
28 | items = items_ | 30 | items = items_ | ||
29 | currentLevel = 0 | 31 | currentLevel = 0 | ||
30 | numberOfLevel = items.levels.length | 32 | numberOfLevel = items.levels.length | ||
31 | initLevel() | 33 | initLevel() | ||
32 | } | 34 | } | ||
33 | 35 | | |||
34 | function stop() {} | 36 | function stop() {} | ||
35 | 37 | | |||
36 | function initLevel() { | 38 | function initLevel() { | ||
37 | items.bar.level = currentLevel + 1 | 39 | items.bar.level = currentLevel + 1 | ||
38 | 40 | | |||
39 | items.numberOfTry = items.levels[currentLevel].numberOfSubLevels | 41 | items.numberOfTry = items.levels[currentLevel].numberOfSubLevels | ||
40 | items.currentH = Math.floor(Math.random() * 12) | 42 | items.currentH = Math.floor(Math.random() * 12) | ||
41 | items.targetH = Math.floor(Math.random() * 12) | 43 | if(!items.levels[currentLevel].twentyfourHoursFormat) { | ||
jjazeix: it would be easier to do :
```
items.targetH = Math.floor(Math.random() * 12)
if(!items.levels… | |||||
44 | minHours = 0 | ||||
45 | maxHours = 12 | ||||
46 | items.targetH = Math.floor(Math.random() * (+maxHours - +minHours)) + +minHours | ||||
47 | } | ||||
48 | else if(items.levels[currentLevel].twentyfourHoursFormat) { | ||||
49 | minHours = 13 | ||||
50 | maxHours = 24 | ||||
51 | items.targetH = Math.floor(Math.random() * (+maxHours - +minHours)) + +minHours | ||||
52 | } | ||||
42 | items.minutesHandVisible = items.levels[currentLevel].displayMinutesHand | 53 | items.minutesHandVisible = items.levels[currentLevel].displayMinutesHand | ||
43 | if(!items.minutesHandVisible) { | 54 | if(!items.minutesHandVisible) { | ||
44 | items.currentM = 0 | 55 | items.currentM = 0 | ||
45 | items.targetM = 0 | 56 | items.targetM = 0 | ||
46 | } | 57 | } | ||
47 | else if(items.levels[currentLevel].fixedMinutes !== undefined) { | 58 | else if(items.levels[currentLevel].fixedMinutes !== undefined) { | ||
48 | items.currentM = Math.floor(Math.random() * 60) | 59 | items.currentM = Math.floor(Math.random() * 60) | ||
49 | items.targetM = items.levels[currentLevel].fixedMinutes | 60 | items.targetM = items.levels[currentLevel].fixedMinutes | ||
Show All 29 Lines | 89 | function nextTry() { | |||
79 | if (items.numberOfTry <= ++items.currentTry) { | 90 | if (items.numberOfTry <= ++items.currentTry) { | ||
80 | items.currentTry = 0 | 91 | items.currentTry = 0 | ||
81 | nextLevel() | 92 | nextLevel() | ||
82 | } else { | 93 | } else { | ||
83 | initLevel() | 94 | initLevel() | ||
84 | } | 95 | } | ||
85 | } | 96 | } | ||
86 | 97 | | |||
98 | function checkAnswer() { | ||||
99 | if(items.targetH > 12) { | ||||
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 ===… | |||||
100 | if (items.currentH === (items.targetH - 12) | ||||
101 | && items.currentM === items.targetM | ||||
102 | && items.currentS === items.targetS) { | ||||
103 | items.bonus.good("gnu") | ||||
104 | } | ||||
105 | else { | ||||
106 | items.bonus.bad("gnu") | ||||
107 | } | ||||
108 | | ||||
109 | } | ||||
110 | else { | ||||
111 | if (items.currentH === items.targetH | ||||
112 | && items.currentM === items.targetM | ||||
113 | && items.currentS === items.targetS) { | ||||
114 | items.bonus.good("gnu") | ||||
115 | } | ||||
116 | else { | ||||
117 | items.bonus.bad("gnu") | ||||
118 | } | ||||
119 | } | ||||
120 | } | ||||
121 | | ||||
87 | function nextLevel() { | 122 | function nextLevel() { | ||
88 | if (numberOfLevel <= ++currentLevel) { | 123 | if (numberOfLevel <= ++currentLevel) { | ||
89 | currentLevel = 0 | 124 | currentLevel = 0 | ||
90 | } | 125 | } | ||
91 | items.currentTry = 0 | 126 | items.currentTry = 0 | ||
92 | initLevel() | 127 | initLevel() | ||
93 | } | 128 | } | ||
94 | 129 | | |||
Show All 13 Lines |
it would be easier to do :