123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- function getParameterByName(name) {
- var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
- return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
- }
- function getAnswer() {
- let str = '';
-
- if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
- str +=
- 'gameName:' +
- gameName +
- '\ngameShape:' +
- gameShape +
- '\ngameMode:' +
- gameMode +
- '\ngameOperation:' +
- gameOperation +
- '\ngameDifficulty:' +
- gameDifficulty +
- '\ngameId:' +
- gameId +
- '\nshowFractions:' +
- showFractions +
- '\nresults:';
- for (let i = 0; i < moodleVar.hits.length; i++) {
- str +=
- '{level=' +
- (i + 1) +
- ',hits=' +
- moodleVar.hits[i] +
- ',errors=' +
- moodleVar.errors[i] +
- ',timeElapsed=' +
- moodleVar.time[i] +
- '}';
- }
- } else {
-
- if (!gameName) {
- alert(game.lang.error_must_select_game);
- return x;
- }
- moodleVar.hits = [0, 0, 0, 0];
- moodleVar.errors = [0, 0, 0, 0];
- moodleVar.time = [0, 0, 0, 0];
- str +=
- 'gameName:' +
- gameName +
- '\ngameShape:' +
- gameShape +
- '\ngameMode:' +
- gameMode +
- '\ngameOperation:' +
- gameOperation +
- '\ngameDifficulty:' +
- gameDifficulty +
- '\ngameId:' +
- gameId +
- '\nshowFractions:' +
- showFractions;
- }
- return str;
- }
- function getEvaluation() {
-
- if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
- let i;
- for (i = 0; i < moodleVar.hits.length && moodleVar.hits[i] == 1; i++);
- const grade = i / 4;
- return grade;
- }
- }
- const iLMparameters = {
-
- iLM_PARAM_Assignment: getParameterByName('iLM_PARAM_Assignment'),
-
- iLM_PARAM_SendAnswer: getParameterByName('iLM_PARAM_SendAnswer'),
-
- iLM_PARAM_Authoring: getParameterByName('iLM_PARAM_Authoring'),
- iLM_PARAM_ServerToGetAnswerURL: getParameterByName(
- 'iLM_PARAM_ServerToGetAnswerURL'
- ),
-
- lang: getParameterByName('lang'),
- };
- const getiLMContent = function () {
- const url = iLMparameters.iLM_PARAM_Assignment;
- if (url == null) {
- console.error(
- 'Game error: iLMparameters.iLM_PARAM_Assignment empty (File with extension .frc not found).'
- );
- } else {
- const init = { method: 'GET' };
- fetch(url, init)
- .then((response) => {
- if (response.ok) {
- if (isDebugMode) console.log('Processing...');
- response.text().then((text) => {
- breakString(text);
- });
- } else {
- console.error('Game error: Network response was not ok.');
- }
- })
- .catch((error) => {
- console.error(
- 'Game error: problem with fetch operation - ' + error.message + '.'
- );
- });
- }
- };
- const breakString = function (text) {
- let gameInfo = {},
- results;
- const lines = text.split('\n');
- lines.forEach((cur) => {
- try {
- let line = cur.split(':');
- if (line[0] != 'results') {
- const key = line[0].replace(/^\s+|\s+$/g, '');
- const value = line[1].replace(/^\s+|\s+$/g, '');
- gameInfo[key] = value;
- } else {
- results = line[1].replace(/^\s+|\s+$/g, '');
- }
- } catch (Error) {
- console.error('Game error: sintax error. ' + Error);
- }
- });
- if (results) {
- let i = 1;
- const curLevel = results.split('}');
- results = { l1: {}, l2: {}, l3: {}, l4: {} };
- curLevel.forEach((cur) => {
- cur = cur.slice(1);
- cur = cur.split(',');
- cur.forEach((cur) => {
- try {
- if (cur.length != 0) {
- let line = cur.split('=');
- const key = line[0].replace(/^\s+|\s+$/g, '');
- const value = line[1].replace(/^\s+|\s+$/g, '');
- results['l' + i][key] = parseInt(value);
- }
- } catch (Error) {
- console.error('Game error: sintax error. ' + Error);
- }
- });
- i++;
- });
- }
- updateGlobalVariables(gameInfo, results);
- };
- const updateGlobalVariables = function (infoGame, infoResults) {
-
- gameName = infoGame['gameName'];
- if (infoGame['gameId']) {
- gameId = infoGame['gameId'];
- } else {
- switch (gameName) {
- case 'squareOne':
- gameId = 0;
- break;
- case 'circleOne':
- gameId = 1;
- break;
- case 'squareTwo':
- gameId = 2;
- break;
- default:
- gameId = 0;
- }
- }
- gameShape = infoGame['gameShape'];
- gameMode = infoGame['gameMode'];
- gameOperation = infoGame['gameOperation'];
- gameDifficulty = parseInt(infoGame['gameDifficulty']);
- showFractions = infoGame['showFractions'];
-
- curMapPosition = 0;
- canGoToNextMapPosition = true;
- completedLevels = 0;
-
- if (infoResults) {
-
- for (let i = 0; i < moodleVar.hits.length; i++) {
- moodleVar.hits[i] = infoResults['l' + (i + 1)].hits;
- moodleVar.errors[i] = infoResults['l' + (i + 1)].errors;
- moodleVar.time[i] = infoResults['l' + (i + 1)].timeElapsed;
- }
- game.state.start('studentReport');
- } else {
-
- game.state.start('customMenu');
- }
- };
|