-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
692 lines (643 loc) · 15.6 KB
/
index.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Clouds.Hu_21点游戏</title>
<script>
function start() {
var buttonRemove = document.getElementById("buttonR1");
buttonRemove.remove();
}
var array1 = new Array();
var array2 = new Array();
var array3 = new Array();
var array4 = new Array();
//玩家牌面总点数
function playerSum(array1){
var sum=0;
for(i in array1){
sum+=(parseInt((array1[i]-1)/4)+1);
}
return sum;
}
function fapai() /*点击开始-系统每人分两张牌*/ {
/*玩家1发牌*/
for (var i = 0; i < 2; i++) {
var rand = parseInt(Math.random() * 100) % 52 + 1;
array1[i] = rand;
if (array1[i] == array1[i - 1]) {
i--;
continue;
} else {
var playerOne = document.getElementById("playerOne");
var li = document.createElement("li");
li.style.background = "url(img/" + rand + ".jpg)";
li.style.backgroundSize = "100%";
playerOne.appendChild(li);
}
}
/*玩家2发牌*/
var sum2 = 0;
var i = 0;
while (sum2 < 17) {
var rand = parseInt(Math.random() * 100) % 52 + 1;
var count = 0;
array2[i] = rand;
for (var k = 0; k < i + 1; k++) {
if (array2[i] == array2[k - 1]) {
continue;
} else {
for (var j = 0; j < 2; j++) {
if (array1[j] == array2[i]) {
break;
} else {
count++;
}
}
}
}
if (count >= 2 * array2.length) {
var playerTwo = document.getElementById("playerTwo");
var li = document.createElement("li");
li.style.background = "url(img/" + rand + ".jpg)";
li.style.backgroundSize = "100%";
playerTwo.appendChild(li);
sum2 += (parseInt((array2[i] - 1) / 4) + 1)
i++;
} else {
continue;
}
}
/*玩家3发牌*/
var sum3 = 0;
//发牌次数(数量)
var i = 0;
//while循环发牌并做判断(牌面不重复及牌面和大于17时停止发牌)
while (sum3 < 17) {
//随即生成一个数
var rand = parseInt(Math.random() * 100) % 52 + 1;
//当前牌面和已发牌面判断为不相等的次数
var count = 0;
//牌面存到数组内
array3[i] = rand;
//判断牌面是否相等,if和自己的牌面做判断,相等则更换牌
for (var k = 0; k < i + 1; k++) {
if (array3[i] == array3[k - 1]) {
continue;
//else和其他玩家的牌面比较
} else {
//用循环和玩家1和玩家2的牌做判断
for (var j = 0; j < array2.length; j++) {
//如果出现牌面一样则退出循环,更换牌
if (array1[j] == array3[i] || array2[j] == array3[i]) {
break;
//都不相等count计数
} else {
count++;
}
}
}
}
//如果判断过程每次都不相等则count=array2.length*array3.length
if (count >= array2.length * array3.length) {
var playerThree = document.getElementById("playerThree");
var li = document.createElement("li");
li.style.background = "url(img/" + rand + ".jpg)";
li.style.backgroundSize = "100%";
playerThree.appendChild(li);
sum3 += (parseInt((array3[i] - 1) / 4) + 1);
i++;
//有出现相等即count次数小于array2.length则换牌
} else {
continue;
}
}
/*玩家4发牌*/
var sum4 = 0;
var i = 0;
while (sum4 < 17) {
var rand = parseInt(Math.random() * 100) % 52 + 1;
var count = 0;
array4[i] = rand;
for (k = 0; k < i + 1; k++) {
if (array4[i] == array4[k - 1]) {
continue;
} else {
for (var j = 0; j < (array2.length + array3.length); j++) {
if (array1[j] == array4[i] || array2[j] == array4[i] || array3[j] == array4[i]) {
break;
} else {
count++;
}
}
}
}
if (count >= (array2.length + array3.length) * array4.length) {
var playerThree = document.getElementById("playerFour");
var li = document.createElement("li");
li.style.background = "url(img/" + rand + ".jpg)";
li.style.backgroundSize = "100%";
playerFour.appendChild(li);
sum4 += (parseInt((array4[i] - 1) / 4) + 1)
i++;
} else {
continue;
}
}
var buttonRemove = document.getElementById("buttonR2");
buttonRemove.remove();
//玩家2结果判断
if(playerSum(array3)>21){
document.getElementById("xs_div3_2").innerHTML="爆停";
}else{
document.getElementById("xs_div3_2").innerHTML="点数:"+playerSum(array3)+"";
}
if(playerSum(array2)>21){
document.getElementById("xs_div2_1").innerHTML="爆停";
}else{
document.getElementById("xs_div2_1").innerHTML="点数<br/>:<br/> "+playerSum(array2)+"";
}
if(playerSum(array4)>21){
document.getElementById("xs_div4_2").innerHTML="爆停";
}else{
document.getElementById("xs_div4_2").innerHTML="点数<br/>:<br/>"+playerSum(array4)+"";
}
document.getElementById("xs_div1_1").innerHTML="点数:"+playerSum(array1)+"";
}
//点击次数
var count2 = 0;
//要一张牌函数
function yaopai() {
//循环判断产生的牌跟之前的牌不重复
for (var i = 2 + count2; i < 3 + count2; i++) {
var rand = parseInt(Math.random() * 100) % 52 + 1;
array1[i] = rand;
if (array1[i] == array1[0] || array1[i] == array1[1]) {
i--;
continue;
} else {
//循环判断不相等次数
var count1 = 0;
//循环判断
for (var j = 1; j < i; j++) {
//如果相等
if (array1[i] == array1[j]) {
//退出
break;
//如果不相等
} else {
//循环判断不相等次数加1
count1++;
}
}
}
var maxlength = Math.max((array2.length), (array3.length), (array4.length));
/*alert(maxlength);*/
for (var k = 0; k < maxlength; k++) {
if (array1[i] == array2[k] || array1[i] == array3[k] || array1[i] == array4[k]) {
continue;
} else {
count1++;
}
}
//判断不相等次数如果大于等于i-1,则发牌
if (count1 >= i + maxlength - 1) {
var playerOne = document.getElementById("playerOne");
var li = document.createElement("li");
li.style.background = "url(img/" + rand + ".jpg)";
li.style.backgroundSize = "100%";
playerOne.appendChild(li);
//如果不相等次数小于i-1
} else {
//i自减1
i--;
//重新循环
continue;
}
}
count2++;
if(playerSum(array1)>21){
document.getElementById("xs_div1_1").innerHTML="爆停";
}else{
document.getElementById("xs_div1_1").innerHTML="点数:"+playerSum(array1)+"";
}
}
//玩家牌面总点数
/*function al() {
alert(array1);
alert(playerSum(array1));
alert(array2);
alert(playerSum(array2));
alert(array3);
alert(playerSum(array3));
alert(array4);
alert(playerSum(array4));
}*/
</script>
<style type="text/css">
/*javascript_style*/
#playerOne {
/*玩家1发牌*/
/*border: 1px solid red;*/
margin: 0px 90px 0px;
padding: 0px 0px 0px;
width: 140px;
height: 80px;
}
#playerOne li {
/*玩家1发牌*/
list-style-type: none;
float: left;
margin-left: -25px;
/*border: 1px solid yellow;*/
width: 49.41px;
height: 70.59px;
}
#yaopai li {
/*玩家1要牌*/
list-style-type: none;
float: left;
margin-left: -25px;
/*border: 1px solid yellow;*/
width: 49.41px;
height: 70.59px;
}
#playerTwo {
/*玩家2发牌*/
/*border: 1px solid red;*/
margin: 0px 35px 0px;
padding: 0px 0px 0px;
width: 80px;
height: 140px;
transform: rotate(180deg);
}
#playerTwo li {
/*玩家2发牌*/
list-style-type: none;
margin-top: -46px;
margin-left: 20px;
/*border: 1px solid yellow;*/
width: 49.41px;
height: 70.59px;
transform: rotate(90deg);
}
#playerThree {
/*玩家3发牌*/
/*border: 1px solid red;*/
margin: 0px 90px 0px;
padding: 0px 0px 0px;
width: 140px;
height: 80px;
transform: rotate(180deg);
}
#playerThree li {
/*玩家3发牌*/
list-style-type: none;
float: left;
margin-left: -25px;
/*border: 1px solid yellow;*/
width: 49.41px;
height: 70.59px;
}
#playerFour {
/*玩家4发牌*/
/*border: 1px solid red;*/
margin: 0px 30px 0px;
padding: 0px 0px 0px;
width: 80px;
height: 140px;
transform: rotate(0deg);
}
#playerFour li {
/*玩家4发牌*/
list-style-type: none;
margin-top: -47px;
margin-left: 20px;
/*border: 1px solid yellow;*/
width: 49.41px;
height: 70.59px;
transform: rotate(90deg);
}
</style>
<style type="text/css">
/*html_style*/
.big_div {
border: 8px solid #2d2115;
background-color: #3F1902;
position: relative;
width: 900px;
height: 640px;
margin: auto;
}
.s_div1 {
/*border: 2px solid white;*/
left: 50%;
margin-left: -230px;
position: absolute;
bottom: 0px;
width: 460px;
height: 210px;
}
#xs_div1_1 {
/*border: 1px solid black;*/
width: 100%;
height: 25px;
font-size: 40px;
font-weight: bolder;
color: red;
text-align: center;
}
.xs_div1_2 {
/*border: 1px solid black;*/
text-align: end;
width: 100%;
height: 30px;
}
.xs_div1_2 button {
height: 100%;
width: 50px;
background-color: darkcyan;
font-size: 16px;
font-weight: bolder;
color: greenyellow;
/*border: 1px solid green;*/
}
.xs_div1_3 {
/*border: 1px solid black;*/
width: 100%;
height: 150px;
}
.xs_div1_3 table {
border-spacing: 0px;
/*border: 2px solid black;*/
width: 100%;
height: 100%;
}
.xs_div1_3_table_td1 {
/*border: 2px solid black;*/
width: 140px;
height: 140px;
background: url(img/头像7.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
.xs_div1_3_table_td2 {
/*border: 2px solid black;*/
padding: 0px 0px 0px;
}
.s_div2 {
/*border: 2px solid white;*/
position: absolute;
right: 0px;
top: 50%;
margin-top: -230px;
width: 210px;
height: 460px;
}
#xs_div2_1 {
/*border: 1px solid black;*/
float: left;
width: 55px;
height: 99%;
font-size: 40px;
font-weight: bolder;
color: red;
text-align: center;
}
.xs_div2_2 {
/*border: 1px solid black;*/
width: 150px;
height: 99%;
float: left;
}
.xs_div2_2 table {
border-spacing: 0px;
/*border: 1px solid black;*/
width: 100%;
height: 100%;
}
.xs_div2_2_table_td1 {
/*border: 1px solid black;*/
padding: 0px 0px 0px;
}
.xs_div2_2_table_td2 {
/*border: 1px solid black;*/
width: 140px;
height: 140px;
background: url(img/头像6.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
.s_div3 {
/*border: 2px solid white;*/
position: absolute;
top: 0;
left: 50%;
margin-left: -230px;
width: 460px;
height: 210px;
}
.xs_div3_1 {
/*border: 1px solid black;*/
width: 100%;
height: 150px;
}
.xs_div3_1 table {
border-spacing: 0px;
/*border: 1px solid black;*/
width: 100%;
height: 100%;
}
.xs_div3_1_table_td1 {
/*border: 1px solid black;*/
padding: 0px 0px 0px;
}
.xs_div3_1_table_td2 {
/*border: 1px solid black;*/
width: 140px;
height: 140px;
background: url(img/头像5.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
#xs_div3_2 {
/*border: 1px solid black;*/
width: 100%;
height: 55px;
font-size: 40px;
font-weight: bolder;
color: red;
text-align: center;
}
.s_div4 {
/*border: 2px solid white;*/
position: absolute;
left: 0px;
top: 50%;
margin-top: -230px;
width: 210px;
height: 460px;
}
.xs_div4_1 {
/*border: 1px solid black;*/
width: 150px;
height: 99%;
float: left;
}
.xs_div4_1 table {
border-spacing: 0px;
/*border: 1px solid black;*/
width: 100%;
height: 100%;
}
.xs_div4_1_table_td1 {
/*border: 1px solid black;*/
width: 140px;
height: 140px;
background: url(img/头像3.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
.xs_div4_1_table_td2 {
padding: 0px 0px 0px;
/*border: 1px solid black;*/
}
#xs_div4_2 {
/*border: 1px solid black;*/
float: left;
width: 55px;
height: 99%;
font-size: 40px;
font-weight: bolder;
color: red;
text-align: center;
}
.s_div5 {
position: absolute;
width: 200px;
text-align: center;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
background: url(img/21图片1.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
.s_div5 button {
background-color: #ef8551;
position: absolute;
font-size: 80px;
font-weight: bolder;
color: white;
/*border: 2px solid darkgray;*/
margin-top: 75px;
width: 100%;
height: 100%;
top: -75px;
left: 0px;
}
.s_button {
position: absolute;
width: 200px;
text-align: center;
height: 200px;
font-size: 80px;
font-weight: bolder;
color: white;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
background-color: darkcyan;
z-index: 1;
}
</style>
</head>
<body style="background-color:#072853;">
<div class="big_div">
<div class="s_div1">
<!--玩家1-->
<div id="xs_div1_1"></div>
<div class="xs_div1_2">
<button onclick="yaopai()">要排</button>
<button onclick="al()">停牌</button>
</div>
<div class="xs_div1_3">
<table>
<tr>
<td class="xs_div1_3_table_td1"></td>
<td class="xs_div1_3_table_td2">
<!--玩家1发牌位置-->
<ul id="playerOne"></ul>
</td>
<!--玩家1发牌位置-->
</tr>
</table>
</div>
</div>
<!--玩家1-->
<div class="s_div2">
<!--玩家2-->
<div id="xs_div2_1"></div>
<div class="xs_div2_2">
<table>
<tr>
<td class="xs_div2_2_table_td1">
<!--玩家2发牌位置-->
<ul id="playerTwo"></ul>
</td>
<!--玩家2发牌位置-->
</tr>
<tr>
<td class="xs_div2_2_table_td2"></td>
</tr>
</table>
</div>
</div>
<!--玩家2-->
<div class="s_div3">
<!--玩家3-->
<div class="xs_div3_1">
<table>
<tr>
<td class="xs_div3_1_table_td1">
<!--玩家3派牌位置-->
<ul id="playerThree"></ul>
</td>
<!--玩家3派牌位置-->
<td class="xs_div3_1_table_td2"></td>
</tr>
</table>
</div>
<div id="xs_div3_2"></div>
</div>
<!--玩家3-->
<div class="s_div4">
<!--玩家4-->
<div class="xs_div4_1">
<table>
<tr>
<td class="xs_div4_1_table_td1"></td>
</tr>
<tr>
<td class="xs_div4_1_table_td2">
<!--玩家4派牌位置-->
<ul id="playerFour"></ul>
</td>
<!--玩家4派牌位置-->
</tr>
</table>
</div>
<div id="xs_div4_2"></div>
</div>
<!--玩家4-->
<button class="s_button" id="buttonR1" onclick="start()">开始游戏</button>
<div class="s_div5">
<button id="buttonR2" onclick="fapai()">发牌</button>
</div>
<!--中间背景和开始按钮-->
</div>
</body>
</html>