-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape_pattern.html
281 lines (271 loc) · 8.32 KB
/
shape_pattern.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<html>
<head>
<style>
body {
font-family: "Helvetica Neue", "Calibri","Arial", sans-serif;
color: #444444;
}
#problemArea {
max-width:800px;
}
#workingArea{
display:inline-block;
}
#dashboardArea{
display:inline-block;
min-width:120px;
max-width:320px;
vertical-align: top;
}
#outputArea {
min-width:800px;
max-width:800px;
min-height:80px;
}
#outputContainer {
max-width:800px;
background: #f1f1f1;
}
#dialog {
display:none;
}
#avatar {
position:absolute;
top:-16px;
left:-16px;
z-index:2;
max-width:40px;
max-height:95px;
width: auto;
height: auto;
}
h1 {
font-size: 16px;
display:inline-block;
}
.runButton {
font-size: 16px;
margin-left:28px;
background: #ff7619;
border: none;
color: #ffffff;
padding: 8px 24px;
}
.runButton:hover {
margin-left:28px;
background: #cf5300;
border: none;
color: #ffffff;
padding: 8px 24px;
}
</style>
<link rel="stylesheet" href="../jquery-ui.min.css">
<script src="../external/jquery/jquery.js"></script>
<script src="../jquery-ui.min.js"></script>
<script src="shapes_puzzle.js"></script>
<script src="scoring.js"></script>
<script src="blockly/blockly_compressed.js"></script>
<script src="blockly/blocks_compressed.js"></script>
<script src="blockly/msg/js/en.js"></script>
<script src="blockly/javascript_compressed.js"></script>
<script src="iterative_playground_blocks.js"></script>
<script>
var lo_keys = [ "simpleLinearProgram",
"singleInstructionInLoop",
"twoInstructionsInLoop",
"threeOrMoreInstructionsInLoop"];
var thresholds = {
"simpleLinearProgram":{},
"singleInstructionInLoop":{"simpleLinearProgram":4},
"twoInstructionsInLoop":{"singleInstructionInLoop":2},
"threeOrMoreInstructionsInLoop":{"twoInstructionsInLoop":3}
};
var learningObjectives = {
"simpleLinearProgram": {"friendlyName":"Create a simple linear program","generator":genSimpleLinearProgram},
"singleInstructionInLoop": {"friendlyName":"Create a loop with a single repeated instruction","generator":genSingleInstructionInLoop},
"twoInstructionsInLoop": {"friendlyName":"Create a loop with two repeated instructions where order matters","generator":genTwoInstructionsInLoop},
"threeOrMoreInstructionsInLoop": {"friendlyName":"Create a loop with three or more repeated instructions where order matters","generator":genThreeOrMoreInstructionsInLoop}
};
Blockly.Msg.LOOPS_HUE="#DC56B0"
String.prototype.replaceAll = function(searchString,replacementString) {
var target = this;
return target.replace(new RegExp(searchString,'g'),replacementString);
};
var userScores = {
"simpleLinearProgram":0,
"singleInstructionInLoop":0,
"twoInstructionsInLoop": 0,
"threeOrMoreInstructionsInLoop": 0,
}
var code;
var lastProblem="";
var linesTarget = 0;
var currentLO;
var startToolboxStr = '<xml><block type="put_circle"></block><block type="put_square"></block><block type="put_triangle"></block></xml>';
var workspace;
var failureSound = new Audio('assets/failure_sound.mp3');
var winSound = new Audio('assets/win_sound.mp3');
var improvingSound = new Audio('assets/improving_sound.mp3');
var finishedSound = new Audio('assets/finished_sound.mp3');
var startSound = new Audio('assets/start_sound.mp3');
//NEED REFACTORING
function generatePuzzle() {
var lines;
var problem;
var lo;
var toolboxString;
var options = selectViableObjectives(userScores,lo_keys);
var lo = chooseRandomObjectiveFromList(options,userScores);
[problem,lines,toolboxString] = learningObjectives[lo]["generator"](userScores[lo]);
console.log(lo);
console.log("Using "+lines+" blocks");
$('#currentLO').text(learningObjectives[lo]["friendlyName"]);
if (workspace != undefined) {
workspace.updateToolbox(toolboxString)
}
//FACTOR THIS RENDERING OUT
$('#problemArea').text(problem);
$('#outputArea').html("");
return [problem,lines,lo];
}
//SHARED FUNCTIONS, AGNOSTIC
function run() {
code = Blockly.JavaScript.workspaceToCode(workspace);
genCode();
}
function nextPuzzle() {
[problem, linesTarget,currentLO] = generatePuzzle();
$('#blockCount').text(linesTarget);
Blockly.mainWorkspace.clear();
updateDashboard();
}
function updateDashboard() {
var newStats = "";
for (var lo in userScores) {
if (userScores.hasOwnProperty(lo)) {
newStats+="<li>"+learningObjectives[lo]["friendlyName"]+": "+userScores[lo]+"</li>";
}
}
$('#proficiencyArea').html(newStats);
}
//SHARED, PUZZLE AGNOSTIC BUT NEED REFACTOR
function finish(result) {
updateScore(result);
if (result == 50) {
improvingSound.play();
$('#dialogMessage').text("We used too many blocks - can you find a repeating pattern?");
$( function() {
$( "#dialog" )
.dialog( {
show: {
effect: "",
duration: 200
},
open: function (event, ui) {
if ($("#avatar").length == 0) {
$(".ui-dialog-titlebar").prepend("<img src='assets/improving_avatar.png' id='avatar' />");
}
else {
$("#avatar").attr("src","assets/improving_avatar.png");
}},
close: function (event, ui) { updateDashboard();},
title: "You're getting close!"
} );
});
} else if (result == 100) {
winSound.play();
$( function() {
$('#dialogMessage').text("My memory is improving!");
$( "#dialog" )
.dialog( {
show: {
effect: "",
duration: 200
},
open: function (event, ui) {
if ($("#avatar").length == 0) {
$(".ui-dialog-titlebar").prepend("<img src='assets/win_avatar.png' id='avatar' />");
}
else {
$("#avatar").attr("src","assets/win_avatar.png");
}
},
close: function (event, ui) { updateDashboard(); nextPuzzle(); },
title: "You did it!"
} );
});
} else {
failureSound.play();
$( function() {
$('#dialogMessage').text("Try to take it one instruction at a time.");
$( "#dialog" )
.dialog( {
show: {
effect: "",
duration: 200
},
open: function (event, ui) {
if ($("#avatar").length == 0) {
$(".ui-dialog-titlebar").prepend("<img src='fassets/ailure_avatar.png' id='avatar' />");
}
else {
$("#avatar").attr("src","assets/failure_avatar.png");
}
},
close: function (event, ui) { updateDashboard(); },
title: "Not quite - keep coding!"})
} );
}
}
</script>
</head>
<body>
<div id='workingArea'>
<div id="instructionContainer"><div id='instructionHeader'><h1>Help me match this using <span id='blockCount'> </span> blocks:</span></h1><button class='runButton' onclick="run()">Run</button>
<button class='runButton' onclick="nextPuzzle()">Skip This</button></div><div id='problemArea'> </div></div>
<div id='outputContainer'><div id='outputHeader'><h1>Your Output:</h1></div><div id='outputArea'> </div></div>
<div id="blocklyDiv" style="height: 480px; max-width: 800px;"></div>
</div><div id='dashboardArea'><h1>Learning Dashboard</h1>
<div style='font-size:10px;color:#777777;margin-top:12px;'>Current Learning Objective: <span id='currentLO'></span><div>Your Proficiency Levels:
<ul id='proficiencyArea'></ul></div>
</div>
<div id="dialog" title="Basic dialog">
<p id='dialogMessage'></p>
</div>
</body>
<script>
var blockCountField = document.getElementById("blockCount");
var outputArea = document.getElementById("outputArea");
var problemArea = document.getElementById("problemArea");
$(document).ready(function(){
startSound.play();
workspace = Blockly.inject('blocklyDiv',
{toolbox: startToolboxStr});
$('#dialogMessage').html("<p>Thank goodness you're here! I am a robot that puts shapes in order. I was pretty good at it, but there was a solar flare and now my code is all scrambled! Can you help me remember how to put these shapes in order?</p><p>When we get a pattern right, the next one might be harder. Don't get discouraged! Remember, your brain is like a muscle - the more you stretch it, the stronger it will get!</p><p>Drag blocks together to match the pattern. After you put the blocks together, click 'Run' up above.</p>");
$( "#dialog" )
.dialog( {
title: "I need your help!",
hide: {
effect: "clip",
duration: 100
},
show: {
effect: "bounce",
duration: 500
},
modal: true,
width: 360,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
},
open: function (event, ui) {
$(".ui-dialog-titlebar").prepend("<img src='assets/idle_avatar.png' id='avatar' />");
},
close: function (event, ui) {
nextPuzzle();
}})
});
</script>
</html>