-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathteam_4.html
More file actions
62 lines (57 loc) · 1.45 KB
/
team_4.html
File metadata and controls
62 lines (57 loc) · 1.45 KB
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
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript">
var suits=["黑桃", "紅心", "方塊", "梅花"];
var cards = new Array(52);
for(var i=0; i<52; ++i) cards[i]=i;
var Users=["User 1","User 2","User 3","User 4"];
Shuffle();
BlackJack( Math.floor((Math.random() * 52)) );
/* start blackjack, deal the cards from Num */
function BlackJack(Num){
for(var user in Users){
if(Num>50) Num=0;
var Point1=cards[Num]%13+1, Point2=cards[Num+1]%13+1;
if(Point1>10) Point1=10;
if(Point2>10) Point2=10;
if(Point1==1 && Point2+11<22) Point1=11;
if(Point2==1 && Point2+11<22) Point2=11;
console.log(
Users[user]+": ["+
Turn(cards[Num])+", "+
Turn(cards[Num+1])+"] "+
(Point1+Point2)+"點"
);
Num+=2;
}
}
/* return the chinese name of the card */
function Turn(n){
var j= n % 13 +1;
if(j==1) j='A';
else if(j==11) j ='J';
else if(j==12) j ='Q';
else if(j==13) j ='K';
return suits[Math.floor(n/13)]+j;
}
/* shuffle the cards!! */
function Shuffle(){
for(var i=0; i<52; ++i){
var ranA=Math.floor((Math.random() * 52));
var ranB=Math.floor((Math.random() * 52));
var tmp=cards[ranA];
cards[ranA]=cards[ranB];
cards[ranB]=tmp;
}
}
</script>
</body>
</html>