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 | 32 | | |||
33 | function start(items_) { | 33 | function start(items_) { | ||
34 | items = items_ | 34 | items = items_ | ||
35 | currentLevel = 0 | 35 | currentLevel = 0 | ||
36 | initLevel() | 36 | initLevel() | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | function stop() { | 39 | function stop() { | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | function initLevel() { | 42 | function initLevel() { | ||
43 | items.bar.level = currentLevel + 1 | 43 | items.bar.level = currentLevel + 1 | ||
44 | var filename = "resource/board/"+ "board" + currentLevel + ".qml" | | |||
45 | items.dataset.source = filename | | |||
46 | | ||||
47 | setUp() | 44 | setUp() | ||
48 | } | 45 | } | ||
49 | 46 | | |||
50 | function setUp() { | 47 | function setUp() { | ||
51 | var levelData = items.dataset.item | 48 | var levelData = items.levels | ||
52 | 49 | numberOfLevel = items.levels.length | |||
50 | var subLevelData = levelData[currentLevel][items.currentSubLevel]; | ||||
53 | // use board levels | 51 | // use board levels | ||
54 | if (currentLevel < 7) { | 52 | if (!subLevelData["randomisedInputData"]) { | ||
55 | var subLevelData = levelData.levels[items.currentSubLevel]; | | |||
56 | items.totalBoys = subLevelData.totalBoys | 53 | items.totalBoys = subLevelData.totalBoys | ||
57 | items.totalGirls = subLevelData.totalGirls | 54 | items.totalGirls = subLevelData.totalGirls | ||
58 | items.totalCandies = subLevelData.totalCandies | 55 | items.totalCandies = subLevelData.totalCandies | ||
59 | 56 | | |||
60 | items.instruction.text = subLevelData.instruction | 57 | items.instruction.text = subLevelData.instruction | ||
61 | items.nbSubLevel = levelData.levels.length | 58 | items.nbSubLevel = levelData[currentLevel].length | ||
62 | 59 | | |||
63 | items.background.currentCandies = items.totalGirls * subLevelData.placedInGirls + | 60 | items.background.currentCandies = items.totalGirls * subLevelData.placedInGirls + | ||
64 | items.totalBoys * subLevelData.placedInBoys | 61 | items.totalBoys * subLevelData.placedInBoys | ||
65 | 62 | | |||
66 | items.background.placedInGirls = subLevelData.placedInGirls | 63 | items.background.placedInGirls = subLevelData.placedInGirls | ||
67 | items.background.placedInBoys = subLevelData.placedInBoys | 64 | items.background.placedInBoys = subLevelData.placedInBoys | ||
68 | items.background.showCount = subLevelData.showCount | 65 | items.background.showCount = subLevelData.showCount | ||
69 | 66 | | |||
70 | items.background.rest = items.totalCandies - | 67 | items.background.rest = items.totalCandies - | ||
71 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | 68 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | ||
72 | items.basketWidget.element.opacity = (subLevelData.forceShowBasket === true || | 69 | items.basketWidget.element.opacity = (subLevelData.forceShowBasket === true || | ||
73 | items.background.rest !== 0) ? 1 : 0 | 70 | items.background.rest !== 0) ? 1 : 0 | ||
74 | items.background.wrongMove.visible = false | 71 | items.background.wrongMove.visible = false | ||
75 | } | 72 | } | ||
76 | else { | 73 | else { | ||
77 | // create random (guided) levels | 74 | // create random (guided) levels | ||
78 | // get a random number between 1 and max for boys, girls and candies | 75 | // get a random number between 1 and max for boys, girls and candies | ||
79 | var maxBoys = levelData.levels[0].maxBoys | 76 | var maxBoys = subLevelData.maxBoys | ||
80 | var maxGirls = levelData.levels[0].maxGirls | 77 | var maxGirls = subLevelData.maxGirls | ||
81 | var maxCandies = levelData.levels[0].maxCandies | 78 | var maxCandies = subLevelData.maxCandies | ||
82 | 79 | | |||
83 | items.totalBoys = Math.floor(Math.random() * maxBoys) + 1 | 80 | items.totalBoys = Math.floor(Math.random() * maxBoys) + 1 | ||
84 | items.totalGirls = Math.floor(Math.random() * maxGirls) + 1 | 81 | items.totalGirls = Math.floor(Math.random() * maxGirls) + 1 | ||
85 | var sum = items.totalBoys + items.totalGirls | 82 | var sum = items.totalBoys + items.totalGirls | ||
86 | // use sum * 4 as top margin (max 4 candies per rectangle) | 83 | // use sum * 4 as top margin (max 4 candies per rectangle) | ||
87 | items.totalCandies = Math.floor(Math.random() * (4 * sum - sum + 1)) + sum | 84 | items.totalCandies = Math.floor(Math.random() * (4 * sum - sum + 1)) + sum | ||
88 | 85 | items.nbSubLevel = levelData[currentLevel].length | |||
89 | // stay within the max margin | 86 | // stay within the max margin | ||
90 | if (items.totalCandies > maxCandies) | 87 | if (items.totalCandies > maxCandies) | ||
91 | items.totalCandies = maxCandies | 88 | items.totalCandies = maxCandies | ||
92 | 89 | | |||
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 | 90 | items.background.showCount = false | ||
106 | items.nbSubLevel = 5 | | |||
107 | 91 | | |||
108 | // depending on the levels configuration, add candies from start in a child rectangle | 92 | // depending on the levels configuration, add candies from start in a child rectangle | ||
109 | if (levelData.levels[0].alreadyPlaced == false) { | 93 | if (subLevelData.alreadyPlaced == false) { | ||
jjazeixUnsubmitted Not Done jjazeix: === | |||||
110 | items.background.placedInGirls = 0 | 94 | items.background.placedInGirls = 0 | ||
111 | items.background.placedInBoys = 0 | 95 | items.background.placedInBoys = 0 | ||
112 | items.background.currentCandies = 0 | 96 | items.background.currentCandies = 0 | ||
113 | } | 97 | } | ||
114 | else { | 98 | else { | ||
115 | items.background.currentCandies = items.totalCandies * 2 | 99 | items.background.currentCandies = items.totalCandies * 2 | ||
116 | // Place randomly between 0 and 3 candies for each child | 100 | // Place randomly between 0 and 3 candies for each child | ||
117 | while (items.background.currentCandies > items.totalCandies / 3) { | 101 | while (items.background.currentCandies > items.totalCandies / 3) { | ||
118 | items.background.placedInGirls = Math.floor(Math.random() * 3) | 102 | items.background.placedInGirls = Math.floor(Math.random() * 3) | ||
119 | items.background.placedInBoys = Math.floor(Math.random() * 3) | 103 | items.background.placedInBoys = Math.floor(Math.random() * 3) | ||
120 | items.background.currentCandies = items.totalGirls * items.background.placedInGirls | 104 | items.background.currentCandies = items.totalGirls * items.background.placedInGirls | ||
121 | + items.totalBoys * items.background.placedInBoys | 105 | + items.totalBoys * items.background.placedInBoys | ||
122 | } | 106 | } | ||
123 | } | 107 | } | ||
108 | //~ singular Place %n boy | ||||
109 | //~ plural Place %n boys | ||||
110 | 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); | ||||
111 | | ||||
112 | //~ singular and %n girl in the center. | ||||
113 | //~ plural and %n girls in the center. | ||||
114 | 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); | ||||
115 | | ||||
116 | //~ singular Then equally split %n candy between them. | ||||
117 | //~ plural Then equally split %n candies between them. | ||||
118 | 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… | |||||
119 | | ||||
124 | 120 | | |||
125 | items.background.rest = items.totalCandies - | 121 | items.background.rest = items.totalCandies - | ||
126 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | 122 | Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) | ||
127 | 123 | | |||
128 | items.basketWidget.element.opacity = 1 | 124 | items.basketWidget.element.opacity = 1 | ||
129 | 125 | | |||
130 | items.background.wrongMove.visible = false; | 126 | items.background.wrongMove.visible = false; | ||
131 | 127 | | |||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |