用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,登录网站

2016-11-29 17:56:33 天下雪原创达人 造轮子 人生巅峰 楼主 4113560
点评:不多的游戏类demo之一;这个是比较常见的挑选游戏;从多个之中选择那个不同的;
22.png 23.png 24.png
20.png 21.png
[AppleScript] 纯文本查看 复制代码
const cubeMap = [2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9];

// 接收 score
const grids = function (score) {
  let cube = cubeMap[score] || cubeMap[cubeMap.length - 1];
  let ratio = 15 * Math.max(9 - cube, 1); // 难度系数配比
  ratio = score > 20 ? 10 : ratio,
    ratio = score > 40 ? 8 : ratio,
    ratio = score > 50 ? 5 : ratio;

  let baseColor = getColor(255 - ratio);
  let oneColor = getLvColor(baseColor[0], ratio)[1];
  let mainColor = baseColor[1];

  return {
    cube,
    mainColor,
    oneColor
  }
};

function getColor(mrt) {
  var rgb = [Math.round(Math.random() * mrt), Math.round(Math.random() * mrt), Math.round(Math.random() * mrt)],
    rgbStyle = "rgb(" + rgb.join(",") + ")";
  return [rgb, rgbStyle];
}

function getLvColor(mrt, ratio) {
  var brt = ratio,
    rgb = mrt.map(function (item) {
      return item + brt;
    }),
    rgbStyle = "rgb(" + rgb.join(",") + ")";
  return [rgb, rgbStyle];
}

module.exports = {
  grids
};

[AppleScript] 纯文本查看 复制代码
import { grids } from '../../utils/grids.js';

const app = getApp();

const pageData = {
  data: {
    score: 0,
    colors: [],
    cube: 2,
    seconds: 60,
    pause: false
  },

  onShow: function () {
    this._ren();
    this._timer();
  },

  onUnload: function () {
    this.setData({
      pause: true
    });
    this._timer();
  },

  // 下一关
  goNext: function (e) {
    let next = e.currentTarget.dataset.next;
    if (next === 'true') {
      this.setData({
        score: this.data.score + 1
      });
      this._ren();
    }
  },

  // 暂停
  toPause: function () {
    this.setData({
      pause: true
    });
    this._timer();
  },

  // 继续
  toContinue: function () {
    this.setData({
      pause: false
    });
    this._timer();
  },

  // 计时器
  _timer: function () {
    let tm = setInterval(() => {
      let scnd = this.data.seconds;

      // 暂停
      if (this.data.pause) {
        clearInterval(tm);
        return;
      }

      // 结束
      if (scnd == 0) {
        clearInterval(tm);
        this._gameOver();
        return;
      }

      this.setData({
        seconds: scnd - 1
      });
    }, 1000);
  },

  // 游戏结束
  _gameOver: function () {
    let score = this.data.score;
    let levels = ["瞎子", "色盲", "色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色"];
    let idx = 3 > score ? 0 : Math.ceil((score - 3) / 3);
    app.level = levels[idx] || levels[levels.length - 1];
    wx.redirectTo({
      url: '../over/over'
    });
  },

  // 数据准备 & 渲染
  _ren: function () {
    let score = this.data.score;
    let round = grids(score);
    let cube = round.cube;
    let total = cube * cube;
    let colorAry = new Array(total);

    colorAry.fill({
      color: round.mainColor,
      next: false
    }, 0, colorAry.length);

    let oneIndex = Math.floor(Math.random() * total);

    colorAry[oneIndex] = {
      color: round.oneColor,
      next: true
    };

    this.setData({
      cube: cube,
      level: 'cb-' + cube,
      colors: colorAry
    });
  }
};

Page(pageData);


项目地址及下载:
https://github.com/aisin/weapp-color
weapp-color-master.zip (7.23 KB, 下载次数: 1763)
有问题请在本站内搜索相应关键词,假如无法解决请在综合交流区内发帖咨询,发帖时请提供详细的问题描述、相关图片及代码。
66666666666666666
多谢啊
66666666666666
识色;从相似颜色中挑选不同的一个
谢谢分享
谢谢分享
2016-12-5 20:29:48 webkfz 攻城狮
8#
66666666666
2016-12-7 10:24:57 webkf 架构狮
10#
哈哈哈哈哈哈哈哈或
谢谢分享
666666666
dddddddddddddddddddddddddddddddddd
棒棒棒
666666666666666
123下一页
发新帖
您需要登录后才可以回帖 登录 | 立即注册