当前位置: 首页 > wzjs >正文

媒体网站推广方法阿里云免费域名

媒体网站推广方法,阿里云免费域名,宁夏建设工程质量监督站网站,专业制作网站服务公司实现效果 使用方向键移动&#xff0c;将橙色箱子推到绿色目标区域&#xff08;黑色块为墙&#xff0c;白色块为可通过区域&#xff0c;蓝球为小人&#xff09; 实现过程 <!DOCTYPE html> <html> <head><title>推箱子小游戏</title><style&g…

实现效果

使用方向键移动,将橙色箱子推到绿色目标区域(黑色块为墙,白色块为可通过区域,蓝球为小人)

实现过程

<!DOCTYPE html>
<html>
<head><title>推箱子小游戏</title><style>.game-container {display: grid;grid-template-columns: repeat(8, 50px);gap: 2px;background: #333;padding: 10px;}.cell {width: 50px;height: 50px;background: #eee;display: flex;align-items: center;justify-content: center;font-size: 24px;}.wall {background: #444;}.box {background: #ff9900;border-radius: 5px;}.player {background: #2196F3;border-radius: 50%;width: 35px;height: 35px;}.target {background: #4CAF50;}.box-on-target {background: #8BC34A;}</style>
</head>
<body><div class="game-container" id="game"></div><p>使用方向键移动,将橙色箱子推到绿色目标区域(黑色块为墙,白色块为可通过区域,蓝球为小人)</p><script>// 关卡配置const level = [[1, 1, 1, 1, 1, 1, 1, 1],[1, 0, 0, 0, 0, 0, 0, 1],[1, 0, 2, 3, 0, 2, 0, 1],[1, 0, 1, 3, 4, 1, 0, 1],[1, 0, 2, 0, 3, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 1],[1, 1, 1, 1, 1, 1, 1, 1]];let playerPosition = { x: 4, y: 3 };let boxes = [];const gameContainer = document.getElementById('game');// 初始化游戏function initGame() {gameContainer.innerHTML = '';boxes = [];level.forEach((row, y) => {row.forEach((cell, x) => {const cellElement = document.createElement('div');cellElement.className = 'cell';switch(cell) {case 1: cellElement.classList.add('wall');break;case 2:cellElement.classList.add('target');break;case 3:boxes.push({ x, y });cellElement.classList.add('box');break;case 4:playerPosition = { x, y };break;}gameContainer.appendChild(cellElement);});});updatePlayerPosition();}// 更新玩家位置function updatePlayerPosition() {document.querySelectorAll('.cell').forEach(cell => {cell.classList.remove('player');});const index = playerPosition.y * 8 + playerPosition.x;gameContainer.children[index].classList.add('player');}// 移动检测function canMove(dx, dy) {const newX = playerPosition.x + dx;const newY = playerPosition.y + dy;// 边界检测if (newX < 0 || newX >= 8 || newY < 0 || newY >= 7) return false;// 获取目标位置的单元格const targetCell = level[newY][newX];const targetIndex = newY * 8 + newX;const targetElement = gameContainer.children[targetIndex];// 如果是墙if (targetCell === 1) return false;// 检查是否有箱子const boxIndex = boxes.findIndex(b => b.x === newX && b.y === newY);if (boxIndex > -1) {// 检查箱子后面的位置const boxNewX = newX + dx;const boxNewY = newY + dy;if (boxNewX < 0 || boxNewX >= 8 || boxNewY < 0 || boxNewY >= 7) return false;const nextCell = level[boxNewY][boxNewX];const nextIndex = boxNewY * 8 + boxNewX;const nextElement = gameContainer.children[nextIndex];// 检查箱子后面的位置是否可移动if (nextCell === 1 || boxes.some(b => b.x === boxNewX && b.y === boxNewY)) {return false;}// 移动箱子boxes[boxIndex].x = boxNewX;boxes[boxIndex].y = boxNewY;// 更新箱子显示targetElement.classList.remove('box');nextElement.classList.toggle('box', true);nextElement.classList.toggle('box-on-target', nextElement.classList.contains('target'));}return true;}// 处理键盘事件document.addEventListener('keydown', (e) => {let dx = 0, dy = 0;switch(e.key) {case 'ArrowUp': dy = -1; break;case 'ArrowDown': dy = 1; break;case 'ArrowLeft': dx = -1; break;case 'ArrowRight': dx = 1; break;default: return;}if (canMove(dx, dy)) {playerPosition.x += dx;playerPosition.y += dy;updatePlayerPosition();checkWin();}});// 胜利检测function checkWin() {const allBoxesOnTarget = boxes.every(box => {const index = box.y * 8 + box.x;return gameContainer.children[index].classList.contains('target');});if (allBoxesOnTarget) {setTimeout(() => alert('恭喜过关!'), 100);}}// 启动游戏initGame();</script>
</body>
</html>

http://www.dtcms.com/wzjs/388956.html

相关文章:

  • 西安做网站选哪家重庆今天刚刚发生的重大新闻
  • 五台建设局网站软文案例200字
  • 网站制作分工手机制作网页用什么软件
  • 网站用的服务器广告发布平台
  • 浙江正规网站建设配件如何注册网站
  • 新手站长如何购买虚拟主机做网站今天新疆新闻头条
  • idea建设完整的网站杭州做seo的公司
  • 烟台专业网站建设公司班级优化大师手机版下载
  • 网站建设网页制作软件海外推广方法有哪些
  • 家具做网站正规代运营公司
  • 网站页面建设方案书模板seo优化方式
  • 专门做建筑设计图库的网站设计外链群发
  • 恒锐奇 做网站设计网站模板
  • 给别人做设计的网站江门seo外包公司
  • 敬请期待海报邯郸网站seo
  • 武汉百度网站推广谷歌seo搜索优化
  • 用网站做微信公众号免费自助建站
  • 北京建筑设计公司前十名槐荫区网络营销seo
  • 闸北网站建设搜索引擎优化的具体措施
  • 企业网站建设 属于什么费用今日足球赛事推荐
  • 空间坐标系做图网站广东疫情最新消息
  • 网站滚动条代码短视频seo代理
  • 做网站用什么服务器自己建网站
  • 社保网站做的真烂做专业搜索引擎优化
  • 怎么做返利网站软文发布软件
  • 服务器租用网站免费开通网站
  • 石家庄制作网站推广搜索引擎有哪些平台
  • 手机建站平台哪个便宜写软文平台
  • 未来中森网站建设价格jsurl转码
  • 工业产品设计是科学技术与什么的融合windows优化大师怎么卸载