Skip to content

Commit bed81c3

Browse files
author
linyisonger
committed
标准版
1 parent 1335c52 commit bed81c3

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

091.中国象棋.html

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,68 @@
6565
left: 0;
6666
top: 0;
6767
}
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+
}
68118
</style>
69119
</head>
70120

71121
<body>
72122

73123
<div class="chess-board">
74124
<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>
75130
</div>
76131

77132
<script type="module">
@@ -156,7 +211,8 @@
156211
}
157212

158213
// 中国象棋棋盘
159-
let chessBoardGridBox = document.querySelector('.cb-grid-box')
214+
let chessBoardGridBox = document.querySelector('.cb-grid-box') // 格子盒子
215+
let chessBoardOverBox = document.querySelector(".cb-over-box") // 结束盒子
160216
let chineseChessBoard = createFlatArray(9, 10, (x, y) => {
161217
let grid = new Grid(x, y)
162218
let dom = document.createElement('div')
@@ -290,8 +346,6 @@
290346
}
291347
}
292348

293-
loadChessManual();
294-
295349
/**
296350
* 同一阵营
297351
* @author linyisonger
@@ -625,19 +679,38 @@
625679
let nextOperateGrid = chineseChessBoard[y][x];
626680
let tempOperateChessPiece = chessManual[y][x];
627681

682+
628683
if (tempOperateChessPiece != null) { // 吃子
629684
console.log('吃子', tempOperateChessPiece);
630685
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+
}
632690
}
633-
634691
nextOperateGrid.dom.appendChild(currentOperateGrid.dom.querySelector('.chess-piece'))
635692
chessManual[y][x] = currentOperateChessPiece;
636693
chessManual[currentOperateGrid.y][currentOperateGrid.x] = null;
637694

638695
currentOperateCamp = currentOperateCamp === CAMP_TYPE.RED ? CAMP_TYPE.BLACK : CAMP_TYPE.RED // 切换阵营
639696
}
640697

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();
641714
</script>
642715

643716

0 commit comments

Comments
 (0)