css+js实现图形问答小游戏代码
代码语言:html
所属分类:游戏
代码描述:css+js实现图形问答小游戏代码,根据文字提示选择正确的答案并点击。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link rel="canonical" href="https://codepen.io/Pedro-Ondiviela/pen/jORgbbK"> <style> @import url("https://fonts.googleapis.com/css2?family=Major+Mono+Display&display=swap"); @media (max-width: 767px) { html { font-size: 12px; } } body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; color: white; background: linear-gradient(60deg, #799df1, #60c1ec 30%, #7bd9de 60%, #cfb0d2 90%); background-size: 100% 100%; overflow: hidden; font-family: "Major Mono Display", monospace; } .game { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; padding: 1rem; color: #000038; } .game__wrapper { position: relative; width: 100%; height: 100%; max-width: 1400px; display: flex; flex-direction: column; justify-content: center; align-items: center; } .game__start { position: absolute; top: 0; left: 0; z-index: 9; display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; font-size: 35vh; background: linear-gradient(60deg, #799df1, #60c1ec 30%, #7bd9de 60%, #cfb0d2 90%); transition: transform 1s ease; cursor: pointer; } .game__start:after { content: ""; position: absolute; top: calc(50% - 10vh); left: calc(50% - 6.5vh); border-top: 13vh solid transparent; border-bottom: 13vh solid transparent; border-left: 20vh solid #000038; pointer-events: none; transition: transform 1s ease; } .game__start:hover { transform: scale(1.1); } .game__start:hover:after { transform: scale(1.2); } @media (max-width: 767px) { .game__start { font-size: 30vw; } .game__start:after { top: calc(50% - 10vw); left: calc(50% - 6.5vw); border-top: 13vw solid transparent; border-bottom: 13vw solid transparent; border-left: 20vw solid #000038; } } .game__logo { position: absolute; top: 1rem; left: 1rem; font-size: 1.5rem; color: white; } .game__title-wrapper { display: flex; justify-content: center; font-size: 3rem; } .game__title { color: white; text-transform: uppercase; text-align: center; padding: 1rem; } .game__pattern { display: flex; flex-direction: column; justify-content: center; align-items: center; font-size: 2rem; text-align: right; width: 12rem; padding: 1rem; } .game__pattern-text { width: 100%; margin-top: 1rem; line-height: 1.2; word-wrap: break-word; } .game__score { position: absolute; right: 1rem; bottom: 1rem; font-size: 2rem; color: white; } .tile { position: relative; display: flex; justify-content: center; align-items: center; width: 5rem; height: 5rem; margin: 0.5rem; font-size: 4rem; border-radius: 1rem; cursor: pointer; transition: all 0.3s ease; } .tile:hover { transform: scale(1.2) rotate(-10deg); z-index: 1; box-shadow: -0.2rem 0.5rem 0.5rem 0 rgba(0, 0, 56, 0.5); } </style> <script> window.console = window.console || function(t) {}; </script> </head> <body translate="no"> <div class="game__wrapper"> <div id="start" class="game__start"> <div>PATT<br />ERNS</div> </div> <div class="game__logo"> PATT<br /> ERNS </div> <div class="game__title-wrapper"> <div id="title" class="game__title"></div> </div> <div id="game" class="game"></div> <div id="score" class="game__score">0</div> </div> <script id="rendered-js" > const game = document.getElementById("game"); const start = document.getElementById("start"); const title = document.getElementById("title"); const scoreElement = document.getElementById("score"); let score = 0; let level = 0; let stage = 0; const prepareTile = id => { const tile = document.createElement("div"); tile.classList.add("tile"); tile.id = id; return tile; }; const basicBuildFunction = id => { const tile = prepareTile(id); tile.innerHTML = id; return tile; }; function shuffle(array) { let currentIndex = array.length; // While there remain elements to shuffle... while (currentIndex != 0) {if (window.CP.shouldStopExecution(0)) break; // Pick a remaining element... let randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; // And swap it with the current element. [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex]]; }window.CP.exitedLoop(0); } const firstLevel = [ { title: "Bigger", stages: [ { tiles: ["10", "20", "30", "40"], correct: "40" }, { tiles: ["35", "33", "36", "40"], correct: "40" }], buildFunction: id => { const tile = prepareTile(id); const px = document.createElement("div"); px.style = `background-color: #000038; width: ${id}px; height: ${id}px; pointer-events: none`; tile.appendChild(px); return tile; } }]; const levelList = [ { title: "Pure".........完整代码请登录后点击上方下载按钮下载查看
网友评论0