css+js实现国际益智类象棋游戏代码
代码语言:html
所属分类:游戏
代码描述:css+js实现国际益智类象棋游戏代码,使用标准的国际象棋走法,将黑色棋子移动到红色目标格。 黑兵在顶层行晋升。不允许吃子。尽量减少移动次数。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");
* {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
scroll-behavior: smooth;
touch-action: manipulation;
}
html,
body {
height: 100%;
overflow: hidden;
}
:root {
color-scheme: light dark;
--bg-light: #cecece;
--bg-dark: #333;
}
[data-theme="light"] {
color-scheme: light only;
}
[data-theme="dark"] {
color-scheme: dark only;
}
body {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
text-align: center;
margin: 0;
font-family: Poppins;
}
body,
.intro-screen,
.info-screen {
background: linear-gradient(#333, #171a21);
background: linear-gradient(
196deg,
light-dark(var(--bg-light), #3b434a),
light-dark(#aaa, #171a21)
);
}
[data-theme="light"] :is(body, .intro-screen, .info-screen) {
background: linear-gradient(196deg, var(--bg-light), #aaa);
}
[data-theme="dark"] :is(body, .intro-screen, .info-screen) {
background: linear-gradient(196deg, #3b434a, #171a21);
}
select,
input,
button {
font-family: Poppins;
border-radius: 6px;
padding: 4px 6px;
cursor: pointer;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
header {
position: absolute;
top: 0;
width: 100%;
z-index: 200;
display: flex;
align-items: center;
justify-content: space-between;
}
header .logo {
text-decoration: none;
color: light-dark(var(--bg-dark), var(--bg-light));
display: flex;
align-items: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
}
header .logo svg {
display: inline-block;
width: 42px;
height: 42px;
fill: light-dark(var(--bg-dark), var(--bg-light));
margin-right: -6px;
}
.mid-header {
gap: 12px;
display: none;
align-items: center;
}
@media screen and (max-width: 680px) {
.mid-header {
position: fixed;
top: unset;
bottom: 16px;
width: 100vw;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 24px;
}
.mid-header > :nth-child(n + 2) {
width: 30%;
}
.mid-header > :nth-child(-n + 2) {
width: 44%;
order: 1;
}
.mid-header > * {
width: fit-content;
}
.mid-header .btn:hover svg {
top: 2px;
}
}
#toggleColorScheme {
margin: 12px;
width: 24px;
height: 24px;
filter: grayscale(1);
cursor: pointer;
}
.intro-screen,
.info-screen {
position: absolute;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.intro-screen {
z-index: 100;
}
.intro-screen h2,
.info-screen h2 {
font-size: 2em;
margin-bottom: 0;
line-height: 100%;
text-shadow: 0 2px 3px #000;
}
.intro-screen p {
margin-top: 0;
}
.intro-screen p,
.info-screen p {
margin-bottom: 2em;
padding: 0 16px;
text-shadow: 0 2px 3px #000;
}
.intro-screen p a {
text-decoration: none;
color: inherit;
}
.intro-screen p a:hover {
text-decoration: underline;
}
.btn,
.btn-text,
.btn svg {
transition: all 0.2s ease-in-out;
}
.btn {
position: relative;
border: 1px solid #3333;
padding: 4px 16px;
border-radius: 4px;
background: light-dark(#292929, #bbbbbb);
color: light-dark(#fff, #292929);
box-shadow: 0 2px 2px 0 #3333, inset 2px 2px 2px 0 #fff3,
inset -2px -2px 2px 0 #0003;
cursor: pointer;
overflow: hidden;
white-space: nowrap;
}
.btn:hover {
border: 1px solid #3335;
box-shadow: 0 0 0 0 #3330;
translate: 0 2px;
}
.btn:hover .btn-text {
filter: blur(5px);
}
.btn svg {
width: 22px;
height: 22px;
position: absolute;
left: 0;
right: 0;
margin: auto;
top: 42px;
}
.btn:hover svg {
top: 4px;
}
.btn svg :is(path, polyline, line) {
stroke: light-dark(#fff, #292929);
stroke-width: 0.8px;
fill: #0000;
}
.btn.btn-right svg :is(path, polyline, line) {
stroke-width: 2px;
}
.btn svg circle {
fill: light-dark(#fff, #292929);
}
.btn.btn-rotate:hover svg {
animation: btn-rotate 1s ease-in-out forwards;
}
@keyframes btn-rotate {
0% {
rotate: 0deg;
}
100% {
rotate: -360deg;
}
}
.btn.btn-right:hover svg {
animation: btn-right 0.4s ease-in-out forwards;
}
@keyframes btn-right {
0% {
left: -124%;
}
100% {
left: 0;
}
}
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
padding: 4px 16px;
font-size: 0.9em;
line-height: 142%;
color: #333;
}
select:focus {
outline: none;
border-color: #a0bacf;
box-shadow: 0 0 5px rgba(191, 201, 209, 0.6);
}
.info-screen {
z-index: 99;
}
.info-screen h2 {
font-size: 2em;
margin-bottom: 0;
line-height: 100%;
}
.intro-screen > img {
position: absolute;
opacity: 0.1;
width: min(400px, 50vw);
pointer-events: none;
z-index: -1;
}
.level-clear {
position: absolute;
background: light-dark(#fffc, #000c);
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 101;
}
.lvl-clear-box {
background: light-dark(var(--bg-light), var(--bg-dark));
border: 1px solid light-dark(var(--bg-dark), var(--bg-light));
box-shadow: 0 4px 12px 0 #0004;
color: light-dark(var(--bg-dark), var(--bg-light));
}
.lvl-clear-box h2 {
padding: 16px;
border-bottom: 1px solid light-dark(var(--bg-dark), var(--bg-light));
padding-bottom: 12px;
margin-top: 0;
}
.lvl-clear-box p {
line-height: 100%;
padding: 0;
padding-bottom: 8px;
margin: 8px 0;
}
.lvl-clear-box span:not(.btn-text) {
font-weight: 1000;
font-size: 1.2em;
margin-right: 12px;
display: inline-block;
text-align: center;
}
.lvl-clear-box .next-lvl,
.lvl-clear-box .same-lvl {
background: light-dark(var(--bg-dark), var(--bg-light));
color: light-dark(var(--bg-light), var(--bg-dark));
width: fit-content;
margin: auto;
padding: 4px 16px;
margin-bottom: 24px;
cursor: pointer;
}
.lvl-clear-box .same-lvl {
scale: 0.8;
}
#scoreboard-container {
display: none;
position: absolute;
height: 100%;
width: 100%;
justify-content: center;
align-items: center;
z-index: 102;
background-color: #000a;
}
#scoreboard-container.show {
display: flex;
}
.scoreboard {
min-width: min(80vw, 242px);
max-width: calc(100% - 16px);
height: fit-content;
position: relative;
margin: auto;
background: light-dark(#fffc, #000c);
padding: 0 12px;
border: 1px solid light-dark(var(--bg-dark), var(--bg-light));
box-shadow: 0 4px 12px 0 #0004;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.scoreboard #close-score {
p.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0