-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbuilder.html
164 lines (141 loc) · 5.57 KB
/
mapbuilder.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>WordGame地图编辑</title>
<style>
.border {
border: 1px solid black;
}
</style>
</head>
<body>
<textarea id="text" placeholder="编辑地图" rows="15" cols="30" onchange="show()"></textarea>
<a href="javascript:void(0);" onClick="clicka()" id="process">处理</a>
<div id="output">
<p>方块种类:</p>
<p id="word"></p>
<p>颜色:<input type="text" id="color"></p>
<p>可以通过的方块:<input type="text" id="passable"></p>
<a href="javascript:void(0);" onClick="reload()">导出地图</a>
<p id="map"></p>
<p>输出内容(请全部复制并粘贴到游戏的地图组件的输入栏里):</p>
<a href="explain.html" id="show">说明</a><br>
<div class="border">
<p id="result">
</p>
</div>
</div>
<script>
document.getElementById('output').style.visibility = "hidden"; //隐藏output部分
var num;
var map_length;
map = new Array();
map_output = new Array();
word = new Array();
color = new Array();
passable = new Array();
//一键复制
function copyText(id) {
s = document.getElementById(id).parentElement.id;
var Url2 = document.getElementById(s).innerText;
var oInput = document.createElement('input');
oInput.value = Url2;
document.body.appendChild(oInput);
oInput.select();
document.execCommand("Copy");
oInput.className = 'oInput';
oInput.style.display = 'none';
alert('复制成功');
}
// 判断元素是否在数组内的函数,使用方法:contains(Array,元素),返回true或false
function contains(arr, obj) {
var i = arr.length;
while (i--) {
if (arr[i] === obj) {
return true;
}
}
return false;
}
//处理输入的地图底稿
function clicka() {
//将地图拆分成数组map
var aa = document.getElementById("text");
var lines = aa.value.split("\n");
for (i = 0; i < lines.length; i++) {
map[i] = lines[i].split("");
}
num = 1;
word[0] = "人";
color[0] = "red";
// 提取地图中出现过的字(方块),并放入word数组中
for (i = 0; i < map.length; i++) {
for (j = 0; j < map[i].length; j++) {
if (!contains(word, map[i][j])) {
word[num] = map[i][j];
color[num] = "black";
num += 1;
}
}
}
// 显示
drawmap();
word[word.length] = "怪";
color[color.length] = "red";
passable = word;
document.getElementById("word").innerHTML = word;
document.getElementById("color").value = color;
document.getElementById("passable").value = passable;
hide();
}
function drawmap() {
//画地图
document.getElementById("map").innerHTML = "";
document.getElementById("map").innerHTML += "预览:<br>";
for (i = 0; i < map.length; i++) {
var line = "";
for (j = 0; j < map[i].length; j++) {
line += map[i][j];
}
document.getElementById("map").innerHTML += line + "<br>";
}
//地图着色
for (i = 0; i < word.length; i++) {
var oBox = document.getElementById("map");
var oContent = oBox.innerHTML;
var val = word[i];
var findText = oContent.split(val);
oBox.innerHTML = findText.join('<span style="color:' + color[i] + ';">' + val + '</span>');
}
}
// 导出地图
function reload() {
color_get = document.getElementById("color").value; //获取调整后的color
color = color_get.split(","); //拆分成数组
passable_get = document.getElementById("passable").value; //获取调整后的passable
passable = passable_get.split(","); //拆分成数组
drawmap();
map_length = map.length - 1;
map_output = [];
map_output = JSON.parse(JSON.stringify(map)); //https://www.cnblogs.com/Blogzlj/p/13031677.html
word[word.length] = "土";
color[color.length] = "Sienna"
passable[passable.length] = "土";
map_output[map_length + 1] = word;
map_output[map_length + 2] = color;
map_output[map_length + 3] = passable;
document.getElementById("result").innerHTML = map_output.join(";"); //数组转字符串,元素间用";"连接
document.getElementById("result").innerHTML += '<br><input type="button" id="copy3" value="复制" onclick="copyText(this.id)" />';
}
function show() {
document.getElementById('process').style.display = 'block';
document.getElementById('output').style.visibility = 'hidden';
}
function hide() {
document.getElementById('process').style.display = 'none';
document.getElementById('output').style.visibility = 'visible';
}
</script>
</body>
</html>