This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapMaker.html
132 lines (108 loc) · 3 KB
/
MapMaker.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
129
130
<!DOCTYPE html>
<html lang="it" >
<head>
<meta charset="UTF-8">
<title>MapMaker</title>
<link rel="shortcut icon" href="./favicon.ico" />
<style>
body{
background-color: #414141;
}
table{
border-collapse: collapse;
margin: auto;
}
td{
width: 23px;
height: 23px;
border: 1px solid black;
background-color: white;
}
</style>
</head>
<body>
<pre style="color: aliceblue;">
<span style="color: white;">1</span>: terreno
<span style="color: black;">2</span>: muro
<span style="color: green;">3</span>: zombie
<span style="color: orange;">4</span>: player
</pre>
<table></table>
<button>Generate</button>
<script>
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
var cmd = 1;
var press = true;
const len = 16;
const door = 2;
let table = document.querySelector("table");
for (let i=0; i<len; i++) {
let row = table.insertRow();
for (let j=0; j<len; j++) {
let cell = row.insertCell();
cell.style.backgroundColor =
(
((i==0 || i==len-1) && (j>=Math.floor((len+door)/2) || j<(len-door)/2)) ||
((j==0 || j==len-1) && (i>=Math.floor((len+door)/2) || i<(len-door)/2))
) ? 'black' : 'white';
cell.addEventListener('click', ()=>{
if(press){
if(cmd==1) cell.style.backgroundColor = 'white';
if(cmd==2) cell.style.backgroundColor = 'black';
if(cmd==3) cell.style.backgroundColor = 'green';
if(cmd==4) cell.style.backgroundColor = 'orange';
}
});
}
}
document.addEventListener('keydown', function (event) {
switch (event.key) {
case "1": cmd = 1; break;
case "2": cmd = 2; break;
case "3": cmd = 3; break;
case "4": cmd = 4; break;
}
console.log(cmd);
});
document.querySelector('button').addEventListener('click', ()=>{
let data = [];
let tds = document.getElementsByTagName('td');
let okz = false;
let okp = 0;
for (let i=0; i<len; i++){
let tmp = "";
for (let j=0; j<len; j++) {
if(tds[i*len+j].style.backgroundColor == 'white') tmp += ' ';
if(tds[i*len+j].style.backgroundColor == 'black') tmp += 'W';
if(tds[i*len+j].style.backgroundColor == 'green'){
tmp += 'E';
okz = true;
}
if(tds[i*len+j].style.backgroundColor == 'orange'){
tmp += 'P';
okp++ ;
}
}
data.push(tmp);
}
if(!okz || !okp || okp>1){
let err = "Necessario: "
if(!okz) err+='Zombie';
if(!okz && (!okp || okp>1)) err+= ' e ';
if(!okp || okp>1) err+= '1 Player';
alert(err);4
return;
}
download('map.json', JSON.stringify(data, null, "\t"));
});
</script>
</body>
</html>