<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [數(shù)字華容道] Html+css+js 實(shí)現(xiàn)小游戲

      [數(shù)字華容道] Html+css+js 實(shí)現(xiàn)小游戲

      效果圖

      代碼預(yù)覽

      在線(xiàn)預(yù)覽地址

      代碼示例

      <!DOCTYPE html>
      <html>
      	<head>
      		<meta charset="utf-8">
      		<title>數(shù)字華容道</title>
      		<style>
      			h1 {
      				text-align: center;
      			}
      
      			.box {
      				border: 1px solid #cfcfcf;
      				margin: 0 auto;
      				width: 322px;
      				padding: 20px;
      				border-radius: 20px;
      			}
      
      			.fun {
      				display: flex;
      				justify-content: space-between;
      			}
      
      
      			td {
      				width: 100px;
      				height: 100px;
      				text-align: center;
      				background-color: #f1c385;
      				user-select: none;
      			}
      
      			.current {
      				background-color: #fff !important;
      				transition: all .3s;
      			}
      
      			#error {
      				color: red;
      			}
      		</style>
      	</head>
      	<body>
      		<div class="box">
      			<h1>數(shù)字華容道</h1>
      			<p><strong>規(guī)則:</strong>移動(dòng)方塊依次出現(xiàn)1、2、3、4、5、6、7、8就可通關(guān)!不能對(duì)角線(xiàn)移動(dòng),不能跳格子移動(dòng)。只能相鄰上下或左右</p>
      			<hr />
      			<div class="fun">
      				<div><span>計(jì)次:</span><span id="num">0</span></div>
      				<div><span>提示:</span><span id="error"></span></div>
      				<div><span>功能:</span><button id="reset">重開(kāi)</button></div>
      			</div>
      			<hr />
      			<table border="1">
      				<tr>
      					<td>1</td>
      					<td>2</td>
      					<td>3</td>
      				</tr>
      				<tr>
      					<td>4</td>
      					<td>5</td>
      					<td>6</td>
      				</tr>
      				<tr>
      					<td>7</td>
      					<td>8</td>
      					<td class="current"></td>
      				</tr>
      			</table>
      		</div>
      		<script>
      			const step = document.getElementById('num');
      			const error = document.getElementById('error');
      			const seed = [1, 2, 3, 4, 5, 6, 7, 8];
      			// 隨機(jī)數(shù)組
      			const shuffle = (array) => {
      				for (let i = array.length - 1; i > 0; i--) {
      					const j = Math.floor(Math.random() * (i + 1));
      					[array[i], array[j]] = [array[j], array[i]];
      				}
      				return array;
      			}
      			// 檢查結(jié)果
      			const check = () => {
      				let flag = true;
      				const tds = document.querySelectorAll('td');
      				for (let i = 0; i < tds.length - 1; i++) {
      					let td = tds[i];
      					if (i + 1 !== parseInt(td.innerText)) {
      						flag = false;
      					}
      				}
      				if (flag) {
      					error.innerText = '恭喜你通關(guān)啦!??';
      				}
      			}
      			// 更新 td 數(shù)據(jù)
      			const init = () => {
      				const data = shuffle(seed);
      				const tds = document.querySelectorAll('td');
      				for (let i = 0; i < tds.length - 1; i++) {
      					let td = tds[i];
      					td.innerText = data[i];
      					td.className = ''
      				}
      				error.innerText = '';
      				step.innerText = 0;
      				tds[tds.length - 1].className = 'current'
      				tds[tds.length - 1].innerText = ''
      			}
      			init()
      			document.getElementById('reset').addEventListener('click',()=>{
      				init();
      			});
      			// 監(jiān)聽(tīng)點(diǎn)擊事件,移動(dòng)方塊處理
      			document.querySelector('table').addEventListener('click', (event) => {
      				const target = event.target;
      				const current = document.querySelector('.current');
      
      				const {
      					x: cx,
      					y: cy
      				} = current.getBoundingClientRect();
      				const {
      					x: tx,
      					y: ty
      				} = target.getBoundingClientRect();
      				const w = Math.abs(cx - tx);
      				const h = Math.abs(cy - ty);
      				if ((cx === tx || ty === cy) && (w < 200 && h < 200)) {
      					if (target.nodeName === 'TD' && target !== current) {
      						const innerText = target.innerText;
      						target.classList = 'current';
      						target.innerText = '';
      						// 當(dāng)前空白塊
      						current.innerText = innerText
      						current.classList.remove('current');
      						// 更新步驟
      						let num = step.innerText || 0;
      						num++;
      						step.innerText = num;
      						error.innerText = '';
      						check();
      					}
      				} else {
      					error.innerText = '不能這樣哦??';
      				}
      			})
      		</script>
      	</body>
      </html>
      
      posted @ 2024-03-14 10:04  天葬  閱讀(625)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 中文字幕第一页亚洲精品| 亚洲人成网线在线播放VA| 欧美日韩在线第一页免费观看| 最新偷拍一区二区三区| 国产精品综合在线免费看| 国产不卡在线一区二区| 疏勒县| 深夜福利成人免费在线观看| 亚欧洲乱码视频在线观看| aa性欧美老妇人牲交免费| 激情综合网激情综合网五月| 18禁无遮挡啪啪无码网站破解版| 国产精品疯狂输出jk草莓视频| 日韩中文字幕亚洲精品| 久久99精品久久久久久 | 亚洲另类激情专区小说图片| 蜜臀久久综合一本av| 亚洲欧美日韩成人综合一区| 国产精品电影久久久久电影网| 色综合网天天综合色中文| 最新精品国偷自产在线| 综合久久婷婷综合久久| 久久免费精品国自产拍网站| 一区二区三区四区自拍偷拍| 亚洲中文字幕无码中字| 久久热这里只有精品99| 麻豆精品久久久久久久99蜜桃| 91精品91久久久久久| 亚洲性日韩一区二区三区| 国产性色av高清在线观看| mm1313亚洲国产精品| 九九九国产| 国产最大的福利精品自拍| 在线高清免费不卡全码| 日韩有码精品中文字幕| 亚洲综合区激情国产精品| 在线看国产精品自拍内射| 一区二区三区四区国产综合| 国产精品自拍午夜福利| 久久丫精品国产| 欧美牲交a欧美牲交aⅴ图片|