123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- 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 += 'gameTypeString:' + gameTypeString
- + '\ngameShape:' + gameShape
- + '\ngameMode:' + gameMode
- + '\ngameOperation:' + gameOperation
- + '\ngameDifficulty:' + gameDifficulty
- + '\nfractionLabel:' + fractionLabel
- + '\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 (!gameType) {
- 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 += 'gameTypeString:' + gameTypeString
- + '\ngameShape:' + gameShape
- + '\ngameMode:' + gameMode
- + '\ngameOperation:' + gameOperation
- + '\ngameDifficulty:' + gameDifficulty
- + '\nfractionLabel:' + fractionLabel;
- }
- 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;
- parent.getEvaluationCallback(grade);
- return grade;
- }
- };
- const iLMparameters = {
-
- iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
-
- iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
-
- lang: getParameterByName("lang"),
- iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL"),
- iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL")
- };
- 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 (debugMode) 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.'); }
- });
- 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.'); }
- });
- i++;
- });
- }
- updateGlobalVariables(gameInfo, results);
- };
- const updateGlobalVariables = function (info, infoResults) {
-
- gameTypeString = info['gameTypeString'];
- gameShape = info['gameShape'];
- gameMode = info['gameMode'];
- gameOperation = info['gameOperation'];
- gameDifficulty = parseInt(info['gameDifficulty']);
- fractionLabel = info['fractionLabel'];
-
- mapPosition = 0;
- mapMove = 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');
- }
- };
- const moodleVar = {
- hits: [0, 0, 0, 0],
- errors: [0, 0, 0, 0],
- time: [0, 0, 0, 0]
- };
|