-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpokertest.html
More file actions
128 lines (118 loc) · 3.94 KB
/
pokertest.html
File metadata and controls
128 lines (118 loc) · 3.94 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
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
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<title>德州撲克遊戲</title>
<style>
body { font-family: sans-serif; background: #1b1b1b; color: #fff; text-align: center; }
.table { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 20px; }
.player { width: 160px; margin: 10px; padding: 10px; background: #333; border-radius: 8px; }
.card { display: inline-block; width: 40px; height: 60px; margin: 2px; background: #fff; color: #000; border-radius: 6px; line-height: 60px; font-size: 18px; }
.community { margin: 20px 0; }
button, input { padding: 10px 20px; font-size: 16px; margin: 10px; }
.info { margin-top: 10px; font-size: 14px; }
</style>
</head>
<body>
<h1>♠ 德州撲克遊戲 ♣</h1>
<div class="community">
<h2>公共牌</h2>
<div id="communityCards"></div>
<div class="info">獎池:<span id="pot">0</span></div>
</div>
<div class="table" id="players"></div>
<div>
<input type="number" id="yourBet" value="50" min="10">
<button onclick="playerBet()">你下注</button>
<button onclick="nextStage()">下一階段</button>
<button onclick="startGame()">重新開始</button>
</div>
<script>
const suits = ['♠', '♥', '♦', '♣'];
const ranks = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'];
let deck = [], stage = 0, pot = 0;
const playerCount = 4;
let players = [], communityCards = [];
function shuffleDeck() {
deck = [];
for (let s of suits) for (let r of ranks) deck.push(r + s);
deck.sort(() => Math.random() - 0.5);
}
function startGame() {
shuffleDeck();
stage = 0;
pot = 0;
communityCards = [];
players = Array.from({length: playerCount}, (_, i) => ({
name: i === 0 ? '你' : `AI 玩家 ${i}`,
cards: [deck.pop(), deck.pop()],
chips: 1000,
bet: 0,
folded: false
}));
blindBet();
render();
}
function blindBet() {
players[1].bet = 10; players[1].chips -= 10;
players[2].bet = 20; players[2].chips -= 20;
pot = 30;
}
function playerBet() {
const amount = parseInt(document.getElementById('yourBet').value);
const p = players[0];
if (p.chips >= amount && !p.folded) {
p.chips -= amount;
p.bet += amount;
pot += amount;
render();
}
}
function aiBetting() {
for (let i = 1; i < players.length; i++) {
const p = players[i];
if (!p.folded) {
const amount = Math.floor(Math.random() * 50) + 10;
if (p.chips >= amount) {
p.chips -= amount;
p.bet += amount;
pot += amount;
} else {
p.folded = true;
}
}
}
}
function nextStage() {
if (stage === 0) communityCards = [deck.pop(), deck.pop(), deck.pop()];
else if (stage === 1) communityCards.push(deck.pop());
else if (stage === 2) communityCards.push(deck.pop());
else if (stage === 3) showdown();
if (stage < 3) aiBetting();
stage++;
render();
}
function showdown() {
let active = players.filter(p => !p.folded);
let winner = active[Math.floor(Math.random() * active.length)];
winner.chips += pot;
alert(`${winner.name} 贏得獎池 ${pot}!`);
pot = 0;
}
function render() {
document.getElementById('communityCards').innerHTML =
communityCards.map(c => `<div class="card">${c}</div>`).join('');
document.getElementById('pot').textContent = pot;
document.getElementById('players').innerHTML = players.map(p =>
`<div class="player">
<strong>${p.name}</strong><br>
${p.cards.map(c => `<div class="card">${c}</div>`).join('')}<br>
籌碼:${p.chips}<br>
${p.folded ? '<em>已棄牌</em>' : `下注:${p.bet}`}
</div>`
).join('');
}
startGame();
</script>
</body>
</html>