-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.js
66 lines (52 loc) · 1.53 KB
/
helpers.js
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
/* Holds all the functions that can manipulate game state */
var gameState = (function () {
/* The object that holds the game state */
var state = {};
return {
newState : function () {
state = { state: 'SAFE' };
},
readState : function () {
return state.state;
},
readHealth : function () {
return state.health;
},
readEnemy : function () {
return state.enemy;
},
writeStateStr : function (stateStr) {
state.state = stateStr;
},
writeHealth : function (health) {
state.health = health;
},
writeEnemy : function (enemy) {
state.enemy = enemy;
}
}
}());
/* Adds a new item to the end of the log list */
function log(msg) {
var node = document.createElement('ons-list-item');
var text = document.createTextNode(msg);
node.appendChild(text)
document.querySelector('#log').appendChild(node);
}
/* Adds a click event listener */
function onClick(selector, callback) {
document.querySelector(selector).addEventListener('click', callback);
}
/* Does something on init event */
function onInit(callback) {
document.addEventListener('init', callback);
}
/* Returns a random integer representing the move the enemy used.
* The integer is interpreted by the Idris wrapper function. */
function enemyResponse() {
return Math.floor((Math.random() * 3) + 1);
}
/* Updates the status bar at the top of the UI. */
function showStatus(status) {
return document.querySelector('#status').innerHTML = status;
}