-
Notifications
You must be signed in to change notification settings - Fork 17
/
team_1.html
93 lines (85 loc) · 2.79 KB
/
team_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
<!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">
Gamestart();
function Gamestart(){
gameData = setNewGame(4,2);
showPlayerInfo_testStyle(gameData);
}
function setNewGame(playerNum, initCardsNum){
var players = new Array();
var ready_cards = generateNewCardDeck(100);
for(var i0 = 0; i0 < playerNum; i0++){
players.push({name: i0+1,
cards: drawFromCards(ready_cards, initCardsNum)
});
}
return {players:players};
}
function showPlayerInfo_testStyle(gameData){
if(gameData.players.length > 0)
for(var i0 = 0; i0 < gameData.players.length; i0++){
var cardsinfo = getCardInfo_String(gameData.players[i0].cards[0]),
bjTotal = getBlackJackNumber(gameData.players[i0].cards[0]);
for(var i1 = 1; i1 < gameData.players[i0].cards.length; i1++){
cardsinfo += ", " + getCardInfo_String(gameData.players[i0].cards[i1]);
bjTotal += getBlackJackNumber(gameData.players[i0].cards[i1]);
}
console.log("User "+gameData.players[i0].name+": ["+cardsinfo+"] "+bjTotal+"點");
}
}
function getCardInfo_String(card){
return (card["color"] == "p" ? "黑桃" :
card["color"] == "f" ? "菱形" :
card["color"] == "h" ? "紅心" :
card["color"] == "s" ? "梅花" : "none")
+" "+
(card["num"] == 11 ? 'J' :
card["num"] == 12 ? 'Q' :
card["num"] == 13 ? 'K' :
card["num"] == 1 ? 'A' : card["num"])
;
}
function getBlackJackNumber(card){
return (card["num"] == 1 ? 11 :
card["num"] > 10 ? 10 : card["num"]);
}
function generateNewCardDeck(washTimes){
var POKECHINESS = ["p","f","h","s"];
var newPokeAll = new Array();
for(var i0 = 1; i0 <= 13; i0++)
for(var i1 = 0; i1 < 4; i1++)
newPokeAll.push(newCard(i0, POKECHINESS[i1]));
return washCards(newPokeAll, washTimes);
}
function newCard(num, color){
return {"num":num, "color":color};
}
function washCards(cards, washTimes){
for(var i0 = 0, cardTemp, len = cards.length; i0 < washTimes; i0++){
var choosed = Math.round(Math.random() * (len - 1) ) ;
cardTemp = cards[0];
cards[0] = cards[choosed];
cards[choosed] = cardTemp;
}
return cards;
}
function drawFromCards(cards, times){
if(cards.length < times)
return false;
var temp_card = new Array();
for(var i0 = 0; i0 < times; i0++)
temp_card.push(cards.shift());
return temp_card;
}
</script>
</body>
</html>