-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (103 loc) · 4.31 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
<h1 class="text-center">Ovella a la fuga.</h1>
<div class="container" id="dim-insert">
<div class="form-group">
<label for="dim" class="control-label">Quina dimensió ha de tenir la graella?</label>
<input type="number" class="form-control" id="dim" value="15" />
</div>
<div class="form-group">
<input type="submit" id="dimbtn" value="Crear el mapa" class="form-control btn btn-default" />
</div>
</div>
<div class="container" id="map-creator">
<div id="minimap"></div>
<div class="form-group">
<input type="submit" id="start" disabled="disabled" value="Comença" class="form-control btn btn-default" />
</div>
</div>
<div id="map"></div>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jquery.bc.js"></script>
<script>
$(document).ready(function () {
var $map = $('#map');
var $diminsert = $('#dim-insert');
var $mapcreator = $('#map-creator');
var $minimap = $('#minimap');
var dim = 15;
$('#dimbtn').click(function () {
dim = $('#dim').val();
$diminsert.hide();
$mapcreator.show();
var celldim = $minimap.width() / dim;
for (var col = 0; col < dim; col++) {
var $line = $('<div class="minimap-line"></div>')
for (var row = 0; row < dim; row++) {
var $cell = $('<div class="minimap-cell col-' + col + ' row-' + row + '"></div>');
$cell.css({
width: celldim,
height: celldim
});
$cell.appendTo($line);
}
$line.appendTo($minimap);
}
$('.minimap-cell').click(function () {
$(this).toggleClass('roca').removeClass('cabra');
if ($('.minimap-cell.cabra').length === 0) {
$('#start').prop('disabled', true);
}
});
$('.minimap-cell').on('contextmenu', function (ev) {
$('.minimap-cell.cabra').removeClass('cabra');
$(this).addClass('cabra').removeClass('roca');
$('#start').prop('disabled', false);
return false;
});
$('#start').click(function () {
var roques = [];
$('.minimap-cell.roca').each(function (item) {
var $self = $(this);
var c = +$self.getNum('col-');
var r = +$self.getNum('row-');
roques.push({ col: c, row: r });
});
$mapcreator.hide();
$map.show();
$map.initMap(dim, {
col: +$('.minimap-cell.cabra').getNum('col-'),
row: +$('.minimap-cell.cabra').getNum('row-')
},
roques);
setTimeout(function () { }, 1500);
var interval = setInterval(function () {
$map.seach();
}, 400);
$(document).on('keydown', function (ev) {
if (ev.which == 27) {
clearInterval(interval);
var c = +$('#map').getNum('col-');
var r = +$('#map').getNum('row-');
$('.minimap-cell.cabra').removeClass('cabra');
$('.minimap-cell.col-' + c + '.row-' + r).addClass('cabra');
$mapcreator.show();
$map.html('');
$map.attr('class', '');
$map.hide();
return false;
}
});
return false;
});
});
});
</script>
</body>
</html>