js+css实现逼真的石头剪刀布游戏代码
代码语言:html
所属分类:游戏
代码描述:js+css实现逼真的石头剪刀布游戏代码,规则:你与电脑对战,电脑会随机选择石头、剪刀或布。 每场比赛开始时,你的手势会被随机设定。 点击指纹来伸展或收回相应的指头。 排列手指以形成石头、剪刀或布。 你有有限的时间来做出选择。 当你输掉比赛或展示无效手势时,你的分数会重置。 你的分数越高,你做出选择的时间就越少。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { background-color: black; height: 100vh; margin: 0; display: flex; flex-direction: column; color: white; font-family: Arial; position: relative; } .handWrapper { flex: 1; display: flex; justify-content: center; } .hand { aspect-ratio: 0.8; background-image: url(//repo.bfw.wiki/bfwrepo/images/hand/combined.png); background-size: auto 3200%; position: relative; height: 100%; } #opponent .hand { transform: rotate(180deg); } .fingerprint { display: none; background-image: url("//repo.bfw.wiki/bfwrepo/images/hand/fingerprint.png"); aspect-ratio: 1; width: 10%; position: absolute; filter: invert(1); background-size: contain; opacity: 0.7; cursor: pointer; } .fingerprint#thumb { top: 41%; left: 81%; } .fingerprint#index { top: 10%; left: 57%; } .fingerprint#middle { top: 5%; left: 44%; } .fingerprint#ring { top: 9%; left: 31%; } .fingerprint#pinky { top: 19%; left: 13%; } [data-state=Playing] .fingerprint { display: block; } #timer { display: none; position: absolute; top: 0; right: 0; margin: 22px; width: 80px; height: 80px; transform: rotate(-90deg); } [data-state=Playing] #timer { display: block; } [data-state=Playing] #timer circle { stroke-dasharray: 226px; stroke-dashoffset: 0px; stroke-width: 8px; stroke: white; fill: none; animation-name: countdown; animation-timing-function: linear; animation-fill-mode: forwards; } @keyframes countdown { from { stroke-dashoffset: 0px; } to { stroke-dashoffset: 226px; } } #result { text-align: center; justify-content: center; flex-direction: column; display: none; font-size: 64px; line-height: 64px; width: 80vw; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } #result > div { display: none; } [data-state=Done] #result { display: flex; } [data-result=Win] #result #win { display: block; } [data-result=Lose] #result #lose { display: block; } [data-result=Draw] #result #draw { display: block; } [data-result=Invalid] #result #invalid { display: block; } input { padding: 10px 15px; border: 0; background-color: white; color: black; border-radius: 10px; font-size: 16px; cursor: pointer; } #restart { margin-left: auto; margin-right: auto; margin-top: 25px; } #score { position: absolute; top: 0; left: 0; margin: 15px; width: 70px; height: 70px; display: flex; flex-direction: column; align-items: center; border: 1px solid white; border-radius: 10px; padding: 10px; justify-content: space-between; font-size: 22px; } #scoreCount { font-size: 42px; } #rules { position: absolute; bottom: 0; left: 0; margin: 15px; } #modalWrapper { display: none; cursor: pointer; } #modalWrapper::before { content: ""; position: absolute; top: 0; left: 0; height: 100vh; width: 100vw; background-color: black; opacity: 0.5; } #modalWrapper.visible { display: block; } #rulesModal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background-color: white; color: black; width: 80vw; border-radius: 10px; padding: 15px; line-height: 24px; } #rulesModal h1 { text-align: center; margin: 0; } #rulesModal p { text-align: center; margin-top: 6px; font-size: 15px; } #rulesModal ul { margin: 0; padding-left: 20px; } </style> </head> <body translate="no"> <div class="handWrapper" id="opponent"> <div class="hand"></div> </div> <div class="handWrapper" id="player"> <div class="hand"> <div class="fingerprint" id="thumb"></div> <div class="fingerprint" id="index"></div> <div class="fingerprint" id="middle"></div> <div class="fingerprint" id="ring"></div> <div class="fingerprint" id="pinky"></div> </div> </div> <svg id="timer"> <circle r="36" cx="40" cy="40"></circle> </svg> <div id="result"> <div id="win">你赢了</div> <div id="lose">你输了</div> <div i.........完整代码请登录后点击上方下载按钮下载查看
网友评论0