1 <html>
2 <head>
3 <meta charset="utf-8">
4 <title>计算</title>
5 </head>
6 <body>
7 <p>1、红色(功法) 2、黄色(速度) 3、蓝色(气血) 4、绿色(防御)</p>
8 <p>等级:
9 <select>
10 <option>50-54级</option>
11 <option>55-59级</option>
12 <option>61-64级</option>
13 <option>65级以上</option>
14 </select>
15 </p>
16 <div>
17 <table border="1" id="buwei_table">
18 <tr>
19 <th>部位</th>
20 <th>是否</th>
21 <th>左上</th>
22 <th>右上</th>
23 <th>右下</th>
24 <th>左下</th>
25 </tr>
26 </table>
27 </div>
28
29 连线条数:<select id="lianxian">
30 <option>1</option>
31 <option>2</option>
32 <option>3</option>
33 <option>4</option>
34 <option>5</option>
35 <option>6</option>
36 <option>7</option>
37 <option>8</option>
38 <option>9</option>
39 <option>10</option>
40 <option>11</option>
41 <option>12</option>
42 </select>
43 <input type="button" value="计算" onclick="FResult()">
44 <div>
45 <table border="1">
46 <tr>
47 <td width="20" height="20"></td>
48 <td width="20" height="20"></td>
49 <td id="tu_td6" width="20" height="20" style="text-align:center;background-color: darkgray">6</td>
50 <td width="20" height="20"></td>
51 <td width="20" height="20"></td>
52 </tr>
53 <tr>
54 <td width="20" height="20"></td>
55 <td id="tu_td2" width="20" height="20" style="text-align:center;background-color: darkgray">2</td>
56 <td width="20" height="20"></td>
57 <td id="tu_td3" width="20" height="20" style="text-align:center;background-color: darkgray">3</td>
58 <td width="20" height="20"></td>
59 </tr>
60 <tr>
61 <td id="tu_td8" width="20" height="20" style="text-align:center;background-color: darkgray">8</td>
62 <td width="20" height="20"></td>
63 <td id="tu_td1" width="20" height="20" style="text-align:center;background-color: darkgray">1</td>
64 <td width="20" height="20"></td>
65 <td id="tu_td9" width="20" height="20" style="text-align:center;background-color: darkgray">9</td>
66 </tr>
67 <tr>
68 <td width="20" height="20"></td>
69 <td id="tu_td5" width="20" height="20" style="text-align:center;background-color: darkgray">5</td>
70 <td width="20" height="20"></td>
71 <td id="tu_td4" width="20" height="20" style="text-align:center;background-color: darkgray">4</td>
72 <td width="20" height="20"></td>
73 </tr>
74 <tr>
75 <td width="20" height="20"></td>
76 <td width="20" height="20"></td>
77 <td id="tu_td7" width="20" height="20" style="text-align:center;background-color: darkgray">7</td>
78 <td width="20" height="20"></td>
79 <td width="20" height="20"></td>
80 </tr>
81 </table>
82 </div>
83 <div id="result">
84 <table border="1" id="table">
85 <tr>
86 <th>1号位</th>
87 <th>2号位</th>
88 <th>3号位</th>
89 <th>4号位</th>
90 <th>5号位</th>
91 <th>6号位</th>
92 <th>7号位</th>
93 <th>8号位</th>
94 <th>9号位</th>
95 <th>属性</th>
96 <th>操作</th>
97 </tr>
98
99 </table>
100 </div>
101 <script type="application/javascript">
102 //创建部位列表
103 window.onload=function () {
104 var buwei_arr = ['束带','上衣','护腕','下摆','武器','玉佩','项链','腰带','鞋子'];
105 var buwei_table = document.getElementById('buwei_table');
106 buwei_arr.forEach(function (buwei) {
107 var buwei_tr = document.createElement('tr');
108 var buwei_td = document.createElement('td');
109 buwei_td.innerText=buwei;
110 buwei_tr.appendChild(buwei_td);
111 var shifou_td = document.createElement('td');
112 shifou_td.innerHTML='<select><option value="0">否</option><option value="1">是</option></select>';
113 buwei_tr.appendChild(shifou_td);
114 for (var i=0;i<4;i++){
115 var td1 = document.createElement('td');
116 td1.innerHTML='<select><option value="1" style="color:red;">红</option><option value="2" style="color:yellow">黄</option>' +
117 '<option value="3" style="color:blue">蓝</option><option value="4" style="color:green">绿</option></select>';
118 buwei_tr.appendChild(td1);
119 };
120 buwei_table.appendChild(buwei_tr);
121 });
122 };
123 function create_arr() {
124 var arr1=[];
125 var buwei_arr = ['束带','上衣','护腕','下摆','武器','玉佩','项链','腰带','鞋子'];
126 var buwei_table = document.getElementById('buwei_table');
127 for (var i=1;i<buwei_table.children.length;i++){
128 var arr2=[];
129 for (var j=2;j<6;j++){
130 if(buwei_table.children[i].children[1].children[0].selectedIndex===1){
131 arr2.push(buwei_table.children[i].children[j].children[0].selectedIndex+1)
132 }
133 }
134 arr2.push(buwei_arr[i-1]);
135 arr1.push(arr2)
136 }
137 return arr1;
138 }
139 //全排列
140 function fullSort(arr){
141 var result = [];
142 if (arr.length == 1) {
143 result.push(arr);
144 return result;
145 }
146 for (var i = 0; i < arr.length; i++) {
147 var temp = [];
148 temp.push(arr[i]);
149 var remain = arr.slice(0);
150 remain.splice(i,1);
151 var temp2 = fullSort(remain).concat();
152 for (var j = 0; j < temp2.length; j++) {
153 temp2[j].unshift(temp[0]);
154 result.push(temp2[j]);
155 }
156 }
157 return result;
158 };
159
160 //计算结果
161 function FResult() {
162 var l = [
163 [2,3,2,1,'束带'],
164 [1,1,2,2,'上衣'],
165 [4,4,1,1,'护腕'],
166 [2,4,2,1,'下摆'],
167 [4,4,1,2,'武器'],
168 [3,3,1,4,'玉佩'],
169 [2,2,3,4,'项链'],
170 [1,4,2,3,'腰带'],
171 [1,4,4,2,'鞋子']
172 ];
173 var table = document.getElementById('table');
174 for (i=table.children.length-1;i>=1;i--){
175 table.removeChild(table.children[i]);
176 }
177 var all_l = [];
178 for (var i = 0, arr = fullSort(l); i < arr.length; i++) {
179 all_l.push(arr[i]);
180 };
181 var count_id = 0;
182 all_l.forEach(function (l1) {
183 var count=0;
184 var zuhe=[];
185 if (l1[0][0]===l1[1][2]){
186 count+=1;
187 zuhe.push(l1[0][0]);
188 };
189 if (l1[0][1]===l1[2][3]){
190 count+=1;
191 zuhe.push(l1[0][1])
192 };
193 if (l1[0][2]===l1[3][0]){
194 count+=1;
195 zuhe.push(l1[0][2])
196 };
197 if (l1[0][3]===l1[3][1]){
198 count+=1;
199 zuhe.push(l1[0][3])
200 };
201 if (l1[5][3]===l1[1][1]){
202 count+=1;
203 zuhe.push(l1[5][3])
204 };
205 if (l1[5][2]===l1[2][0]){
206 count+=1;
207 zuhe.push(l1[5][2])
208 };
209 if (l1[6][0]===l1[4][2]){
210 count+=1;
211 zuhe.push(l1[6][0])
212 };
213 if (l1[6][1]===l1[3][3]){
214 count+=1;
215 zuhe.push(l1[6][1])
216 };
217 if (l1[7][1]===l1[1][3]){
218 count+=1;
219 zuhe.push(l1[7][1])
220 };
221 if (l1[7][2]===l1[4][0]){
222 count+=1;
223 zuhe.push(l1[7][2])
224 };
225 if (l1[8][0]===l1[2][2]){
226 count+=1;
227 zuhe.push(l1[8][0])
228 };
229 if (l1[8][3]===l1[3][1]) {
230 count += 1;
231 zuhe.push(l1[8][3])
232 };
233 var lianxian = document.getElementById('lianxian');
234 if(count===(lianxian.selectedIndex+1)){
235
236
237 //table.innerHTML='';
238 var tr = document.createElement('tr');
239 tr.id = 'tr'+count_id;
240
241 for (var i=0,arr=l1;i<l1.length;i++){
242 var td = document.createElement('td');
243 td.innerHTML = l1[i][4];
244 tr.appendChild(td);
245 };
246 var td = document.createElement('td');
247 td.innerText=f(zuhe);
248 function f(zuhe){
249 var count1=0;
250 var count2=0;
251 var count3=0;
252 var count4=0;
253 zuhe.forEach(function (v) {
254 if (v===1)count1++;
255 if (v===2)count2++;
256 if (v===3)count3++;
257 if (v===4)count4++;
258 });
259 return '攻击(红色)'+count1+'条'+','+
260 '速度(黄色)'+count2+'条'+','+
261 '气血(蓝色)'+count3+'条'+','+
262 '防御(绿色)'+count4+'条'
263 };
264
265 tr.appendChild(td);
266 var td = document.createElement('td');
267 td.innerHTML='<input type="button" value="代入" onclick="dairu(\''+count_id+'\')">';
268 tr.appendChild(td);
269 table.appendChild(tr);
270 count_id++;
271 };
272 });
273 };
274 function dairu(count_id) {
275 var dairu_tr = document.getElementById('tr'+count_id);
276 for (var i=0;i<9;i++){
277 document.getElementById('tu_td'+(i+1)).innerText = dairu_tr.children[i].innerText;
278 }
279 }
280
281 </script>
282 </body>
283 </html>