forked from israellevin/dafence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (77 loc) · 2.43 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta charset="utf-8">
<title>dafencec</title>
<meta name="description" content="test client for dafence server. Now, with an extra cook in the kitchen!">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
var get = function(url, callback){
$.ajax({
url: url,
dataType: 'jsonp',
success:function(data){
callback(data);
},
error:function(){
console.log('Unable to retrieve ' + url);
}
});
};
var player = {
name: 'root',
get: function(name){
},
claim: function(pos){
get('claim.jsonp?name=' + player.name + '&pos=' + pos.join(','), function(data){
console.log(data);
map.update();
});
}
};
var map = {
update: function(){
get('map.jsonp?pos=' + map.pos.join(','), function(data){
map.table.empty();
var row;
$.each(data, function(i, cell){
if(0 === i % 10) row = $('<tr>').appendTo(map.table);
$('<td>').text(cell[0]).css('background', cell[1]).appendTo(row)
.mousedown(function(e){
if(1 === e.which){
var claim = map.pos.slice()
claim.push(i);
player.claim(claim);
}else{
map.pos.push(i);
map.update();
}
e.stopPropagation();
e.preventDefault();
return false;
});
});
map.label.text(map.pos);
if(map.pos.length > 0) map.backBtn.attr('disabled', false);
else map.backBtn.attr('disabled', true);
});
}
};
$(function(){
var qpos = location.search.match(/[?&]pos=([^&]*)/);
map.pos = qpos && qpos[1] && qpos[1].split(',') || [1, 2, 3, 4];
map.table = $('#map');
map.label = $('#curpos');
map.backBtn = $('#back').click(function(){
map.pos.pop();
map.update();
});
map.update();
});
</script>
</head>
<body oncontextmenu="return false;">
<div>Currently at<div id="curpos"></div><button id="back">Back</button><table id="map"></table></div>
</body>
</html>