Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
New Game
Moves
0
/
35
css
@import url("https://fonts.googleapis.com/css?family=Bubblegum+Sans"); /* colors */ .a, .a-x { background: #573659; } .b, .b-x { background: #ad4375; } .c, .c-x { background: #fa7370; } .d, .d-x { background: #f59231; } .e, .e-x { background: #fecd5f; } .f, .f-x { background: #9ccf5e; } .g, .g-x { background: #3cad5b; } .h, .h-x { background: #36cbbf; } .i, .i-x { background: #1d839c; } .j, .j-x { background: #2f506c; } body { margin: 0; height: 100vh; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; font-size: calc(1em + 1vmin); font-family: 'Bubblegum Sans', Helvetica, FontAwesome, sans-serif; background: #212429; color: #fffced; } .controls { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 1em 0; } #board { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-flow: row wrap; flex-flow: row wrap; height: 70vmin; width: 70vmin; border: 1ch solid; border-radius: .3em; } #board > * { -webkit-box-flex: 0; -ms-flex: 0 1 7vmin; flex: 0 1 7vmin; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; height: 7vmin; -webkit-transition: background 300ms linear; transition: background 300ms linear; } #board:not(.started) > *:first-of-type::after { content: '\f006'; } #colors { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; margin-top: 1ch; } #colors > * { -webkit-box-flex: 0; -ms-flex: 0 1 7vmin; flex: 0 1 7vmin; height: 7vmin; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; cursor: pointer; border-radius: .3em; } .new-game { pointer-events: auto; cursor: pointer; text-decoration: underline; color: #00bcd4; } #game-over { pointer-events: none; position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); font-size: 3em; }
JavaScript
((document) => { // parts of the game board let moves = document.querySelector('.moves') // ? let board = document.querySelector('#board') let colors = document.querySelector('#colors') let gameover = document.querySelector('#game-over') // control variables let colorArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] let running = false let cell = '-x' let skill = 5 let tally = 0 let cap = 35 let color // game play methods // ---------------------------- let shuffle = (collection) => { for (let i = collection.length; i; i--) { let j = Math.floor(Math.random() * i); [collection[i - 1], collection[j]] = [collection[j], collection[i - 1]] } return collection } let setColors = (collection, n) => { return n < 10 ? shuffle(collection).slice(0, n) : collection } let checkWin = (moves) => { let n = 0 let msg = '' if (moves <= cap) { if (board.childNodes[99].className.indexOf(cell) > -1) { for (var i = 0; i < 100; i++) { if (board.childNodes[i].className.indexOf(cell) > -1) { n++ } } } if (n === 100) { msg = '
You Win!
' running = false } else if (n < 100 && moves >= cap) { msg = '
Oops! Try Again...
' running = false } } if(!running) { gameover.innerHTML = msg } } let checkColor = (color) => { let tiles = board.childNodes for(var x = 0; x < 100; x++) { if(tiles[x].className.indexOf(cell) > -1) { tiles[x].className = color + cell if (x + 1 < 100 && tiles[x + 1].className === color) { tiles[x + 1].className += cell } if (x + 10 < 100 && tiles[x + 10].className === color) { tiles[x + 10].className += cell } if (x - 1 >= 0 && x % 10 > 0 && tiles[x - 1].className === color) { tiles[x - 1].className += cell } if (x - 10 >= 0 && x % 10 > 0 && tiles[x - 10].className === color) { tiles[x - 10].className += cell } } } } let builder = (container, element, collection, count, randomize) => { container.innerHTML = '' count = count || collection.length randomize = randomize || false for (let i = 0; i < count; i++) { let child = document.createElement(element) child.className = randomize ? collection[Math.floor((Math.random() * collection.length))] : collection[i] container.appendChild(child) } } let newGame = () => { let options = setColors(colorArray.slice(), skill) tally = 0 moves.innerText = tally //? gameover.innerHTML = '' running = true builder(colors, 'chip', options) builder(board, 'tile', options, 100, true) color = board.childNodes[0].className board.className = '' board.childNodes[0].className = color + cell checkColor(color) } let play = (chip) => { if (running && color !== chip){ color = chip if(board.className !== 'started') { board.className = 'started' } tally++ //? checkColor(chip) checkWin(tally) } } document.addEventListener("DOMContentLoaded", () => { newGame() }, false) document.addEventListener('click', (event) => { let css = Array.from(event.target.classList) if(event.target.tagName === 'CHIP') { play(event.target.className) } else if(css.includes('new-game')) { newGame() } }) })(document)
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>颜色匹配游戏-破碎-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号