|
18 | 18 | .chess-board { |
19 | 19 | background-image: url('./assets/chess-piece/chessBoard.png'); |
20 | 20 | background-repeat: no-repeat; |
21 | | - width: 100vmin; |
22 | | - height: 100vmin; |
| 21 | + width: 90vmin; |
| 22 | + height: 90vmin; |
23 | 23 | background-position: center; |
24 | 24 | background-size: 90% 90%; |
25 | 25 | position: relative; |
|
104 | 104 | opacity: .7; |
105 | 105 | box-shadow: inset 0px 0px 0 transparent; |
106 | 106 | } |
| 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 | + } |
107 | 137 | </style> |
108 | 138 | </head> |
109 | 139 |
|
|
116 | 146 | <div class="over-subtitle"></div> |
117 | 147 | <div class="again-btn">再来一局!</div> |
118 | 148 | </div> |
| 149 | + <div class="cb-eat-piece"> |
| 150 | + <div class="eat-piece-list"></div> |
| 151 | + <div class="eat-piece-list"></div> |
| 152 | + </div> |
119 | 153 | </div> |
120 | 154 |
|
121 | 155 | <script type="module"> |
|
205 | 239 | // 中国象棋棋盘 |
206 | 240 | let chessBoardGridBox = document.querySelector('.cb-grid-box') // 格子盒子 |
207 | 241 | let chessBoardOverBox = document.querySelector(".cb-over-box") // 结束盒子 |
| 242 | + let chessBoardEatBox = document.querySelector(".cb-eat-piece") // 吃子盒子 |
208 | 243 | let chineseChessBoard = createFlatArray(9, 10, (x, y) => { |
209 | 244 | let grid = new Grid(x, y) |
210 | 245 | let dom = document.createElement('div') |
|
687 | 722 | tempOperateChessPiece = randomChessPiece() |
688 | 723 | } |
689 | 724 | console.log('吃子', tempOperateChessPiece); |
| 725 | + createEatenChessPiece(currentOperateCamp, tempOperateChessPiece) // 创建吃子列表 |
690 | 726 | nextChessPieceDom.remove() |
691 | 727 | if (tempOperateChessPiece.type == CHESS_PIECE_STANDARD.KING) { // 被吃掉的是将 |
692 | 728 | chessBoardOverBox.querySelector('.over-subtitle').textContent = `🎉${currentOperateCamp}方获胜!` |
|
741 | 777 | return dom.querySelector('.chess-piece').getAttribute('data-type') === CHESS_PIECE_DARK.DARK |
742 | 778 | } |
743 | 779 |
|
| 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 | + |
744 | 800 | loadChessManual(); |
745 | 801 | loadOverPanel(); |
746 | 802 | </script> |
|
0 commit comments