diff --git a/activity_2/index.html b/activity_2/index.html new file mode 100644 index 0000000000000000000000000000000000000000..49c409e9542d0dc3c626c7713adcad0596257df6 --- /dev/null +++ b/activity_2/index.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + <head> + <title>Road to the Moon !</title> + <meta charset="utf-8" /> + <link rel="stylesheet" href="../res/style.css" /> + + <!-- Import des bibliothèques js nécessaires --> + <script src="../res/blockly/blockly_compressed.js"></script> + <script src="../res/blockly/blocks_compressed.js"></script> + <script src="../res/blockly/javascript_compressed.js"></script> + <script src="../res/blockly/msg/js/fr.js"></script> + <script src="../res/JS-Interpreter/acorn_interpreter.js"></script> + + </head> + + + <body> + <header> + <p>Road to the moon !</p> + </header> + <section class="mainSection"> + <!-- Création de la div portant blockly et d'un conteneur supérieur pour le responsive--> + <div id="blocklyArea"><div id="blocklyDiv" ></div></div> + <div id="toolsArea"> + <a onclick="runCode()" id="runButton">Lancer le programme !</a> + </div> + </section> + + + <footer> + <img src="../res/img/logos/insa.png"> + <img src="../res/img/logos/clubelek.png"> + <img src="../res/img/logos/blockly.png"> + </footer> + + + </body> + + <!-- Définition du contenu et de l'organisation de la "toolbox" --> + + + <!-- Script d'intanciation lancé au chargement, doit toujours être à la fin--> + <script src="main-script.js"></script> + +</html> diff --git a/activity_2/main-script.js b/activity_2/main-script.js new file mode 100644 index 0000000000000000000000000000000000000000..3b77535312d2a1caddfca44eff1ba42f40e04f70 --- /dev/null +++ b/activity_2/main-script.js @@ -0,0 +1,62 @@ +var blocklyDiv = document.getElementById('blocklyDiv'); +var blocklyArea = document.getElementById('blocklyArea'); + +var xml = null; +var request = new XMLHttpRequest(); +request.open('GET', 'toolbox.xml', false); +request.send(); +if (request.readyState == 4 && request.status == 200) { + xml = request.responseXML; +} +var toolbox = new XMLSerializer().serializeToString(xml.documentElement); +var workspace = Blockly.inject(blocklyDiv, + {toolbox: toolbox}); + +//Ca a l'air dégueulasse pour faire du responsive mais c'est le truc de la doc +//officielle de google xD +var onresize = function(e) { + // Compute the absolute coordinates and dimensions of blocklyArea. + var element = blocklyArea; + var x = 0; + var y = 0; + do { + x += element.offsetLeft; + y += element.offsetTop; + element = element.offsetParent; + } while (element); + // Position blocklyDiv over blocklyArea. + blocklyDiv.style.left = x + 'px'; + blocklyDiv.style.top = y + 'px'; + blocklyDiv.style.width = blocklyArea.offsetWidth + 'px'; + blocklyDiv.style.height = blocklyArea.offsetHeight + 'px'; + Blockly.svgResize(workspace); + }; + window.addEventListener('resize', onresize, false); + onresize(); + Blockly.svgResize(workspace); + + +//Lance le code tel que rentré par le joueur +function runCode() { + var code = Blockly.JavaScript.workspaceToCode(workspace); //On récupère un code javascript + var myInterpreter = new Interpreter(code, initApi); //Intanciation d'une VM avec fonctions réécrites + myInterpreter.run(); //On lance le code de l'utilisateur dans la VM + //Il est possible de lancer le code de façon séquencielle +} + +//Interprétation des commandes par l'utiliseur (redéfinition des fonctions avec IO) +function initApi(interpreter, scope) { + // Add an API function for the alert() block. + var wrapper = function(text) { + return alert(arguments.length ? text : ''); + }; + interpreter.setProperty(scope, 'alert', + interpreter.createNativeFunction(wrapper)); + + // Add an API function for the prompt() block. + wrapper = function(text) { + return prompt(text); + }; + interpreter.setProperty(scope, 'prompt', + interpreter.createNativeFunction(wrapper)); +} diff --git a/activity_2/toolbox.xml b/activity_2/toolbox.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef3fb0b8383dd0eedff31371e320020119200e5f --- /dev/null +++ b/activity_2/toolbox.xml @@ -0,0 +1,311 @@ +<xml xmlns="https://developers.google.com/blockly/xml"> + <category name="Logic" colour="%{BKY_LOGIC_HUE}"> + <category name="If"> + <block type="controls_if"></block> + <block type="controls_if"> + <mutation else="1"></mutation> + </block> + <block type="controls_if"> + <mutation elseif="1" else="1"></mutation> + </block> + </category> + <category name="Boolean" colour="%{BKY_LOGIC_HUE}"> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null"></block> + <block type="logic_ternary"></block> + </category> + </category> + <category name="Loops" colour="%{BKY_LOOPS_HUE}"> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + <block type="controls_whileUntil"></block> + <block type="controls_for"> + <field name="VAR">i</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="%{BKY_MATH_HUE}"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + <block type="math_arithmetic"></block> + <block type="math_single"></block> + <block type="math_trig"></block> + <block type="math_constant"></block> + <block type="math_number_property"></block> + <block type="math_round"></block> + <block type="math_on_list"></block> + <block type="math_modulo"></block> + <block type="math_constrain"> + <value name="LOW"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="HIGH"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_int"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_float"></block> + <block type="math_atan2"></block> + </category> + <category name="Lists" colour="%{BKY_LISTS_HUE}"> + <block type="lists_create_empty"></block> + <block type="lists_create_with"></block> + <block type="lists_repeat"> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"></block> + <block type="lists_getIndex"></block> + <block type="lists_setIndex"></block> + </category> + <sep></sep> + <category name="Variables" custom="VARIABLE" colour="%{BKY_VARIABLES_HUE}"> + </category> + <category name="Functions" custom="PROCEDURE" colour="%{BKY_PROCEDURES_HUE}"> + </category> + <sep></sep> + <category name="Library" expanded="true"> + <category name="Randomize"> + <block type="procedures_defnoreturn"> + <mutation> + <arg name="list"></arg> + </mutation> + <field name="NAME">randomize</field> + <statement name="STACK"> + <block type="controls_for" inline="true"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <statement name="DO"> + <block type="variables_set" inline="false"> + <field name="VAR">y</field> + <value name="VALUE"> + <block type="math_random_int" inline="true"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">temp</field> + <value name="VALUE"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">temp</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + </statement> + </block> + </category> + <category name="Jabberwocky"> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">'Twas brillig, and the slithy toves</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> Did gyre and gimble in the wabe:</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">All mimsy were the borogroves,</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> And the mome raths outgrabe.</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">"Beware the Jabberwock, my son!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The jaws that bite, the claws that catch!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">Beware the Jubjub bird, and shun</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The frumious Bandersnatch!"</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </category> + </category> +</xml> diff --git a/activity_3/index.html b/activity_3/index.html new file mode 100644 index 0000000000000000000000000000000000000000..49c409e9542d0dc3c626c7713adcad0596257df6 --- /dev/null +++ b/activity_3/index.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + <head> + <title>Road to the Moon !</title> + <meta charset="utf-8" /> + <link rel="stylesheet" href="../res/style.css" /> + + <!-- Import des bibliothèques js nécessaires --> + <script src="../res/blockly/blockly_compressed.js"></script> + <script src="../res/blockly/blocks_compressed.js"></script> + <script src="../res/blockly/javascript_compressed.js"></script> + <script src="../res/blockly/msg/js/fr.js"></script> + <script src="../res/JS-Interpreter/acorn_interpreter.js"></script> + + </head> + + + <body> + <header> + <p>Road to the moon !</p> + </header> + <section class="mainSection"> + <!-- Création de la div portant blockly et d'un conteneur supérieur pour le responsive--> + <div id="blocklyArea"><div id="blocklyDiv" ></div></div> + <div id="toolsArea"> + <a onclick="runCode()" id="runButton">Lancer le programme !</a> + </div> + </section> + + + <footer> + <img src="../res/img/logos/insa.png"> + <img src="../res/img/logos/clubelek.png"> + <img src="../res/img/logos/blockly.png"> + </footer> + + + </body> + + <!-- Définition du contenu et de l'organisation de la "toolbox" --> + + + <!-- Script d'intanciation lancé au chargement, doit toujours être à la fin--> + <script src="main-script.js"></script> + +</html> diff --git a/activity_3/main-script.js b/activity_3/main-script.js new file mode 100644 index 0000000000000000000000000000000000000000..3b77535312d2a1caddfca44eff1ba42f40e04f70 --- /dev/null +++ b/activity_3/main-script.js @@ -0,0 +1,62 @@ +var blocklyDiv = document.getElementById('blocklyDiv'); +var blocklyArea = document.getElementById('blocklyArea'); + +var xml = null; +var request = new XMLHttpRequest(); +request.open('GET', 'toolbox.xml', false); +request.send(); +if (request.readyState == 4 && request.status == 200) { + xml = request.responseXML; +} +var toolbox = new XMLSerializer().serializeToString(xml.documentElement); +var workspace = Blockly.inject(blocklyDiv, + {toolbox: toolbox}); + +//Ca a l'air dégueulasse pour faire du responsive mais c'est le truc de la doc +//officielle de google xD +var onresize = function(e) { + // Compute the absolute coordinates and dimensions of blocklyArea. + var element = blocklyArea; + var x = 0; + var y = 0; + do { + x += element.offsetLeft; + y += element.offsetTop; + element = element.offsetParent; + } while (element); + // Position blocklyDiv over blocklyArea. + blocklyDiv.style.left = x + 'px'; + blocklyDiv.style.top = y + 'px'; + blocklyDiv.style.width = blocklyArea.offsetWidth + 'px'; + blocklyDiv.style.height = blocklyArea.offsetHeight + 'px'; + Blockly.svgResize(workspace); + }; + window.addEventListener('resize', onresize, false); + onresize(); + Blockly.svgResize(workspace); + + +//Lance le code tel que rentré par le joueur +function runCode() { + var code = Blockly.JavaScript.workspaceToCode(workspace); //On récupère un code javascript + var myInterpreter = new Interpreter(code, initApi); //Intanciation d'une VM avec fonctions réécrites + myInterpreter.run(); //On lance le code de l'utilisateur dans la VM + //Il est possible de lancer le code de façon séquencielle +} + +//Interprétation des commandes par l'utiliseur (redéfinition des fonctions avec IO) +function initApi(interpreter, scope) { + // Add an API function for the alert() block. + var wrapper = function(text) { + return alert(arguments.length ? text : ''); + }; + interpreter.setProperty(scope, 'alert', + interpreter.createNativeFunction(wrapper)); + + // Add an API function for the prompt() block. + wrapper = function(text) { + return prompt(text); + }; + interpreter.setProperty(scope, 'prompt', + interpreter.createNativeFunction(wrapper)); +} diff --git a/activity_3/toolbox.xml b/activity_3/toolbox.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef3fb0b8383dd0eedff31371e320020119200e5f --- /dev/null +++ b/activity_3/toolbox.xml @@ -0,0 +1,311 @@ +<xml xmlns="https://developers.google.com/blockly/xml"> + <category name="Logic" colour="%{BKY_LOGIC_HUE}"> + <category name="If"> + <block type="controls_if"></block> + <block type="controls_if"> + <mutation else="1"></mutation> + </block> + <block type="controls_if"> + <mutation elseif="1" else="1"></mutation> + </block> + </category> + <category name="Boolean" colour="%{BKY_LOGIC_HUE}"> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null"></block> + <block type="logic_ternary"></block> + </category> + </category> + <category name="Loops" colour="%{BKY_LOOPS_HUE}"> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + <block type="controls_whileUntil"></block> + <block type="controls_for"> + <field name="VAR">i</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="%{BKY_MATH_HUE}"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + <block type="math_arithmetic"></block> + <block type="math_single"></block> + <block type="math_trig"></block> + <block type="math_constant"></block> + <block type="math_number_property"></block> + <block type="math_round"></block> + <block type="math_on_list"></block> + <block type="math_modulo"></block> + <block type="math_constrain"> + <value name="LOW"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="HIGH"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_int"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_float"></block> + <block type="math_atan2"></block> + </category> + <category name="Lists" colour="%{BKY_LISTS_HUE}"> + <block type="lists_create_empty"></block> + <block type="lists_create_with"></block> + <block type="lists_repeat"> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"></block> + <block type="lists_getIndex"></block> + <block type="lists_setIndex"></block> + </category> + <sep></sep> + <category name="Variables" custom="VARIABLE" colour="%{BKY_VARIABLES_HUE}"> + </category> + <category name="Functions" custom="PROCEDURE" colour="%{BKY_PROCEDURES_HUE}"> + </category> + <sep></sep> + <category name="Library" expanded="true"> + <category name="Randomize"> + <block type="procedures_defnoreturn"> + <mutation> + <arg name="list"></arg> + </mutation> + <field name="NAME">randomize</field> + <statement name="STACK"> + <block type="controls_for" inline="true"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <statement name="DO"> + <block type="variables_set" inline="false"> + <field name="VAR">y</field> + <value name="VALUE"> + <block type="math_random_int" inline="true"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">temp</field> + <value name="VALUE"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">temp</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + </statement> + </block> + </category> + <category name="Jabberwocky"> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">'Twas brillig, and the slithy toves</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> Did gyre and gimble in the wabe:</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">All mimsy were the borogroves,</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> And the mome raths outgrabe.</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">"Beware the Jabberwock, my son!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The jaws that bite, the claws that catch!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">Beware the Jubjub bird, and shun</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The frumious Bandersnatch!"</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </category> + </category> +</xml> diff --git a/activity_4/index.html b/activity_4/index.html new file mode 100644 index 0000000000000000000000000000000000000000..49c409e9542d0dc3c626c7713adcad0596257df6 --- /dev/null +++ b/activity_4/index.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + <head> + <title>Road to the Moon !</title> + <meta charset="utf-8" /> + <link rel="stylesheet" href="../res/style.css" /> + + <!-- Import des bibliothèques js nécessaires --> + <script src="../res/blockly/blockly_compressed.js"></script> + <script src="../res/blockly/blocks_compressed.js"></script> + <script src="../res/blockly/javascript_compressed.js"></script> + <script src="../res/blockly/msg/js/fr.js"></script> + <script src="../res/JS-Interpreter/acorn_interpreter.js"></script> + + </head> + + + <body> + <header> + <p>Road to the moon !</p> + </header> + <section class="mainSection"> + <!-- Création de la div portant blockly et d'un conteneur supérieur pour le responsive--> + <div id="blocklyArea"><div id="blocklyDiv" ></div></div> + <div id="toolsArea"> + <a onclick="runCode()" id="runButton">Lancer le programme !</a> + </div> + </section> + + + <footer> + <img src="../res/img/logos/insa.png"> + <img src="../res/img/logos/clubelek.png"> + <img src="../res/img/logos/blockly.png"> + </footer> + + + </body> + + <!-- Définition du contenu et de l'organisation de la "toolbox" --> + + + <!-- Script d'intanciation lancé au chargement, doit toujours être à la fin--> + <script src="main-script.js"></script> + +</html> diff --git a/activity_4/main-script.js b/activity_4/main-script.js new file mode 100644 index 0000000000000000000000000000000000000000..3b77535312d2a1caddfca44eff1ba42f40e04f70 --- /dev/null +++ b/activity_4/main-script.js @@ -0,0 +1,62 @@ +var blocklyDiv = document.getElementById('blocklyDiv'); +var blocklyArea = document.getElementById('blocklyArea'); + +var xml = null; +var request = new XMLHttpRequest(); +request.open('GET', 'toolbox.xml', false); +request.send(); +if (request.readyState == 4 && request.status == 200) { + xml = request.responseXML; +} +var toolbox = new XMLSerializer().serializeToString(xml.documentElement); +var workspace = Blockly.inject(blocklyDiv, + {toolbox: toolbox}); + +//Ca a l'air dégueulasse pour faire du responsive mais c'est le truc de la doc +//officielle de google xD +var onresize = function(e) { + // Compute the absolute coordinates and dimensions of blocklyArea. + var element = blocklyArea; + var x = 0; + var y = 0; + do { + x += element.offsetLeft; + y += element.offsetTop; + element = element.offsetParent; + } while (element); + // Position blocklyDiv over blocklyArea. + blocklyDiv.style.left = x + 'px'; + blocklyDiv.style.top = y + 'px'; + blocklyDiv.style.width = blocklyArea.offsetWidth + 'px'; + blocklyDiv.style.height = blocklyArea.offsetHeight + 'px'; + Blockly.svgResize(workspace); + }; + window.addEventListener('resize', onresize, false); + onresize(); + Blockly.svgResize(workspace); + + +//Lance le code tel que rentré par le joueur +function runCode() { + var code = Blockly.JavaScript.workspaceToCode(workspace); //On récupère un code javascript + var myInterpreter = new Interpreter(code, initApi); //Intanciation d'une VM avec fonctions réécrites + myInterpreter.run(); //On lance le code de l'utilisateur dans la VM + //Il est possible de lancer le code de façon séquencielle +} + +//Interprétation des commandes par l'utiliseur (redéfinition des fonctions avec IO) +function initApi(interpreter, scope) { + // Add an API function for the alert() block. + var wrapper = function(text) { + return alert(arguments.length ? text : ''); + }; + interpreter.setProperty(scope, 'alert', + interpreter.createNativeFunction(wrapper)); + + // Add an API function for the prompt() block. + wrapper = function(text) { + return prompt(text); + }; + interpreter.setProperty(scope, 'prompt', + interpreter.createNativeFunction(wrapper)); +} diff --git a/activity_4/toolbox.xml b/activity_4/toolbox.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef3fb0b8383dd0eedff31371e320020119200e5f --- /dev/null +++ b/activity_4/toolbox.xml @@ -0,0 +1,311 @@ +<xml xmlns="https://developers.google.com/blockly/xml"> + <category name="Logic" colour="%{BKY_LOGIC_HUE}"> + <category name="If"> + <block type="controls_if"></block> + <block type="controls_if"> + <mutation else="1"></mutation> + </block> + <block type="controls_if"> + <mutation elseif="1" else="1"></mutation> + </block> + </category> + <category name="Boolean" colour="%{BKY_LOGIC_HUE}"> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null"></block> + <block type="logic_ternary"></block> + </category> + </category> + <category name="Loops" colour="%{BKY_LOOPS_HUE}"> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + <block type="controls_whileUntil"></block> + <block type="controls_for"> + <field name="VAR">i</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="%{BKY_MATH_HUE}"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + <block type="math_arithmetic"></block> + <block type="math_single"></block> + <block type="math_trig"></block> + <block type="math_constant"></block> + <block type="math_number_property"></block> + <block type="math_round"></block> + <block type="math_on_list"></block> + <block type="math_modulo"></block> + <block type="math_constrain"> + <value name="LOW"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="HIGH"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_int"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + <block type="math_random_float"></block> + <block type="math_atan2"></block> + </category> + <category name="Lists" colour="%{BKY_LISTS_HUE}"> + <block type="lists_create_empty"></block> + <block type="lists_create_with"></block> + <block type="lists_repeat"> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"></block> + <block type="lists_getIndex"></block> + <block type="lists_setIndex"></block> + </category> + <sep></sep> + <category name="Variables" custom="VARIABLE" colour="%{BKY_VARIABLES_HUE}"> + </category> + <category name="Functions" custom="PROCEDURE" colour="%{BKY_PROCEDURES_HUE}"> + </category> + <sep></sep> + <category name="Library" expanded="true"> + <category name="Randomize"> + <block type="procedures_defnoreturn"> + <mutation> + <arg name="list"></arg> + </mutation> + <field name="NAME">randomize</field> + <statement name="STACK"> + <block type="controls_for" inline="true"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <statement name="DO"> + <block type="variables_set" inline="false"> + <field name="VAR">y</field> + <value name="VALUE"> + <block type="math_random_int" inline="true"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">temp</field> + <value name="VALUE"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">y</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="lists_getIndex" inline="true"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex" inline="false"> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">temp</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + </statement> + </block> + </category> + <category name="Jabberwocky"> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">'Twas brillig, and the slithy toves</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> Did gyre and gimble in the wabe:</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">All mimsy were the borogroves,</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> And the mome raths outgrabe.</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">"Beware the Jabberwock, my son!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The jaws that bite, the claws that catch!</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">Beware the Jubjub bird, and shun</field> + </block> + </value> + <next> + <block type="text_print"> + <value name="TEXT"> + <block type="text"> + <field name="TEXT"> The frumious Bandersnatch!"</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </category> + </category> +</xml>