Changeset View
Changeset View
Standalone View
Standalone View
src/activities/share/share.js
Show All 14 Lines | |||||
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | 16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | .pragma library | 19 | .pragma library | ||
20 | .import QtQuick 2.6 as Quick | 20 | .import QtQuick 2.6 as Quick | ||
21 | 21 | | |||
22 | var currentLevel = 0 | 22 | var currentLevel = 0 | ||
23 | var numberOfLevel = 10 | 23 | var numberOfLevel | ||
24 | var items | 24 | var items | ||
25 | 25 | | |||
26 | var savedTotalBoys | 26 | var savedTotalBoys | ||
27 | var savedTotalGirls | 27 | var savedTotalGirls | ||
28 | var savedTotalCandies | 28 | var savedTotalCandies | ||
29 | var savedPlacedInGirls | 29 | var savedPlacedInGirls | ||
30 | var savedPlacedInBoys | 30 | var savedPlacedInBoys | ||
31 | var savedCurrentCandies | 31 | var savedCurrentCandies | ||
32 | var subLevelData | ||||
32 | 33 | | |||
33 | function start(items_) { | 34 | function start(items_) { | ||
34 | items = items_ | 35 | items = items_ | ||
35 | currentLevel = 0 | 36 | currentLevel = 0 | ||
36 | initLevel() | 37 | initLevel() | ||
37 | } | 38 | } | ||
38 | 39 | | |||
39 | function stop() { | 40 | function stop() { | ||
40 | } | 41 | } | ||
41 | 42 | | |||
42 | function initLevel() { | 43 | function initLevel() { | ||
43 | items.bar.level = currentLevel + 1 | 44 | items.bar.level = currentLevel + 1 | ||
44 | var filename = "resource/board/"+ "board" + currentLevel + ".qml" | | |||
45 | items.dataset.source = filename | | |||
46 | | ||||
47 | setUp() | 45 | setUp() | ||
48 | } | 46 | } | ||
49 | 47 | | |||
50 | function setUp() { | 48 | function setUp() { | ||
51 | var levelData = items.dataset.item | 49 | var levelData = items.levels | ||
52 | 50 | numberOfLevel = items.levels.length | |||
51 | subLevelData = levelData[currentLevel][items.currentSubLevel]; | ||||
53 | // use board levels | 52 | // use board levels | ||
54 | if (currentLevel < 7) { | 53 | if (!subLevelData["randomisedInputData"]) { | ||
55 | var subLevelData = levelData.levels[items.currentSubLevel]; | | |||
56 | items.totalBoys = subLevelData.totalBoys | 54 | items.totalBoys = subLevelData.totalBoys | ||
57 | items.totalGirls = subLevelData.totalGirls | 55 | items.totalGirls = subLevelData.totalGirls | ||
58 | items.totalCandies = subLevelData.totalCandies | 56 | items.totalCandies = subLevelData.totalCandies | ||
59 | 57 | | |||
60 | items.instruction.text = subLevelData.instruction | 58 | items.instruction.text = subLevelData.instruction | ||
61 | items.nbSubLevel = levelData.levels.length | 59 | items.nbSubLevel = levelData[currentLevel].length | ||
62 | 60 | | |||
63 | items.background.currentCandies = items.totalGirls * subLevelData.placedInGirls + | 61 | items.background.currentCandies = items.totalGirls * subLevelData.placedInGirls + | ||
64 | items.totalBoys * subLevelData.placedInBoys | 62 | items.totalBoys * subLevelData.placedInBoys | ||
65 | 63 | | |||
66 | items.background.placedInGirls = subLevelData.placedInGirls | 64 | items.background.placedInGirls = subLevelData.placedInGirls | ||
67 | items.background.placedInBoys = subLevelData.placedInBoys | 65 | items.background.placedInBoys = subLevelData.placedInBoys | ||
68 | items.background.showCount = subLevelData.showCount | 66 | items.background.showCount = subLevelData.showCount | ||
69 | 67 | | |||
70 | items.background.rest = items.totalCandies - | 68 | items.background.rest = items.totalCandies - | ||
71 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | 69 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | ||
72 | items.basketWidget.element.opacity = (subLevelData.forceShowBasket === true || | 70 | items.basketWidget.element.opacity = (subLevelData.forceShowBasket === true || | ||
73 | items.background.rest !== 0) ? 1 : 0 | 71 | items.background.rest !== 0) ? 1 : 0 | ||
74 | items.background.wrongMove.visible = false | 72 | items.background.wrongMove.visible = false | ||
75 | } | 73 | } | ||
76 | else { | 74 | else { | ||
77 | // create random (guided) levels | 75 | // create random (guided) levels | ||
78 | // get a random number between 1 and max for boys, girls and candies | 76 | // get a random number between 1 and max for boys, girls and candies | ||
79 | var maxBoys = levelData.levels[0].maxBoys | 77 | var maxBoys = subLevelData.maxBoys | ||
80 | var maxGirls = levelData.levels[0].maxGirls | 78 | var maxGirls = subLevelData.maxGirls | ||
81 | var maxCandies = levelData.levels[0].maxCandies | 79 | var maxCandies = subLevelData.maxCandies | ||
82 | 80 | | |||
83 | items.totalBoys = Math.floor(Math.random() * maxBoys) + 1 | 81 | items.totalBoys = Math.floor(Math.random() * maxBoys) + 1 | ||
84 | items.totalGirls = Math.floor(Math.random() * maxGirls) + 1 | 82 | items.totalGirls = Math.floor(Math.random() * maxGirls) + 1 | ||
85 | var sum = items.totalBoys + items.totalGirls | 83 | var sum = items.totalBoys + items.totalGirls | ||
86 | // use sum * 4 as top margin (max 4 candies per rectangle) | 84 | // use sum * 4 as top margin (max 4 candies per rectangle) | ||
87 | items.totalCandies = Math.floor(Math.random() * (4 * sum - sum + 1)) + sum | 85 | items.totalCandies = Math.floor(Math.random() * (4 * sum - sum + 1)) + sum | ||
88 | 86 | items.nbSubLevel = levelData[currentLevel].length | |||
89 | // stay within the max margin | 87 | // stay within the max margin | ||
90 | if (items.totalCandies > maxCandies) | 88 | if (items.totalCandies > maxCandies) | ||
91 | items.totalCandies = maxCandies | 89 | items.totalCandies = maxCandies | ||
92 | 90 | | |||
93 | //~ singular Place %n boy | | |||
94 | //~ plural Place %n boys | | |||
95 | items.instruction.text = qsTr("Place %n boy(s) ", "First part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalBoys); | | |||
96 | | ||||
97 | //~ singular and %n girl in the center. | | |||
98 | //~ plural and %n girls in the center. | | |||
99 | items.instruction.text += qsTr("and %n girl(s) in the center. ", "Second part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalGirls); | | |||
100 | | ||||
101 | //~ singular Then equally split %n candy between them. | | |||
102 | //~ plural Then equally split %n candies between them. | | |||
103 | items.instruction.text += qsTr("Then equally split %n pieces of candy between them.", "Third part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalCandies); | | |||
104 | | ||||
105 | items.background.showCount = false | 91 | items.background.showCount = false | ||
106 | items.nbSubLevel = 5 | | |||
107 | 92 | | |||
108 | // depending on the levels configuration, add candies from start in a child rectangle | 93 | // depending on the levels configuration, add candies from start in a child rectangle | ||
109 | if (levelData.levels[0].alreadyPlaced == false) { | 94 | if (subLevelData.alreadyPlaced == false) { | ||
jjazeixUnsubmitted Not Done jjazeix: === | |||||
110 | items.background.placedInGirls = 0 | 95 | items.background.placedInGirls = 0 | ||
111 | items.background.placedInBoys = 0 | 96 | items.background.placedInBoys = 0 | ||
112 | items.background.currentCandies = 0 | 97 | items.background.currentCandies = 0 | ||
113 | } | 98 | } | ||
114 | else { | 99 | else { | ||
115 | items.background.currentCandies = items.totalCandies * 2 | 100 | items.background.currentCandies = items.totalCandies * 2 | ||
116 | // Place randomly between 0 and 3 candies for each child | 101 | // Place randomly between 0 and 3 candies for each child | ||
117 | while (items.background.currentCandies > items.totalCandies / 3) { | 102 | while (items.background.currentCandies > items.totalCandies / 3) { | ||
118 | items.background.placedInGirls = Math.floor(Math.random() * 3) | 103 | items.background.placedInGirls = Math.floor(Math.random() * 3) | ||
119 | items.background.placedInBoys = Math.floor(Math.random() * 3) | 104 | items.background.placedInBoys = Math.floor(Math.random() * 3) | ||
120 | items.background.currentCandies = items.totalGirls * items.background.placedInGirls | 105 | items.background.currentCandies = items.totalGirls * items.background.placedInGirls | ||
121 | + items.totalBoys * items.background.placedInBoys | 106 | + items.totalBoys * items.background.placedInBoys | ||
122 | } | 107 | } | ||
123 | } | 108 | } | ||
109 | //~ singular Place %n boy | ||||
110 | //~ plural Place %n boys | ||||
111 | items.instruction.text = qsTr("Place %n boy(s) ", "First part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalBoys); | ||||
112 | | ||||
113 | //~ singular and %n girl in the center. | ||||
114 | //~ plural and %n girls in the center. | ||||
115 | items.instruction.text += qsTr("and %n girl(s) in the center. ", "Second part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalGirls); | ||||
116 | | ||||
117 | //~ singular Then equally split %n candy between them. | ||||
118 | //~ plural Then equally split %n candies between them. | ||||
119 | items.instruction.text += qsTr("Then equally split %n pieces of candy between them.", "Third part of Place %n boy(s) and %n girl(s) in the center. Then equally split %n pieces of candy between them.", items.totalCandies - items.background.currentCandies); | ||||
Previously for non randomised levels, Instructions show how many candies child needs to distribute while for random levels instructions shows total no. of candies without considering placed in candies. shubhammishra: Previously for non randomised levels, Instructions show how many candies child needs to… | |||||
120 | | ||||
124 | 121 | | |||
125 | items.background.rest = items.totalCandies - | 122 | items.background.rest = items.totalCandies - | ||
126 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | 123 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | ||
127 | 124 | | |||
128 | items.basketWidget.element.opacity = 1 | 125 | items.basketWidget.element.opacity = 1 | ||
129 | 126 | | |||
130 | items.background.wrongMove.visible = false; | 127 | items.background.wrongMove.visible = false; | ||
131 | 128 | | |||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 169 | function loadVariables() { | |||
174 | items.totalGirls = savedTotalGirls | 171 | items.totalGirls = savedTotalGirls | ||
175 | items.totalCandies = savedTotalCandies | 172 | items.totalCandies = savedTotalCandies | ||
176 | items.background.placedInGirls = savedPlacedInGirls | 173 | items.background.placedInGirls = savedPlacedInGirls | ||
177 | items.background.placedInBoys = savedPlacedInBoys | 174 | items.background.placedInBoys = savedPlacedInBoys | ||
178 | items.background.currentCandies = savedCurrentCandies | 175 | items.background.currentCandies = savedCurrentCandies | ||
179 | } | 176 | } | ||
180 | 177 | | |||
181 | function reloadRandom() { | 178 | function reloadRandom() { | ||
182 | if (currentLevel < 7) { | 179 | if (!subLevelData["randomisedInputData"]) { | ||
183 | initLevel() | 180 | initLevel() | ||
184 | } | 181 | } | ||
185 | else { | 182 | else { | ||
186 | loadVariables() | 183 | loadVariables() | ||
187 | resetBoard() | 184 | resetBoard() | ||
188 | 185 | | |||
189 | items.background.rest = items.totalCandies - | 186 | items.background.rest = items.totalCandies - | ||
190 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | 187 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | ||
Show All 30 Lines |