-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (81 loc) · 3.28 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Experiment Factory Game</title>
<script src='js/phaser.min.js'></script>
<script src='js/jquery.min.js'></script>
<script src='js/box2d-plugin-full.min.js'></script>
<script src='js/Boot.js'></script>
<script src='js/Preloader.js'></script>
<script src='js/Menu.js'></script>
<script src='js/Instructions.js'></script>
<script src='js/Run.js'></script>
<script src='js/problems.js'></script>
</head>
<body>
<script type="text/javascript">
this.data = {}
this.taskdata = []
function inputData(field, value) {
this.data[field] = value
}
function sendData(trial) {
inputData('trial', trial)
this.taskdata.push(this.data);
if (data.finished == 1) {
// Serialize the data
var promise = new Promise(function(resolve, reject) {
var data = "text/json;charset=utf-8," + JSON.stringify(this.taskdata);
resolve(data);
})
promise.then(function(data) {
$.ajax({
type: "POST",
url: '/save',
data: { "data": data },
success: function(){ document.location = "/next" },
dataType: "application/json",
// Endpoint not running, local save
error: function(err) {
if (err.status == 200){
document.location = "/next";
} else {
setTimeout(function() {
var a = document.createElement('a');
a.title = "Download"
a.id = "download"
a.type = "button"
a.download = 'bridge-game_result.json';
a.href = 'data:' + data;
$("#finished").show();
$("#download").click(function(){
$("body").append(a)
a.click()
})
},2000)
}
}
});
})
}
this.data = {};
}
window.onload = function() {
//create the game and the game states
var game = new Phaser.Game(960, 600, Phaser.CANVAS, 'gameContainer')
problem_set='A'
game.state.add('Boot', Game.Boot)
game.state.add('Preloader', Game.Preloader)
game.state.add('Menu',Game.Menu)
game.state.add('Instructions', Game.Instructions)
game.state.add('Run', Game.Run)
//Now start the Boot state.
game.state.start('Boot', true, false, problem_set)
}
</script>
<div id="finished" hidden>
<button id="download" type="button" style="background-color:white;padding:10px; border-radius:5px">Download</button>
</div>
</body>
</html>