|
@@ -1,9 +1,8 @@
|
|
|
|
|
|
* LInE - Free Education, Private Data
|
|
|
+ *
|
|
|
* iFractions GAME STATE
|
|
|
*
|
|
|
- * LEVELS - SQUARE I & II: tractor level
|
|
|
- *
|
|
|
* Name of game state : squareOne
|
|
|
* Shape : square
|
|
|
* Character : tractor
|
|
@@ -11,16 +10,16 @@
|
|
|
* Concept : Player associates 'blocks carried by the tractor' and 'floor spaces to be filled by them'
|
|
|
* Represent fractions as : blocks
|
|
|
*
|
|
|
- * # of different difficulties for each level : 3
|
|
|
+ * # of different difficulties : 3
|
|
|
*
|
|
|
- * Levels can be : 'A' or 'B' (in variable 'levelType')
|
|
|
+ * Game modes can be : 'A' or 'B' (in variable 'gameModeType')
|
|
|
*
|
|
|
* A : Player can select # of 'floor blocks' (hole in the ground)
|
|
|
* Selects size of hole to be made in the ground (to fill with the blocks in front of the truck)
|
|
|
* B : Player can select # of 'stacked blocks' (in front of the truck)
|
|
|
* Selects number of blocks in front of the truck (to fill the hole on the ground)
|
|
|
*
|
|
|
- * Sublevels can be : 'Plus' or 'Minus' (in variable 'sublevelType')
|
|
|
+ * Operations can be : 'Plus' or 'Minus' (in variable 'gameOperationType')
|
|
|
*
|
|
|
* Plus : addition of fractions
|
|
|
* Represented by : tractor going to the right (floor positions 0..8
|
|
@@ -45,14 +44,14 @@ const squareOne = {
|
|
|
|
|
|
this.divisorsList = '';
|
|
|
|
|
|
- this.DIREC_LEVEL = (sublevelType == 'Minus') ? -1 : 1;
|
|
|
+ this.DIREC_LEVEL = (gameOperationType == 'Minus') ? -1 : 1;
|
|
|
this.animationSpeed = 2 * this.DIREC_LEVEL;
|
|
|
|
|
|
|
|
|
this.defaultBlockWidth = 80;
|
|
|
this.defaultBlockHeight = 40;
|
|
|
|
|
|
- this.startX = (sublevelType == 'Minus') ? 730 : 170;
|
|
|
+ this.startX = (gameOperationType == 'Minus') ? 730 : 170;
|
|
|
|
|
|
|
|
|
|
|
@@ -77,7 +76,7 @@ const squareOne = {
|
|
|
|
|
|
this.tractor = game.add.sprite(this.startX, 445, 'tractor', 0, 0.8);
|
|
|
|
|
|
- if (sublevelType == 'Plus') {
|
|
|
+ if (gameOperationType == 'Plus') {
|
|
|
this.tractor.anchor(1, 0.5);
|
|
|
this.tractor.animation = ['move', [0, 1, 2, 3, 4], 4];
|
|
|
} else {
|
|
@@ -91,26 +90,26 @@ const squareOne = {
|
|
|
blocks: [],
|
|
|
labels: [],
|
|
|
|
|
|
- index: undefined,
|
|
|
+ index: undefined,
|
|
|
|
|
|
|
|
|
curIndex: 0,
|
|
|
curBlockEnd: undefined,
|
|
|
|
|
|
|
|
|
- correctIndex: undefined,
|
|
|
+ correctIndex: undefined,
|
|
|
};
|
|
|
|
|
|
|
|
|
this.floor = {
|
|
|
blocks: [],
|
|
|
- index: undefined,
|
|
|
+ index: undefined,
|
|
|
|
|
|
|
|
|
curIndex: -1,
|
|
|
|
|
|
|
|
|
- correctIndex: undefined,
|
|
|
+ correctIndex: undefined,
|
|
|
correctX: undefined,
|
|
|
correctXA: undefined,
|
|
|
correctXB: undefined,
|
|
@@ -124,7 +123,7 @@ const squareOne = {
|
|
|
|
|
|
|
|
|
|
|
|
- if (levelType == 'A') {
|
|
|
+ if (gameModeType == 'A') {
|
|
|
this.arrow = game.add.image(this.startX + this.defaultBlockWidth * this.DIREC_LEVEL, 480, 'arrow_down');
|
|
|
this.arrow.anchor(0.5, 0.5);
|
|
|
this.arrow.alpha = 0.5;
|
|
@@ -168,8 +167,8 @@ const squareOne = {
|
|
|
const restOfCurBlock = (self.defaultBlockWidth - stck.blocks[stck.curIndex].width) * self.DIREC_LEVEL;
|
|
|
|
|
|
|
|
|
- if ((sublevelType == 'Plus' && stck.blocks[0].x >= (stck.curBlockEnd + restOfCurBlock)) ||
|
|
|
- (sublevelType == 'Minus' && stck.blocks[0].x <= (stck.curBlockEnd + restOfCurBlock))) {
|
|
|
+ if ((gameOperationType == 'Plus' && stck.blocks[0].x >= (stck.curBlockEnd + restOfCurBlock)) ||
|
|
|
+ (gameOperationType == 'Minus' && stck.blocks[0].x <= (stck.curBlockEnd + restOfCurBlock))) {
|
|
|
|
|
|
let lowerBlock = true;
|
|
|
|
|
@@ -184,7 +183,7 @@ const squareOne = {
|
|
|
|
|
|
|
|
|
|
|
|
- if ((sublevelType == 'Plus' && curEnd > selectedEnd) || (sublevelType == 'Minus' && curEnd < selectedEnd)) {
|
|
|
+ if ((gameOperationType == 'Plus' && curEnd > selectedEnd) || (gameOperationType == 'Minus' && curEnd < selectedEnd)) {
|
|
|
lowerBlock = false;
|
|
|
}
|
|
|
} else {
|
|
@@ -198,7 +197,7 @@ const squareOne = {
|
|
|
|
|
|
|
|
|
for (let i = 0; i <= floor.index; i++) {
|
|
|
- if ((sublevelType == 'Plus' && floor.blocks[i].x < curEnd) || (sublevelType == 'Minus' && floor.blocks[i].x > curEnd)) {
|
|
|
+ if ((gameOperationType == 'Plus' && floor.blocks[i].x < curEnd) || (gameOperationType == 'Minus' && floor.blocks[i].x > curEnd)) {
|
|
|
floor.blocks[i].alpha = 0.2;
|
|
|
floor.curIndex = i;
|
|
|
}
|
|
@@ -225,7 +224,7 @@ const squareOne = {
|
|
|
|
|
|
game.animation.stop(self.tractor.animation[0]);
|
|
|
|
|
|
- if (levelType == 'A') {
|
|
|
+ if (gameModeType == 'A') {
|
|
|
self.result = self.floor.index == self.floor.correctIndex;
|
|
|
} else {
|
|
|
self.result = self.stck.index == self.stck.correctIndex;
|
|
@@ -239,7 +238,7 @@ const squareOne = {
|
|
|
game.add.image(defaultWidth / 2, defaultHeight / 2, 'ok').anchor(0.5, 0.5);
|
|
|
if (audioStatus) game.audio.okSound.play();
|
|
|
|
|
|
- completedLevels++;
|
|
|
+ completedLevels++;
|
|
|
if (debugMode) console.log('completedLevels = ' + completedLevels);
|
|
|
} else {
|
|
|
|
|
@@ -287,7 +286,7 @@ const squareOne = {
|
|
|
const x = mouseEvent.offsetX;
|
|
|
const y = mouseEvent.offsetY;
|
|
|
|
|
|
- if (levelType == 'A') {
|
|
|
+ if (gameModeType == 'A') {
|
|
|
self.floor.blocks.forEach(cur => {
|
|
|
if (game.math.isOverIcon(x, y, cur)) self.func_clickSquare(cur);
|
|
|
});
|
|
@@ -313,7 +312,7 @@ const squareOne = {
|
|
|
let flagA = false;
|
|
|
let flagB = false;
|
|
|
|
|
|
- if (levelType == 'A') {
|
|
|
+ if (gameModeType == 'A') {
|
|
|
|
|
|
if (!self.hasClicked && !self.animateEnding) {
|
|
|
if (game.math.distanceToPointer(self.arrow.x, x, self.arrow.y, y) > 8) {
|
|
@@ -331,7 +330,7 @@ const squareOne = {
|
|
|
if (!flagA) self.func_outSquare('A');
|
|
|
}
|
|
|
|
|
|
- if (levelType == 'B') {
|
|
|
+ if (gameModeType == 'B') {
|
|
|
self.stck.blocks.forEach(cur => {
|
|
|
if (game.math.isOverIcon(x, y, cur)) {
|
|
|
flagB = true;
|
|
@@ -359,8 +358,8 @@ const squareOne = {
|
|
|
if (!self.hasClicked) {
|
|
|
document.body.style.cursor = 'pointer';
|
|
|
|
|
|
-
|
|
|
- if (levelType == 'A') {
|
|
|
+
|
|
|
+ if (gameModeType == 'A') {
|
|
|
for (let i in self.floor.blocks) {
|
|
|
self.floor.blocks[i].alpha = (i <= cur.index) ? 1 : 0.5;
|
|
|
}
|
|
@@ -368,7 +367,7 @@ const squareOne = {
|
|
|
|
|
|
self.floor.index = cur.index;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
for (let i in self.stck.blocks) {
|
|
|
self.stck.blocks[i].alpha = (i <= cur.index) ? 0.5 : 0.2;
|
|
@@ -387,14 +386,14 @@ const squareOne = {
|
|
|
if (!self.hasClicked) {
|
|
|
document.body.style.cursor = 'auto';
|
|
|
|
|
|
-
|
|
|
- if (levelType == 'A') {
|
|
|
+
|
|
|
+ if (gameModeType == 'A') {
|
|
|
for (let i in self.floor.blocks) {
|
|
|
self.floor.blocks[i].alpha = 0.5;
|
|
|
}
|
|
|
|
|
|
self.floor.index = -1;
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
for (let i in self.stck.blocks) {
|
|
|
self.stck.blocks[i].alpha = 0.5;
|
|
@@ -412,8 +411,8 @@ const squareOne = {
|
|
|
if (!self.hasClicked && !self.animateEnding) {
|
|
|
document.body.style.cursor = 'auto';
|
|
|
|
|
|
-
|
|
|
- if (levelType == 'A') {
|
|
|
+
|
|
|
+ if (gameModeType == 'A') {
|
|
|
|
|
|
self.arrow.alpha = 1;
|
|
|
|
|
@@ -425,7 +424,7 @@ const squareOne = {
|
|
|
|
|
|
|
|
|
self.stck.index = self.stck.blocks.length - 1;
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
for (let i in self.stck.blocks) {
|
|
|
|
|
@@ -468,7 +467,7 @@ const squareOne = {
|
|
|
*/
|
|
|
func_createStckBlocks: function () {
|
|
|
let hasBaseDifficulty = false;
|
|
|
- const max = (levelType == 'B') ? 10 : mapPosition + 4;
|
|
|
+ const max = (gameModeType == 'B') ? 10 : mapPosition + 4;
|
|
|
|
|
|
const total = game.math.randomInRange(mapPosition + 2, max);
|
|
|
|
|
@@ -485,7 +484,7 @@ const squareOne = {
|
|
|
self.floor.correctXA += curBlockWidth * self.DIREC_LEVEL;
|
|
|
|
|
|
|
|
|
- const lineColor = (sublevelType == 'Minus') ? colors.red : colors.darkBlue;
|
|
|
+ const lineColor = (gameOperationType == 'Minus') ? colors.red : colors.darkBlue;
|
|
|
const lineSize = 2;
|
|
|
const block = game.add.graphic.rect(
|
|
|
self.startX,
|
|
@@ -496,11 +495,11 @@ const squareOne = {
|
|
|
lineSize,
|
|
|
colors.white,
|
|
|
1);
|
|
|
- const anchor = (sublevelType == 'Minus') ? 1 : 0;
|
|
|
+ const anchor = (gameOperationType == 'Minus') ? 1 : 0;
|
|
|
block.anchor(anchor, 0);
|
|
|
|
|
|
|
|
|
- if (levelType == 'B') {
|
|
|
+ if (gameModeType == 'B') {
|
|
|
block.alpha = 0.5;
|
|
|
block.index = i;
|
|
|
}
|
|
@@ -533,9 +532,9 @@ const squareOne = {
|
|
|
|
|
|
|
|
|
if (!hasBaseDifficulty ||
|
|
|
- (sublevelType == 'Plus' && (self.floor.correctXA < (self.startX + self.defaultBlockWidth) ||
|
|
|
+ (gameOperationType == 'Plus' && (self.floor.correctXA < (self.startX + self.defaultBlockWidth) ||
|
|
|
self.floor.correctXA > (self.startX + 8 * self.defaultBlockWidth))) ||
|
|
|
- (sublevelType == 'Minus' && (self.floor.correctXA < (self.startX - (8 * self.defaultBlockWidth)) ||
|
|
|
+ (gameOperationType == 'Minus' && (self.floor.correctXA < (self.startX - (8 * self.defaultBlockWidth)) ||
|
|
|
self.floor.correctXA > (self.startX - self.defaultBlockWidth)))
|
|
|
) {
|
|
|
restart = true;
|
|
@@ -557,7 +556,7 @@ const squareOne = {
|
|
|
const blockWidth = self.defaultBlockWidth / divisor;
|
|
|
|
|
|
|
|
|
- if (levelType == 'B') {
|
|
|
+ if (gameModeType == 'B') {
|
|
|
self.stck.correctIndex = game.math.randomInRange(0, (self.stck.blocks.length - 1));
|
|
|
|
|
|
self.floor.correctXB = self.startX + self.defaultBlockWidth * self.DIREC_LEVEL;
|
|
@@ -573,15 +572,15 @@ const squareOne = {
|
|
|
|
|
|
const x = self.startX + (self.defaultBlockWidth + i * blockWidth) * self.DIREC_LEVEL;
|
|
|
|
|
|
- if (flag && levelType == 'A') {
|
|
|
- if ((sublevelType == 'Plus' && x >= self.floor.correctXA) || (sublevelType == 'Minus' && x <= self.floor.correctXA)) {
|
|
|
+ if (flag && gameModeType == 'A') {
|
|
|
+ if ((gameOperationType == 'Plus' && x >= self.floor.correctXA) || (gameOperationType == 'Minus' && x <= self.floor.correctXA)) {
|
|
|
self.floor.correctIndex = i - 1;
|
|
|
flag = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (levelType == 'B') {
|
|
|
- if ((sublevelType == 'Plus' && x >= self.floor.correctXB) || (sublevelType == 'Minus' && x <= self.floor.correctXB)) {
|
|
|
+ if (gameModeType == 'B') {
|
|
|
+ if ((gameOperationType == 'Plus' && x >= self.floor.correctXB) || (gameOperationType == 'Minus' && x <= self.floor.correctXB)) {
|
|
|
total = i;
|
|
|
break;
|
|
|
}
|
|
@@ -598,11 +597,11 @@ const squareOne = {
|
|
|
lineSize,
|
|
|
colors.blueBckgInsideLevel,
|
|
|
1);
|
|
|
- const anchor = (sublevelType == 'Minus') ? 1 : 0;
|
|
|
+ const anchor = (gameOperationType == 'Minus') ? 1 : 0;
|
|
|
block.anchor(anchor, 0);
|
|
|
|
|
|
|
|
|
- if (levelType == 'A') {
|
|
|
+ if (gameModeType == 'A') {
|
|
|
block.alpha = 0.5;
|
|
|
block.index = i;
|
|
|
}
|
|
@@ -611,8 +610,8 @@ const squareOne = {
|
|
|
self.floor.blocks.push(block);
|
|
|
}
|
|
|
|
|
|
- if (levelType == 'A') self.floor.correctX = self.floor.correctXA;
|
|
|
- else if (levelType == 'B') self.floor.correctX = self.floor.correctXB;
|
|
|
+ if (gameModeType == 'A') self.floor.correctX = self.floor.correctXA;
|
|
|
+ else if (gameModeType == 'B') self.floor.correctX = self.floor.correctXB;
|
|
|
|
|
|
|
|
|
for (let i = 1; i < 10; i++) {
|
|
@@ -626,12 +625,12 @@ const squareOne = {
|
|
|
*/
|
|
|
func_viewHelp: function () {
|
|
|
if (!self.hasClicked) {
|
|
|
-
|
|
|
- if (levelType == 'A') {
|
|
|
+
|
|
|
+ if (gameModeType == 'A') {
|
|
|
const aux = self.floor.blocks[0];
|
|
|
self.help.x = self.floor.correctX - aux.width / 2 * self.DIREC_LEVEL;
|
|
|
self.help.y = 501;
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
const aux = self.stck.blocks[self.stck.correctIndex];
|
|
|
self.help.x = aux.x + aux.width / 2 * self.DIREC_LEVEL;
|
|
@@ -655,8 +654,8 @@ const squareOne = {
|
|
|
postScore: function () {
|
|
|
|
|
|
const data = '&line_game=' + gameShape
|
|
|
- + '&line_mode=' + levelType
|
|
|
- + '&line_oper=' + sublevelType
|
|
|
+ + '&line_mode=' + gameModeType
|
|
|
+ + '&line_oper=' + gameOperationType
|
|
|
+ '&line_leve=' + gameDifficulty
|
|
|
+ '&line_posi=' + mapPosition
|
|
|
+ '&line_resu=' + self.result
|