灵山奇缘装备共鸣最优连法

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

猜你喜欢

转载自www.cnblogs.com/cx59244405/p/9211956.html