|
65 | 65 | left: 0; |
66 | 66 | top: 0; |
67 | 67 | } |
| 68 | + |
| 69 | + .chess-board .cb-over-box { |
| 70 | + display: flex; |
| 71 | + align-items: center; |
| 72 | + justify-content: center; |
| 73 | + flex-direction: column; |
| 74 | + position: absolute; |
| 75 | + left: 0; |
| 76 | + top: 0; |
| 77 | + bottom: 0; |
| 78 | + right: 0; |
| 79 | + background-color: rgba(255, 255, 255, .5); |
| 80 | + padding-bottom: 10vmin; |
| 81 | + } |
| 82 | + |
| 83 | + .chess-board .hidden { |
| 84 | + display: none; |
| 85 | + } |
| 86 | + |
| 87 | + .chess-board .over-title { |
| 88 | + font-size: 4vmin; |
| 89 | + font-weight: bold; |
| 90 | + color: #333; |
| 91 | + } |
| 92 | + |
| 93 | + .chess-board .over-subtitle { |
| 94 | + margin-top: 20px; |
| 95 | + font-size: 5vmin; |
| 96 | + font-weight: bold; |
| 97 | + color: goldenrod; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + .again-btn { |
| 102 | + margin-top: 100px; |
| 103 | + display: inline-flex; |
| 104 | + padding: 0 20px 3px; |
| 105 | + line-height: 40px; |
| 106 | + background: linear-gradient(to bottom, rgb(87, 196, 245), rgb(26, 147, 206)); |
| 107 | + color: rgb(254, 252, 255); |
| 108 | + cursor: pointer; |
| 109 | + border-radius: 4px; |
| 110 | + font-weight: bold; |
| 111 | + box-shadow: inset 0px -3px 0 rgb(19, 98, 139); |
| 112 | + } |
| 113 | + |
| 114 | + .again-btn:active { |
| 115 | + opacity: .7; |
| 116 | + box-shadow: inset 0px 0px 0 transparent; |
| 117 | + } |
68 | 118 | </style> |
69 | 119 | </head> |
70 | 120 |
|
71 | 121 | <body> |
72 | 122 |
|
73 | 123 | <div class="chess-board"> |
74 | 124 | <div class="cb-grid-box"></div> |
| 125 | + <div class="cb-over-box hidden"> |
| 126 | + <div class="over-title">游戏结束</div> |
| 127 | + <div class="over-subtitle"></div> |
| 128 | + <div class="again-btn">再来一局!</div> |
| 129 | + </div> |
75 | 130 | </div> |
76 | 131 |
|
77 | 132 | <script type="module"> |
|
156 | 211 | } |
157 | 212 |
|
158 | 213 | // 中国象棋棋盘 |
159 | | - let chessBoardGridBox = document.querySelector('.cb-grid-box') |
| 214 | + let chessBoardGridBox = document.querySelector('.cb-grid-box') // 格子盒子 |
| 215 | + let chessBoardOverBox = document.querySelector(".cb-over-box") // 结束盒子 |
160 | 216 | let chineseChessBoard = createFlatArray(9, 10, (x, y) => { |
161 | 217 | let grid = new Grid(x, y) |
162 | 218 | let dom = document.createElement('div') |
|
290 | 346 | } |
291 | 347 | } |
292 | 348 |
|
293 | | - loadChessManual(); |
294 | | - |
295 | 349 | /** |
296 | 350 | * 同一阵营 |
297 | 351 | * @author linyisonger |
|
625 | 679 | let nextOperateGrid = chineseChessBoard[y][x]; |
626 | 680 | let tempOperateChessPiece = chessManual[y][x]; |
627 | 681 |
|
| 682 | + |
628 | 683 | if (tempOperateChessPiece != null) { // 吃子 |
629 | 684 | console.log('吃子', tempOperateChessPiece); |
630 | 685 | nextOperateGrid.dom.querySelector('.chess-piece').remove() |
631 | | - |
| 686 | + if (tempOperateChessPiece.type == CHESS_PIECE_STANDARD.KING) { // 被吃掉的是将 |
| 687 | + chessBoardOverBox.querySelector('.over-subtitle').textContent = `🎉${currentOperateCamp}方获胜!` |
| 688 | + chessBoardOverBox.classList.remove('hidden') |
| 689 | + } |
632 | 690 | } |
633 | | - |
634 | 691 | nextOperateGrid.dom.appendChild(currentOperateGrid.dom.querySelector('.chess-piece')) |
635 | 692 | chessManual[y][x] = currentOperateChessPiece; |
636 | 693 | chessManual[currentOperateGrid.y][currentOperateGrid.x] = null; |
637 | 694 |
|
638 | 695 | currentOperateCamp = currentOperateCamp === CAMP_TYPE.RED ? CAMP_TYPE.BLACK : CAMP_TYPE.RED // 切换阵营 |
639 | 696 | } |
640 | 697 |
|
| 698 | + /** |
| 699 | + * 结束页面 |
| 700 | + * @author linyisonger |
| 701 | + * @date 2025-03-02 |
| 702 | + */ |
| 703 | + function loadOverPanel() { |
| 704 | + let againBtn = chessBoardOverBox.querySelector('.again-btn') |
| 705 | + againBtn.addEventListener('click', () => { |
| 706 | + location.reload() |
| 707 | + }) |
| 708 | + } |
| 709 | + |
| 710 | + |
| 711 | + |
| 712 | + loadChessManual(); |
| 713 | + loadOverPanel(); |
641 | 714 | </script> |
642 | 715 |
|
643 | 716 |
|
|
0 commit comments