-
Notifications
You must be signed in to change notification settings - Fork 0
/
js2-1.html
233 lines (193 loc) · 6.17 KB
/
js2-1.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style/js-2.css">
<!-- <script type="text/javascript" src="js-2.js"></script> -->
<title>js-2</title>
</head>
<body>
<div class="head">
<span class="left"> <</span>
<span class="center">参数设置</span>
<span class="right"><img src="img/circled-help.png" ></span>
</div>
<div class="bigbox">
<div class="main">
<p class="player">玩家匹配</p>
<div class="set" id="fa">
<div class="box" id="fe"></div>
<div class="seting">
<a href="#" id="se">点击设置</a>
<img src="img/pencil.png">
</div>
</div>
</div>
<div class="word">
<div><input type="text" placeholder="水民词组"></div>
<div><input type="text" placeholder="幽灵词组"></div>
</div>
<div class="playernumber">
<div class="inputnumber">玩家人数<input value="8" type="number" id="mynumber">人</div>
<div class="inputbutton">
<button class="buttonleft" id="ca">-</button>
<input id="slider3" value="8" type ="range" min="6" max="18" step ="1"/>
<button class="buttonright" id="ce">+</button>
</div>
</div>
<button class="button" id="bn">去发牌</button>
</div>
<script>
var time;
var p;
var s;
var killer='<li class ="killer">杀手1人</li>';
var cvl='<li class ="pm">平民1人</li>';
var allNumber=document.getElementById("mynumber")
var range=document.getElementById("slider3");
var pfs = document.getElementById("fe");
sessionStorage.clear();
console.log(document.getElementById('slider3').value);
document.getElementById('ce').onclick = function() {
if (allNumber.value>=18){
alert("人数不能超过18人");
}
else {
allNumber.value++;
range.value++;
}
// time =document.getElementById('slider3').value++;
// console.log(document.getElementById('slider3').value);
// document.getElementById("mynumber").value=document.getElementById("slider3").value;
}
document.getElementById("ca").onclick = function () {
if (allNumber.value<=6){
alert("人数不能少于6人");
}
else {
allNumber.value--;
range.value--;
}
// time=document.getElementById("slider3").value--;
// document.getElementById("mynumber").value=document.getElementById("slider3").value;
}
console.log(time)
// document.getElementById("slider3").onchange = function () {
// document.getElementById("mynumber").value=document.getElementById("slider3").value;
// time = document.getElementById("mynumber").value;
// }
range.oninput =function () {
allNumber.value = range.value;
}
allNumber.onblur = function () {
if (allNumber.value < 6){
alert("人数少不够,至少6人起");
allNumber.value = 6;
}
else if (allNumber.value > 18){
alert("人数过多,不能超过18人");
allNumber.value = 18;
}
range.value = allNumber.value;
}
sessionStorage.clear();
document.getElementById("se").onclick = function () {
var time = allNumber.value;
console.log(time);
console.log(p)
//判断杀手和平民的人数
if (time<8){
s=1;
p=time-s;
}
else if (time>7 && time<12){
s=2;
p=time-s;
}
else if (time>11 && time<19){
s=4;
p=time-s;
}
//
//
//杀手人数
var kill=[];
var civilian=[];
var allnumber=[];
document.getElementById("fe").innerHTML="";
for(var i=0;i<s;i++){
kill[i]=killer;
// console.log(kill)
}
//平民人数
for(var i=0;i<p;i++){
civilian[i]=cvl;
// console.log(civilian)
}
allnumber=kill.concat(civilian);
console.log(allnumber)
//随机数组
function shuffle() {
var a=(allnumber);
var b=[];
while (a.length>0){
var index = parseInt(Math.random()*(a.length-1));
b.push(a[index]);
a.splice(index,1);
}
// console.log(b);
return b;
}
// console.log(a);
var random = shuffle();
for (var i=0;i<random.length;i++){
document.getElementById("fe").innerHTML +=random[i]
}
}
document.getElementById("bn").addEventListener("click",function () {
if (allNumber.value!=pfs.getElementsByTagName("li").length){
alert("请设置游戏人数");
}
else {
sessionStorage.setItem("player",pfs.textContent);
// sessionStorage.setItem("asd",cvl);
// window.sessionStorage.setItem("abc","123");
location.href = "js2-3.html";
}
})
//判断杀手和平民的人数
// if (time<8){
// s=1;
// p=time-s;
// }
// else if (time>7 && time<12){
// s=2;
// p=time-s;
//
// }
// else if (time>11 && time<18){
// s=4;
// p=time-s;
//
// }
// //杀手人数
//
// for(var i=0;i<=s;i++){
// var node=document.createTextNode("杀手1人");
// div.appendChild(node);
// div.setAttribute("class","color")
// var element= document.getElementById("fe");
// element.appendChild(div);
//
// }
// //平民人数
// for(var i=0;i<=p;i++){
// var node=document.createTextNode("杀手1人");
// div.appendChild(node);
// div.setAttribute("class","color")
// var element= document.getElementById("fe");
// element.appendChild(div);
// }
</script>
</body>
</html>