js+css实现人机对战中国象棋游戏代码
代码语言:html
所属分类:游戏
代码描述:js+css实现人机对战中国象棋游戏代码
代码标签: js css 人机 对战 中国 象棋 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中国象棋 - 人机对战</title>
<style>
:root {
--bg: #f5e6d3;
--board-bg: #e8d5b7;
--border: #5d3a1a;
--text: #3e2723;
--highlight: #ffe082;
--selected: #ffab40;
--last-move: #c8e6c9;
--danger: #ff5252;
--button-bg: #6d4c41;
--button-hover: #5d3a1a;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #3e2723 0%, #5d4037 30%, #4e342e 60%, #3e2723 100%);
font-family: 'STSong', 'SimSun', 'KaiTi', 'Noto Serif SC', 'Songti SC', 'STSongti-SC', '华文宋体', '宋体', serif;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.game-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
padding: 25px;
background: #fdf5e6;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 8px #3e2723, 0 0 0 12px #8d6e63;
position: relative;
}
.game-title {
font-size: 32px;
font-weight: bold;
color: #4e342e;
letter-spacing: 6px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
margin-bottom: -5px;
}
.status-bar {
display: flex;
align-items: center;
gap: 15px;
background: #efebe9;
padding: 12px 24px;
border-radius: 30px;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
font-size: 18px;
font-weight: bold;
color: #4e342e;
min-width: 200px;
justify-content: center;
letter-spacing: 2px;
transition: all 0.3s ease;
}
.status-bar.check {
background: #ffebee;
color: #c62828;
animation: pulse 0.8s ease-in-out infinite;
}
.status-bar.win {
background: #e8f5e9;
color: #1b5e20;
}
@keyframes pulse {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
.status-indicator {
width: 14px;
height: 14px;
border-radius: 50%;
display: inline-block;
transition: all 0.3s ease;
}
.status-indicator.red-turn {
background: #d32f2f;
box-shadow: 0 0 12px rgba(211, 47, 47, 0.6);
}
.status-indicator.black-turn {
background: #212121;
box-shadow: 0 0 12px rgba(33, 33, 33, 0.6);
}
.canvas-wrapper {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
border: 4px solid #5d4037;
cursor: pointer;
transition: transform 0.2s ease;
}
.canvas-wrapper:active {
transform: scale(0.995);
}
canvas {
display: block;
background: #faf3e0;
}
.button-row {
display: flex;
gap: 15px;
flex-wrap: wrap;
justify-content: center;
}
.btn {
padding: 12px 28px;
font-size: 16px;
font-weight: bold;
letter-spacing: 2px;
border: none;
border-radius: 25px;
cursor: pointer;
transition: all 0.3s ease;
font-family: inherit;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
color: #fff;
}
.btn-restart {
background: #6d4c41;
}
.btn-restart:hover {
background: #4e342e;
transform: translateY(-2px);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.btn-undo {
background: #8d6e63;
}
.btn-undo:hover {
background: #6d4c41;
transform: translateY(-2px);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.btn:active {
transform: scale(0.95);
}
.btn:disabled {
background: #bcaaa4;
cursor: not-allowed;
transform: none;
box-shadow: none;
opacity: 0.6;
}
.info-text {
font-size: 13px;
color: #8d6e63;
letter-spacing: 1px;
text-align: center;
}
@media (max-width: 650px) {
.game-container {
padding: 15px;
gap: 12px;
border-radius: 14px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 0 4px #3e2723, 0 0 0 7px #8d6e63;
}
.game-title {
font-size: 24px;
letter-spacing: 4px;
}
.status-bar {
font-size: 15px;
padding: 10px 18px;
letter-spacing: 1px;
}
.btn {
padding: 10px 20px;
font-size: 14px;
letter-spacing: 1px;
}
canvas {
max-width: 100%;
height: auto;
}
}
</style>
</head>
<body>
<div class="game-container">
<div class="game-title">🏮 中 国 象 棋 🏮</div>
<div class="status-bar" id="statusBa.........完整代码请登录后点击上方下载按钮下载查看















网友评论0