-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJackal.html
113 lines (103 loc) · 2.68 KB
/
Jackal.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
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
td {width: 80px; height: 80px}
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="Game.js"></script>
<script type="text/javascript">
var halfFieldSize = 3;
//var board = testBoard(halfFieldSize);
var board = serverBoard(test);
function renderTile(tile) {
var res = tile.desc;
if (tile.money)
res += ("<br/>" + "Бабло: " + tile.money);
return res;
}
function renderPirate(pirate) {
var res = pirate.desc + " " + pirate.id;
if (pirate.money)
res += " с баблом"
if (pirate.step)
res += (" _" + pirate.step);
return $("<div></div")
.attr("id", "pirate" + pirate.id)
.text(res)
.click(function() {
checkActions(pirate);
});
}
function renderActions(p, actions) {
for (var action of actions) {
var pos = action.x + "_" + action.y;
$("#" + pos).append(renderAction(p, action));
}
}
function renderAction(who, action) {
var res = $("<div></div>")
.text(action.desc)
.attr("class", "action")
//do action
.click(function () {
$(".action").remove();
var oldX = who.x, oldY = who.y;
var res = action.act(who, board);
//Assuming we received an array of obligatory actions...
if (Array.isArray(res))
renderActions(who, res);
drawTile(oldX, oldY);
drawTile(action.x, action.y);
drawTurn();
});
return res;
}
function drawTurn() {
$("#turn").text(board.currentTeam().name + " ход");
}
function drawTile(i, j) {
var tile = board.tile(i, j);
var pos = i + "_" + j;
var td = $("#" + pos);
td.html(renderTile(tile)).attr("bgcolor", tile.color);
for (var p of board.piratesOn(i, j)) {
if (p.x == i && p.y == j)
td.append(renderPirate(p));
}
}
function checkActions(p) {
$(function () {
$(".action").remove();
renderActions(p, board.possibleActions(p));
});
}
$(function() {
var table = $("#board");
for (var j = 0; j < board.size; ++j) {
var row = $("<tr></tr>");
for (var i = 0; i < board.size; ++i) {
var pos = i + "_" + j;
row.append($("<td></td>").attr("id", pos).text(pos));
}
table.append(row);
}
//Game init
{
//Open the sea tiles
for (var i = 0; i < board.size; ++i) {
drawTile(i, 0);
drawTile(i, board.size - 1);
drawTile(0, i);
drawTile(board.size - 1, i);
}
}
});
</script>
</head>
<body>
<div id="turn"></div>
<table id="board" border="1"></table>
</body>
</html>