Skip to content

Commit e2e2a58

Browse files
author
linyisonger
committed
完善吃子列表
1 parent 5e21dd6 commit e2e2a58

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

092.中国象棋-暗棋模式.html

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
.chess-board {
1919
background-image: url('./assets/chess-piece/chessBoard.png');
2020
background-repeat: no-repeat;
21-
width: 100vmin;
22-
height: 100vmin;
21+
width: 90vmin;
22+
height: 90vmin;
2323
background-position: center;
2424
background-size: 90% 90%;
2525
position: relative;
@@ -104,6 +104,36 @@
104104
opacity: .7;
105105
box-shadow: inset 0px 0px 0 transparent;
106106
}
107+
108+
.chess-board .cb-eat-piece {
109+
position: absolute;
110+
left: 0vmin;
111+
top: -5vmin;
112+
width: 90vmin;
113+
height: 100vmin;
114+
pointer-events: none;
115+
}
116+
117+
.chess-board .cb-eat-piece .eat-piece-list:first-child {
118+
position: absolute;
119+
top: 2vmin;
120+
left: 4vmin;
121+
height: 5vmin;
122+
right: 4vmin;
123+
}
124+
125+
.chess-board .cb-eat-piece .eat-piece-list:last-child {
126+
position: absolute;
127+
bottom: 2vmin;
128+
left: 4vmin;
129+
height: 5vmin;
130+
right: 4vmin;
131+
}
132+
133+
.chess-board .cb-eat-piece .chess-piece {
134+
height: 100%;
135+
margin-right: 10px;
136+
}
107137
</style>
108138
</head>
109139

@@ -116,6 +146,10 @@
116146
<div class="over-subtitle"></div>
117147
<div class="again-btn">再来一局!</div>
118148
</div>
149+
<div class="cb-eat-piece">
150+
<div class="eat-piece-list"></div>
151+
<div class="eat-piece-list"></div>
152+
</div>
119153
</div>
120154

121155
<script type="module">
@@ -205,6 +239,7 @@
205239
// 中国象棋棋盘
206240
let chessBoardGridBox = document.querySelector('.cb-grid-box') // 格子盒子
207241
let chessBoardOverBox = document.querySelector(".cb-over-box") // 结束盒子
242+
let chessBoardEatBox = document.querySelector(".cb-eat-piece") // 吃子盒子
208243
let chineseChessBoard = createFlatArray(9, 10, (x, y) => {
209244
let grid = new Grid(x, y)
210245
let dom = document.createElement('div')
@@ -687,6 +722,7 @@
687722
tempOperateChessPiece = randomChessPiece()
688723
}
689724
console.log('吃子', tempOperateChessPiece);
725+
createEatenChessPiece(currentOperateCamp, tempOperateChessPiece) // 创建吃子列表
690726
nextChessPieceDom.remove()
691727
if (tempOperateChessPiece.type == CHESS_PIECE_STANDARD.KING) { // 被吃掉的是将
692728
chessBoardOverBox.querySelector('.over-subtitle').textContent = `🎉${currentOperateCamp}方获胜!`
@@ -741,6 +777,26 @@
741777
return dom.querySelector('.chess-piece').getAttribute('data-type') === CHESS_PIECE_DARK.DARK
742778
}
743779

780+
781+
/**
782+
* 创建被吃掉的棋子
783+
* @author linyisonger
784+
* @date 2025-03-03
785+
*
786+
* @param {string} camp
787+
* @param {ChessPiece} chessPiece
788+
*/
789+
function createEatenChessPiece(camp, chessPiece) {
790+
const selector = '.eat-piece-list' + (camp === CAMP_TYPE.BLACK ? ':first-child' : ':last-child');
791+
const container = chessBoardEatBox.querySelector(selector)
792+
793+
const dom = document.createElement('img');
794+
dom.classList.add('chess-piece')
795+
dom.setAttribute('src', `./assets/chess-piece/${chessPiece.type}-${chessPiece.camp}.png`)
796+
container.appendChild(dom)
797+
}
798+
799+
744800
loadChessManual();
745801
loadOverPanel();
746802
</script>

0 commit comments

Comments
 (0)