1 Star 6 Fork 0

nickro / wxg2048

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

wxg2048

微信小游戏2048

2048

效果图

算法

该程序主要难度在用户滑动屏幕时值相同的cell合并 将空格标为0(我代码中是用的""表示空格),假设棋盘如下:

  • 0 2 0 2
  • 0 0 0 0
  • 0 0 0 2
  • 0 0 0 0

步骤

  • 通过touch相关的事件函数确定用户滑动方向
  • 将棋盘的数字生成4*4的二维数组list
  • 根据用户滑动方向生成四个小数组,比如用户将上面的棋盘向右滑动,则四个数组为:

item[0] = [2, 0, 2, 0]; item[1] = [0, 0, 0, 0]; item[2] = [2, 0, 0, 0]; // 注意是2000而不是0002,因为是向右滑动要从右边开始 item[3] = [0, 0, 0, 0];

  • 接下来就是滑动时合并,拿item[0]举例,如果是2020,向右滑动我们应该成为0004
  • 将item[0]的所有0移到末尾变为2200,遍历item将相同的下标值相加,后面的数置为0
  • 2020 ---> 2200 ---> 4200 ----> 4000
  • 如法炮制就可以实现滑动时合并
The MIT License (MIT) Copyright (c) 2018 nickro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🐢微信小游戏2048 展开 收起
微信
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
微信
1
https://gitee.com/nickro/wxg2048.git
git@gitee.com:nickro/wxg2048.git
nickro
wxg2048
wxg2048
master

搜索帮助

14c37bed 8189591 565d56ea 8189591