-
Notifications
You must be signed in to change notification settings - Fork 1
/
domayhem.js
70 lines (64 loc) · 2.03 KB
/
domayhem.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
67
68
69
70
function update(key, value, dom) {
var parent = "";
if (dom)
parent = "#" + dom.id + " ";
glow.dom.get(parent + "#" + key).html(value);
}
function log(message) {
glow.dom.get("#log").prepend("<div>" + message + "</div>");
}
function rand( min, max ) {
// Returns a random number
//
// version: 810.1317
// discuss at: http://phpjs.org/functions/rand
// + original by: Leslie Hoare
// + bugfixed by: Onno Marsman
// * example 1: rand(1, 1);
// * returns 1: 1
var argc = arguments.length;
if (argc == 0) {
min = 0;
max = 2147483647;
} else if (argc == 1) {
throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function removeElementFromArray(arr,i) {
var tempArr = [];
tempArr = tempArr.concat(arr);
tempArr.splice(i, 1);
return tempArr;
}
function debugPlayers(players) {
var o = "";
for (var i = 0; i < players.length; i++) {
o += players[i].name + " ";
}
log("debug> " + o);
}
function pause(numMilliseconds) {
var now, goalTime;
now = new Date();
goalTime = now.getTime() + numMilliseconds;
while (now.getTime() < goalTime) {
now = new Date();
}
}
function usleep(microseconds) {
// Delay for a given number of micro seconds
//
// version: 902.122
// discuss at: http://phpjs.org/functions/usleep
// // + original by: Brett Zamir
// % note 1: For study purposes. Current implementation could lock up the user's browser.
// % note 1: Consider using setTimeout() instead.
// % note 2: Note that this function's argument, contrary to the PHP name, does not
// % note 2: start being significant until 1,000 microseconds (1 millisecond)
// * example 1: usleep(2000000); // delays for 2 seconds
// * returns 1: true
var start = new Date().getTime();
while (new Date() < (start + microseconds/1000));
return true;
}