原生js+css实现4人麻将游戏代码
代码语言:html
所属分类:游戏
代码描述:原生js+css实现4人麻将游戏代码
下面为部分代码预览,完整代码请点击下载或在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 {
--table-bg: #0a4d2e;
--table-felt: #136d42;
--tile-face: #fdfdf0;
--tile-back: #2a7fff;
--tile-side: #e0e0d5;
--shadow: rgba(0,0,0,0.4);
}
* {
box-sizing: border-box;
user-select: none;
}
body {
margin: 0;
overflow: hidden;
background: #222;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
/* 麻将桌 */
#table {
width: 100vw;
height: 100vh;
background: radial-gradient(circle, var(--table-felt) 0%, var(--table-bg) 90%);
position: relative;
display: grid;
grid-template-rows: 120px 1fr 160px;
grid-template-columns: 120px 1fr 120px;
box-shadow: inset 0 0 100px rgba(0,0,0,0.8);
}
/* 中间区域 (出牌区 & 信息) */
#center-area {
grid-row: 2;
grid-column: 2;
border: 2px solid rgba(0,0,0,0.1);
border-radius: 20px;
background: rgba(0,0,0,0.1);
position: relative;
display: grid;
grid-template-rows: 1fr 1fr;
grid-template-columns: 1fr 1fr;
padding: 20px;
gap: 10px;
}
.discard-zone {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
gap: 2px;
padding: 5px;
}
/* 各家出牌区定位 */
#discard-top { grid-area: 1 / 1 / 2 / 3; justify-content: center; transform: rotate(180deg); }
#discard-left { grid-area: 1 / 1 / 3 / 2; flex-direction: column; justify-content: center; align-items: flex-end; margin-right: 40px;}
#discard-right { grid-area: 1 / 2 / 3 / 3; flex-direction: column; justify-content: center; align-items: flex-start; margin-left: 40px;}
#discard-bottom { grid-area: 2 / 1 / 3 / 3; justify-content: center; align-items: flex-end; }
/* 调整左右出牌区位置以适应正方形布局 */
#discard-left { position: absolute; left: 20px; top: 20%; bottom: 20%; width: 60px; }
#discard-right { position: absolute; right: 20px; top: 20%; bottom: 20%; width: 60px; }
#discard-top { position: absolute; top: 20px; left: 20%; right: 20%; height: 60px; }
#discard-bottom { position: absolute; bottom: 20px; left: 20%; right: 20%; height: 60px; }
/* 信息中心 */
#info-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0,0,0,0.5);
color: white;
padding: 10px 20px;
border-radius: 8px;
text-align: center;
pointer-events: none;
z-index: 10;
backdrop-filter: blur(4px);
}
/* 手牌区域 */
.hand {
position: relative;
display: flex;
justify-content: center;
align-items: center;
gap: 2px;
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0