-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
65 lines (50 loc) · 1.26 KB
/
Copy pathshared.js
File metadata and controls
65 lines (50 loc) · 1.26 KB
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
"use strict";
(function(exports){
// your code goes here
exports.xkcdRandom = function()
{
console.log("gold standard");
return 4;
};
exports.calculateDistance = function(locationAlpha,locationBravo)
{
var distance = Math.hypot(locationAlpha[0] - locationBravo[0],locationAlpha[1] - locationBravo[1]);
return distance;
};
exports.checkValidAttack = function(attacker,defender)
{
if (exports.calculateDistance(attacker.location,defender.location) > attacker.range)
{
return "Too far.";
}
if (attacker.actionPoints < attacker.attackCost)
{
return "Not enough Action points.";
}
if (attacker.health<=0)
{
return "Attacker is dead.";
}
if (defender.health<=0)
{
return "Defender is dead.";
}
return true;
};
exports.isAlphaNumeric = function(str)
{
var code, i, len;
for (i = 0, len = str.length; i < len; i++)
{
code = str.charCodeAt(i);
if (!(code > 47 && code < 58) && // numeric (0-9)
!(code > 64 && code < 91) && // upper alpha (A-Z)
!(code > 96 && code < 123)) { // lower alpha (a-z)
return false;
}
}
return true;
};
console.log("shared.js loaded inside.");
})(typeof exports === 'undefined'? this['shared']={}: exports);
console.log("shared.js loaded outside.");