123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- const squareTwo = {
-
- create: function () {
-
- this.result = false;
- this.delay = 0;
- this.endLevel = false;
- this.A = {
- blocks: [],
- auxBlocks: [],
- fractions: [],
- selected: 0,
- hasClicked: false,
- animate: false,
- warningText: undefined,
- label: undefined,
- };
- this.B = {
- blocks: [],
- auxBlocks: [],
- fractions: [],
- selected: 0,
- hasClicked: false,
- animate: false,
- warningText: undefined,
- label: undefined,
- };
-
-
- game.add.image(0, 0, 'bgimage');
-
- game.add.image(300, 100, 'cloud');
- game.add.image(660, 80, 'cloud');
- game.add.image(110, 85, 'cloud', 0.8);
-
- for (let i = 0; i < 9; i++) { game.add.image(i * 100, 501, 'floor'); }
-
-
- if (moodle) {
- navigationIcons.func_addIcons(
- false, false, false,
- true, false,
- false, false);
- } else {
- navigationIcons.func_addIcons(
- true, true, false,
- true, false,
- 'customMenu', false);
- }
-
- this.kidAnimation = game.add.sprite(100, 470, 'kid_standing', 5, 0.8);
- this.kidAnimation.anchor(0.5, 0.7);
-
- this.figureWidth = 400;
- const figureHeight = 50;
-
- let xA, xB, yA, yB;
- if (gameModeType != 'B') {
- xA = 230;
- yA = 90;
- xB = xA;
- yB = yA + 3 * figureHeight + 30;
- } else {
- xB = 230;
- yB = 90;
- xA = xB;
- yA = yB + 3 * figureHeight + 30;
- }
-
- const points = [2, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20];
-
- const randomIndex = game.math.randomInRange((gameDifficulty - 1) * 2 + 1, (gameDifficulty - 1) * 2 + 3);
-
- const totalBlocksA = points[randomIndex];
- const totalBlocksB = game.math.randomDivisor(totalBlocksA);
- if (debugMode) {
- console.log('----------');
- console.log('Difficulty ' + gameDifficulty + ', ini ' + ((gameDifficulty - 1) * 2 + 1) + ', end ' + ((gameDifficulty - 1) * 2 + 3));
- console.log('Rpoint ' + randomIndex + ', val ' + totalBlocksA);
- console.log('total blocks A ' + totalBlocksA + ', total blocks B ');
- }
-
- let blockWidth = this.figureWidth / totalBlocksA;
- let lineColor = colors.darkRed;
- let fillColor = colors.lightRed;
-
- for (let i = 0; i < totalBlocksA; i++) {
- const x = xA + i * blockWidth;
-
- const block = game.add.graphic.rect(x, yA, blockWidth, figureHeight, lineColor, 2, fillColor, 0.5);
- block.figure = 'A';
- block.index = i;
- block.finalX = xA;
- this.A.blocks.push(block);
-
- const alpha = (fractionLabel) ? 0.1 : 0;
- const yAux = yA + figureHeight + 10;
- const auxBlock = game.add.graphic.rect(x, yAux, blockWidth, figureHeight, lineColor, 1, fillColor, alpha);
- this.A.auxBlocks.push(auxBlock);
- }
-
- let xLabel = xA + this.figureWidth + 30;
- let yLabel = yA + figureHeight / 2;
- this.A.label = game.add.text(xLabel, yLabel, this.A.blocks.length, textStyles.h4_blue);
-
- yLabel = yA + figureHeight + 34;
- this.A.fractions[0] = game.add.text(xLabel, yLabel, '', textStyles.h4_blue);
- this.A.fractions[1] = game.add.text(xLabel, yLabel + 21, '', textStyles.h4_blue);
- this.A.fractions[2] = game.add.text(xLabel, yLabel, '___', textStyles.h4_blue);
- this.A.fractions[0].alpha = 0;
- this.A.fractions[1].alpha = 0;
- this.A.fractions[2].alpha = 0;
-
- blockWidth = this.figureWidth / totalBlocksB;
- lineColor = colors.darkGreen;
- fillColor = colors.lightGreen;
-
- for (let i = 0; i < totalBlocksB; i++) {
- const x = xB + i * blockWidth;
-
- const block = game.add.graphic.rect(x, yB, blockWidth, figureHeight, lineColor, 2, fillColor, 0.5);
- block.figure = 'B';
- block.index = i;
- block.finalX = xB;
- this.B.blocks.push(block);
-
- const alpha = (fractionLabel) ? 0.1 : 0;
- const yAux = yB + figureHeight + 10;
- const auxBlock = game.add.graphic.rect(x, yAux, blockWidth, figureHeight, lineColor, 1, fillColor, alpha);
- this.B.auxBlocks.push(auxBlock);
- }
-
- xLabel = xB + this.figureWidth + 30;
- yLabel = yB + figureHeight / 2;
- this.B.label = game.add.text(xLabel, yLabel, this.B.blocks.length, textStyles.h4_blue);
-
- yLabel = yB + figureHeight + 34;
- this.B.fractions[0] = game.add.text(xLabel, yLabel, '', textStyles.h4_blue);
- this.B.fractions[1] = game.add.text(xLabel, yLabel + 21, '', textStyles.h4_blue);
- this.B.fractions[2] = game.add.text(xLabel, yLabel, '___', textStyles.h4_blue);
- this.B.fractions[0].alpha = 0;
- this.B.fractions[1].alpha = 0;
- this.B.fractions[2].alpha = 0;
-
- this.A.warningText = game.add.text(defaultWidth / 2, defaultHeight / 2 - 225, '', textStyles.h4_brown);
- this.B.warningText = game.add.text(defaultWidth / 2, defaultHeight / 2 - 45, '', textStyles.h4_brown);
- game.timer.start();
- game.event.add('click', this.func_onInputDown);
- game.event.add('mousemove', this.func_onInputOver);
- },
-
- update: function () {
-
- if (self.A.animate || self.B.animate) {
- ['A', 'B'].forEach(cur => {
- if (self[cur].animate) {
-
- for (let i = 0; i < self[cur].selected; i++) {
- self[cur].blocks[i].y += 2;
- }
-
- if (self[cur].blocks[0].y >= self[cur].auxBlocks[0].y) {
- self[cur].fractions[0].name = self[cur].selected;
- self[cur].animate = false;
- }
- }
- });
- }
-
- if (self.A.hasClicked && self.B.hasClicked && !self.endLevel) {
- game.timer.stop();
- self.delay++;
-
- if (self.delay > 50) {
- self.result = (self.A.selected / self.A.blocks.length) == (self.B.selected / self.B.blocks.length);
-
- if (self.result) {
- if (audioStatus) game.audio.okSound.play();
- game.add.image(defaultWidth / 2, defaultHeight / 2, 'ok').anchor(0.5, 0.5);
- mapMove = true;
- completedLevels++;
- if (debugMode) console.log('completedLevels = ' + completedLevels);
-
- } else {
- if (audioStatus) game.audio.errorSound.play();
- game.add.image(defaultWidth / 2, defaultHeight / 2, 'error').anchor(0.5, 0.5);
- mapMove = false;
- }
- self.postScore();
- self.endLevel = true;
-
- self.delay = 0;
- }
- }
-
- if (self.endLevel) {
- self.delay++;
- if (self.delay >= 80) {
- game.state.start('map');
- }
- }
- game.render.all();
- },
-
-
- func_onInputDown: function (mouseEvent) {
- const x = mouseEvent.offsetX;
- const y = mouseEvent.offsetY;
-
- self.A.blocks.forEach(cur => {
- if (game.math.isOverIcon(x, y, cur)) self.func_clickSquare(cur);
- });
-
- self.B.blocks.forEach(cur => {
- if (game.math.isOverIcon(x, y, cur)) self.func_clickSquare(cur);
- });
-
- navigationIcons.func_onInputDown(x, y);
- game.render.all();
- },
-
- func_onInputOver: function (mouseEvent) {
- const x = mouseEvent.offsetX;
- const y = mouseEvent.offsetY;
- let flagA = false;
- let flagB = false;
-
- self.A.blocks.forEach(cur => {
- if (game.math.isOverIcon(x, y, cur)) {
- flagA = true;
- self.func_overSquare(cur);
- }
- });
- if (!flagA) self.func_outSquare('A');
-
- self.B.blocks.forEach(cur => {
- if (game.math.isOverIcon(x, y, cur)) {
- flagB = true;
- self.func_overSquare(cur);
- }
- });
- if (!flagB) self.func_outSquare('B');
- if (!flagA && !flagB) document.body.style.cursor = 'auto';
-
- navigationIcons.func_onInputOver(x, y);
- game.render.all();
- },
-
-
- func_overSquare: function (curBlock) {
- const curSet = curBlock.figure;
- if (!self[curSet].hasClicked) {
-
- if (curBlock.index == self[curSet].blocks.length - 1) {
- const otherSet = (curSet == 'A') ? 'B' : 'A';
- self[curSet].warningText.name = game.lang.s2_error_msg;
- self[otherSet].warningText.name = '';
- self.func_outSquare(curSet);
- } else {
- document.body.style.cursor = 'pointer';
- self.A.warningText.name = '';
- self.B.warningText.name = '';
-
- for (let i in self[curSet].blocks) {
- self[curSet].blocks[i].alpha = (i <= curBlock.index) ? 1 : 0.5;
- }
- self[curSet].fractions[0].name = curBlock.index + 1;
- self[curSet].fractions[1].name = self[curSet].blocks.length;
- const newX = curBlock.finalX + ((curBlock.index + 1) * (self.figureWidth / self[curSet].blocks.length)) + 25;
- self[curSet].fractions[0].x = newX;
- self[curSet].fractions[1].x = newX;
- self[curSet].fractions[2].x = newX;
- self[curSet].fractions[0].alpha = 1;
- }
- }
- },
-
- func_outSquare: function (curSet) {
- if (!self[curSet].hasClicked) {
- self[curSet].fractions[0].alpha = 0;
- self[curSet].fractions[1].alpha = 0;
- self[curSet].fractions[2].alpha = 0;
- self[curSet].blocks.forEach(cur => {
- cur.alpha = 0.5;
- });
- }
- },
-
- func_clickSquare: function (curBlock) {
- const curSet = curBlock.figure;
- if (!self[curSet].hasClicked && curBlock.index != self[curSet].blocks.length - 1) {
- document.body.style.cursor = 'auto';
-
- for (let i in self[curSet].blocks) {
- if (i > curBlock.index) self[curSet].auxBlocks[i].alpha = 0;
- }
-
- self[curSet].label.alpha = 0;
- if (audioStatus) game.audio.beepSound.play();
-
- self[curSet].selected = curBlock.index + 1;
-
- const newX = curBlock.finalX + (self[curSet].selected * (self.figureWidth / self[curSet].blocks.length)) + 25;
- self[curSet].fractions[0].x = newX;
- self[curSet].fractions[1].x = newX;
- self[curSet].fractions[2].x = newX;
- self[curSet].fractions[1].alpha = 1;
- self[curSet].fractions[2].alpha = 1;
- self[curSet].hasClicked = true;
- self[curSet].animate = true;
- }
- game.render.all();
- },
-
-
- postScore: function () {
-
- const data = '&line_game=' + gameShape
- + '&line_mode=' + gameModeType
- + '&line_oper=Equal'
- + '&line_leve=' + gameDifficulty
- + '&line_posi=' + mapPosition
- + '&line_resu=' + self.result
- + '&line_time=' + game.timer.elapsed
- + '&line_deta='
- + 'numBlocksA: ' + self.A.blocks.length
- + ', valueA: ' + self.A.selected
- + ', numBlocksB: ' + self.B.blocks.length
- + ', valueB: ' + self.B.selected;
-
- if (moodle) sendToDB(data, self.result, game.timer.elapsed);
- else sendToDB(data);
- }
- };
|