Skip to content

Commit 6d32956

Browse files
committed
debug
1 parent c7f1c79 commit 6d32956

File tree

1 file changed

+69
-6
lines changed

1 file changed

+69
-6
lines changed

32-24 Point Poker Game/index.html

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
<button onclick="drawCards()">抽牌</button>
4444
<button onclick="cal()" style="display: none;">算牌</button>
4545
<button onclick="showResult(true)">显示结果</button>
46+
<!-- 显示四个按钮,代表四则运算,点击后赋值selectedMethord 0:+,1:-,2:*,3:/-->
47+
<button onclick="selectedMethord(0)">+</button>
48+
<button onclick="selectedMethod(1)">-</button>
49+
<button onclick="selectedMethod(2)">*</button>
50+
<button onclick="selectedMethod(3)">/</button>
4651

4752
</div>
4853

@@ -60,7 +65,19 @@
6065
const suits = ['♠', '♥', '♣', '♦'];
6166
const values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
6267
const deck = [];
63-
68+
const method = ['+', '-', '*', '/'];
69+
70+
function selectedMethod(i) {
71+
selMethord = i;
72+
if(selectedCards.length == 2){
73+
var cd = calc(cardToNumber(selectedCards[0]), selMethord, cardToNumber(selectedCards[1]));
74+
document.getElementById(`card${selectedCards[0]}`).display = "none";
75+
document.getElementById(`card${selectedCards[1]}`).display = "none";
76+
selectedCards = [];
77+
selMethord = -1;
78+
addCard(cd+" ", "#007f0e",cards.length);
79+
}
80+
}
6481
// 创建扑克牌数组
6582
for (let suit of suits) {
6683
for (let value of values) {
@@ -88,23 +105,48 @@
88105
// 显示抽出的牌
89106
const cardContainer = document.getElementById('cardContainer');
90107
cardContainer.innerHTML = ''; // 清空容器
91-
108+
var index = 0;
92109
drawnCards.forEach(card => {
93110
const color = getColorForSuit(card.slice(-1)); // 根据花色获取颜色
94111
// 使用SVG绘制圆角矩形并显示牌
95-
const svg = `
112+
addCard(card, color,index);
113+
index++;
114+
115+
});
116+
cards = drawnCards;
117+
cal();
118+
}
119+
var selectedCards = [];
120+
function clcikCard(index){
121+
if(selectedCards.length <2){
122+
selectedCards.push(index);
123+
document.getElementById(`card${index}`).style.border = "2px solid blue";
124+
}else if(selectedCards.length == 2){
125+
if(selMethord != -1){
126+
var cd = calc(cardToNumber(selectedCards[0]), selMethord, cardToNumber(selectedCards[1]));
127+
document.getElementById(`card${selectedCards[0]}`).display = "none";
128+
document.getElementById(`card${selectedCards[1]}`).display = "none";
129+
selMethord = -1;
130+
addCard(cd+" ", "#007f0e",cards.length);
131+
}
132+
document.getElementById(`card${selectedCards[0]}`).style.border = "";
133+
document.getElementById(`card${selectedCards[1]}`).style.border = "";
134+
selectedCards = [];
135+
}
136+
}
137+
function addCard(card, color,index) {
138+
const svg = `
96139
<svg width="100" height="150">
97140
<rect width="100" height="150" rx="15" ry="15" style="fill:#f0f0f0;stroke:${color};stroke-width:2" />
98141
<text x="50%" y="50%" alignment-baseline="middle" fill="${color}" text-anchor="middle" font-size="24" font-weight="bold">${card}</text>
99142
</svg>
100143
`;
101144
const div = document.createElement('div');
102145
div.className = 'card';
146+
div.id = `card${index}`;
147+
div.setAttribute('onclick', `clcikCard(${index})`);
103148
div.innerHTML = svg;
104149
cardContainer.appendChild(div);
105-
});
106-
cards = drawnCards;
107-
cal();
108150
}
109151
function getColorForSuit(suit) {
110152
switch (suit) {
@@ -198,6 +240,27 @@
198240
document.getElementById("inputs").innerHTML = str1 + "<br>";
199241
// display the inputs
200242
}
243+
function calc(num1, op1, num2) {
244+
var num3 = 0.0;
245+
switch (op1) {
246+
case 0:
247+
num3 = num1 + num2;
248+
break;
249+
case 1:
250+
num3 = num1 - num2;
251+
break;
252+
case 2:
253+
num3 = num1 * num2;
254+
break;
255+
case 3:
256+
num3 = num1 / num2;
257+
break;
258+
}
259+
if (Math.abs(num3 - Math.round(num3)) < ep)
260+
return (Math.round(num3));
261+
else
262+
return (num3);
263+
}
201264
</script>
202265
</body>
203266

0 commit comments

Comments
 (0)