zoukankan      html  css  js  c++  java
  • 微信小程序

    最近看到南湖微科普小程序游戏环节感觉还可以,于是模仿了下

    <view class='current' animation="{{animation}}">
      {{current.title}}
    </view>
    <view class='caozuo'>
      <text bindtap="type1btn">可回收</text>
      <text bindtap="type2btn">有害垃圾</text>
      <text bindtap="type3btn">其他</text>
    </view>
    <view class='score'>分数:{{score}}</view>
    

      

    .current{ 100px;height:100px;border-radius:5px; margin:20px auto;text-align:center;line-height:100px;color:#fff;background:red; }
    .caozuo{display: flex;justify-content:space-between;margin-top: 15px;font-size:14px;text-align: center;}
    .caozuo text{text-align: center;flex:1;}
    .score{ text-align:center;margin-top:20px;font-size:14px;color:red; }
    

      

    Page({
      data: {
        current:{},
        score:0,
        arr:[
          {
            id:1,
            title:"手机壳",
            type:"1"
          },
          {
            id:2,
            title: "枯枝",
            type: "3"
          },
          {
            id:3,
            title: "纸盒",
            type: "1"
          },
          {
            id:4,
            title: "涂改溢瓶",
            type:"2"
          },
          {
            id:5,
            title: "药水瓶",
            type: "2"
          },
          {
            id: 6,
            title: "电视机",
            type: "1"
          },
          {
            id: 7,
            title: "菜叶",
            type: "3"
          }
        ]
      },
      onReady: function () {
        this.animation = wx.createAnimation()
      },
      onLoad: function (options) {
        // type:1可回收  2 有害垃圾  3 其他垃圾
        // 不能重复
        var that = this;
        that.newdata();
      },
      
      newdata(current,arr){
        //每次操作过后数组更新一次
        var that = this;
        var current = that.data.current;
        var arr = that.data.arr;
    
        var currentIndex = Math.floor(Math.random() * arr.length)
        var newarr = arr.filter(function (currentvalue, index, array) {
          return index != currentIndex
        })
        
        if (arr.length === 0 ){
          wx.showToast({
            title: '恭喜闯关成功',
          })
          return
        }
    
        that.setData({
          current: arr[currentIndex],
          arr: newarr
        })
    
      },
      scoreAdd() {
        //分数添加
        var that = this;
        var score = that.data.score;
        score += 2;
        that.setData({
          score: score
        })
      },
      scoreReduce() {
        //分数减去
        var that = this;
        var score = that.data.score;
        score -= 1;
        that.setData({
          score: score
        })
      },
      select(type){
        //区分点击按钮
        var that = this;
        var current = that.data.current;
        var arr = that.data.arr;
        if (arr.length != 0) {
          if (current.type === type) {
            that.scale()
            that.newdata();
            that.scoreAdd()
          } else {
            that._toast()
            that.scoreReduce()
          }
        } else {
          wx.showToast({
            title: '恭喜闯关成功',
          })
        }
      },
      type1btn() {
        //可回收
        var that = this;
        that.select("1")
      },
      type2btn() {
        //有害垃圾
        var that = this;
        that.select("2")
      },
      type3btn() {
        //其他垃圾
        var that = this;
        that.select("3")
      },
      _toast(){
        wx.showToast({
          title: '不对应',
        })
      },
      scale: function () {
        this.animation.scale(0.6).step()
        this.animation.scale(1).step()
        this.setData({ animation: this.animation.export() })
      }
    })
    

      

  • 相关阅读:
    MySQL 锁的监控及处理
    mssql sqlserver 不固定行转列数据(动态列)
    SQL常用增删改查语句--来源于网络
    mssql sqlserver 对不同群组对象进行聚合计算的方法分享
    mssql sqlserver 自动备份存储过程的方法分享
    mssql sqlserver updatetext关键字应用简介说明
    mssql sqlserver 将字段null(空值)值替换为指定值的三种方法分享
    mssql sqlserver with cte表达式(递归)找出最顶值的方法分享
    mssql sqlserver text数据类型专题说明
    mssql sqlserver 使用sql脚本 清空所有数据库表数据的方法分享
  • 原文地址:https://www.cnblogs.com/changxue/p/8830627.html
Copyright © 2011-2022 走看看