微信小程序项目实例——扫雷

简介: 微信小程序项目实例——扫雷

文章目录

🌻🌻🌻🌼🌼🌼🌺🌺🌺🌼🌼🌼🌻🌻🌻

1️⃣ 项目介绍 👨‍🏫


🎃游戏介绍:

👉《扫雷》是一款大众类的益智小游戏,于1992年发行。游戏目标是在最短的时间内根据点击格子出现的数字找出所有非雷格子,同时避免踩雷,踩到一个雷即全盘皆输。


🎯PC端扫雷:


📑雷诀八条:

1️⃣基本定式不要忘,现场推理真够呛。

2️⃣鼠标点击不要快,稳定节奏把空开。

3️⃣顺手标雷不要惯,积累下来记录悬。

4️⃣无从下手不要愣,就近猜雷把心横。

5️⃣遇到猜雷不要怕,爆了脸上不留疤。

6️⃣猜雷猜错不要悔,哭天抢地也白费。

7️⃣碰上好局不要慌,紧盯局部慢扩张。

8️⃣痛失好局不要恨,既然有缘定有份。


项目展示:

👉扫雷小程序借鉴经典的PC端扫雷

👉玩家可以自行设置格子数🟫和地雷数💣

👉单点是开启,长按为插旗🚩

🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡🤡

2️⃣ 项目结构 👨‍💻


🎃项目目录:

🧑‍🚀核心代码:

<!--pages/game/game.wxml-->
<view class="page">
    <view class="section btns">
        <button bindtap="newGame">重新开始</button>
        <button bindtap="handleSetting">游戏设置</button>
    </view>
    <view class="section">
        <view wx:for="{{grids}}" class="grid">
            <view wx:for="{{item}}" class="grid_cell" style="height:{{height}}rpx;">
                <view bindtouchstart="handleTouchStart" bindtouchend="handleTouchEnd" bindtap="handleClick" id="{{item}}" class="card {{cards[item].open?'open':''}}">
                    <view wx:if="{{cards[item].open}}">
                        <text wx:if="{{cards[item].boom}}" class="iconfont icon-zhadan-BOOM"></text>
                        <text wx:else>{{cards[item].num>0?cards[item].num:''}}</text>
                    </view>
                    <view wx:else>
                        <text wx:if="{{cards[item].flag}}" class="iconfont icon-qizhi" style="color:red"></text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</view>
// pages/game/game.js
const app = getApp();
Page({
  data:{
    config: {
      x: 0,
      y: 0,
      n: 0
    },
    cards: [],
    grids: [],
    // arr: [],
    start: false,
    open: 0,
    touchStart:0,
    touchEnd:0,
    height: 0
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    this.setData({
      config:{
        x:app.globalData.config.x,
        y:app.globalData.config.y,
        n:app.globalData.config.n
      },
      height: 750/app.globalData.config.x      
    });
    this.newGame();
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  newGame(){
    const x = this.data.config.x;
    const y = this.data.config.y;
    const n = this.data.config.n;
    const cards = [];
    const grids = [];
    // const arr = [];
    for(let i=0; i<y; i++){
      grids.push([]);
      for(let j=0; j<x; j++){
        const index = i*x+j;
        cards.push({
          index:index,
          boom:false,
          num:0,
          open:false,
          flag:false
        });
        grids[i].push(index);
        // arr.push(index);
      }
    }
    this.setData({
      cards: cards,
      grids: grids,
      // arr: arr,
      start: false,
      open: x*y-n
    });
  },
  handleClick(e){
    const i = parseInt(e.currentTarget.id);
    console.log(i);
    // console.log(this.data.touchEnd);
    // console.log(this.data.touchStart);
    const touchTime = this.data.touchEnd-this.data.touchStart;
    // console.log(touchTime);
    if(touchTime>350){
      const cards = this.data.cards;
      cards[i].flag = true;
      this.setData({cards:cards});
    }else{
      !this.data.start && this.setBoom(i);
      this.handleOpen(i);
    }
  },
  handleTouchStart(e){
    this.setData({
      touchStart:e.timeStamp
    });
  },
  handleTouchEnd(e){
    this.setData({
      touchEnd:e.timeStamp
    });
  },
  handleOpen:function(i){
    // const i = e.currentTarget.id;
    // console.log(i);
    // !this.data.start && this.setBoom(i);
    // this.getNeighbor(i);
    const cards = this.data.cards;
    if(cards[i].open){
      // console.log('OPENED!!!!!!!!!!!!!!!');
      return;
    }else{
      cards[i].open = true;
      this.setData({
        cards:cards,
        open:--this.data.open
      });
      console.log(this.data.open);
      if(this.data.open==0){
        wx.showModal({
          title: 'YOU WIN!!!!!',
          showCancel: false,
          success: function(res) {
            if (res.confirm) {
              // console.log('用户点击确定')
              this.newGame();
            }
          }.bind(this)
        });
      }
    }
    if(cards[i].boom){
      // console.log('boom!!!!!!!!!!!!!!!');
      wx.showModal({
        title: 'GAME OVER',
        showCancel: false,
        success: function(res) {
          if (res.confirm) {
            // console.log('用户点击确定')
            this.newGame();
          }
        }.bind(this)
      });
    }else if(cards[i].num==0){
      const ns = this.getNeighbor(i);
      ns.forEach(function(item){
        this.handleOpen(item);
      }.bind(this));
    }
  },
  setBoom:function(j){
    const cards = this.data.cards;
    // const arr = this.data.arr;
    const num = this.data.config.n;
    const newArr = this.getNeighbor(j).concat(j);
    // arr.splice(j,1);
    // const arr = [...Array(cards.length).keys()];
    const arr = [];
    for (let index of Array(cards.length).keys()) {
      newArr.indexOf(index)==-1 && arr.push(index);
    }
    // console.log(newArr);
    // console.log(arr);
    for(let i=0; i<num; i++){
      const index = Math.floor(Math.random()*arr.length);
      cards[arr[index]].boom = true;
      newArr.push(arr[index]);
      arr.splice(index,1);
    }
    const newCards = cards.map(function(card,i){
      let n = 0;
      this.getNeighbor(i).forEach(function(neighbor){
        cards[neighbor].boom && n++;
      });
      card.num = n;
      return card;
    }.bind(this));
    this.setData({
      arr:arr.concat(newArr),
      cards:newCards,
      start: true
    });
  },
  getNeighbor:function(i){
    const x = this.data.config.x;
    const y = this.data.config.y;
    // const arr = [i-x-1,i-x,i-x+1,i-1,i+1,i+x-1,i+x,i+x+1];
    const arr = [];
    !(i<x||i%x==0) && arr.push(i-x-1);
    !(i<x) && arr.push(i-x);
    !(i<x||i%x==(x-1)) && arr.push(i-x+1);
    !(i%x==0) && arr.push(i-1);
    // arr.push(i);
    !(i%x==(x-1)) && arr.push(i+1);
    !(i>=x*(y-1)||i%x==0) && arr.push(i+x-1);
    !(i>=x*(y-1)) && arr.push(i+x);
    !(i>=x*(y-1)||i%x==(x-1)) && arr.push(i+x+1);
    // console.log(arr);
    return arr
  },
  handleSetting:function(){
    wx.navigateTo({
      url: '../setting/setting'
    })
  }
})

🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈

3️⃣ 项目展示 👨‍🎨


🧭🧭🧭🧭🧭🧭🧭🧭🧭🧭🧭

4️⃣ 结尾 👨‍🎓


具体的介绍就到这里了💭

扫雷小程序与PC经典的扫雷玩法一致🎰

有兴趣的同学可以继续研究🔎

代码放到下面链接里了👇

👉点击下载 扫雷小程序💣

相关文章
|
1月前
|
监控 小程序 安全
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(2)
小程序提供便捷的鲜花选购和配送服务,汇聚全球优质鲜花品种,确保新鲜送达。用户可轻松挑选花束,享受个性化配送,并通过地图功能查看配送位置。此外,物流功能实时更新,保证鲜花安全快速到达。代码示例展示了地图和物流信息的页面布局与交互实现。 ### 配送与物流功能亮点 1. **地图功能**:使用`map.wxml`, `map.wxss`, 和 `map.js` 实现定位与导航,确保精准配送。 2. **物流追踪**:通过`logistics.wxml`, `logistics.wxss`, 和 `logistics.js` 显示详细物流状态,提供流畅的用户体验。
47 1
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(2)
|
18天前
|
移动开发 开发框架 小程序
开发H5程序或者小程序的时候,后端Web API项目在IISExpress调试中使用IP地址,便于开发调试
开发H5程序或者小程序的时候,后端Web API项目在IISExpress调试中使用IP地址,便于开发调试
|
7天前
|
前端开发 JavaScript API
微信公众号项目,实现微信支付(具体流程和参数)
微信公众号项目,实现微信支付(具体流程和参数)
|
1月前
|
小程序 安全 搜索推荐
【微信小程序开发实战项目】——个人中心页面的制作
本文介绍了如何设计和实现一个网上花店的微信小程序,包括个人中心、我的订单和我的地址等功能模块。个人中心让用户能够查看订单历史、管理地址和与客服互动。代码示例展示了`own.wxml`、`own.wxss`和`own.js`文件,用于构建个人中心界面,包括用户信息、订单链接、收藏、地址、客服和版本信息。我的订单部分展示了订单详情,包括商品图片、名称、销量、价格和订单状态,用户可以查看和管理订单。我的地址功能允许用户输入和编辑收货信息,包括联系人、性别、电话、城市和详细地址。每个功能模块都附有相应的WXML和WXSS代码,以及简洁的样式设计。
72 0
【微信小程序开发实战项目】——个人中心页面的制作
|
1月前
|
小程序 安全 搜索推荐
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(3)
这是一篇关于微信小程序开发的文章摘要,作者介绍了如何创建一个网上花店小程序,旨在提供便捷的购花体验。小程序包含鲜花分类功能,允许用户按品种、颜色和用途筛选,确保快速找到合适的鲜花。它还提供了配送服务,保证鲜花的新鲜度。文章展示了`cash.wxml`、`cash.wxss`和`cash.js`的部分代码,用于实现分类和商品展示,以及`qin.wxml`、`qin.wxss`和`qin.js`,涉及商品详情和购买付款流程。代码示例展示了商品列表渲染和交互逻辑,包括页面跳转、数据传递和点击事件处理。文章最后提到了购买付款界面,强调了安全和便捷的支付体验。
68 0
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(3)
|
2月前
|
程序员 开发者
黑马程序员 苍穹外卖项目 Day微信支付问题解决与生成订单号超出上限问题
黑马程序员 苍穹外卖项目 Day微信支付问题解决与生成订单号超出上限问题
38 5
|
29天前
|
小程序 API
跨端技术问题之哪些形态可以通过getApp()获取全局App实例
跨端技术问题之哪些形态可以通过getApp()获取全局App实例
|
2月前
|
小程序 前端开发 JavaScript
计算机Python项目|django傣族节日及民间故事推广小程序
计算机Python项目|django傣族节日及民间故事推广小程序
|
1月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp小程序的业财票务一体项目管理系统 附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp小程序的业财票务一体项目管理系统 附带文章源码部署视频讲解等
28 0
|
1月前
|
XML Java 数据格式
支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法
支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法

热门文章

最新文章