资讯专栏INFORMATION COLUMN

H5 组词小游戏源代码

chadLi / 3260人阅读

摘要:小游戏篇一组词游戏项目功能简介词库功能,项目文件里配有格式的中文常用词组词库,每次随机抽取词语进行游戏匹配消除功能,自动在词库中匹配选中词语并进行消除选中动画以及消除动画,均由生成爆炸动画智能提醒系统,秒之后未作操作可提示单词过关判定核心代

H5小游戏 篇一 组词游戏

项目功能简介

词库功能,项目文件里配有csv格式的中文常用词组词库,每次随机抽取词语进行游戏

匹配消除功能,自动在词库中匹配选中词语并进行消除

选中动画以及消除动画,均由svg生成爆炸动画

智能提醒系统,10秒之后未作操作可提示单词

过关判定

## 核心代码展示链接描述

https://github.com/fanshyiis/...

</>复制代码

  1. 获取词库,根据csv文件

</>复制代码

  1. $.ajax({
  2. url: "./js/ck2.csv",
  3. dataType: "text"
  4. }).done(successFunction);
  5. // 回调函数
  6. function successFunction(data) {
  7. var allRows = data.split(/
  8. ?
  9. |
  10. /);
  11. for (var singleRow = 1; singleRow < allRows.length; singleRow++) {
  12. if (allRows[singleRow].length === 2) {
  13. var m = {
  14. a: allRows[singleRow][0],
  15. b: allRows[singleRow][2]
  16. }
  17. dataBase.push(m)
  18. }
  19. }
  20. }

</>复制代码

  1. 随机抽取函数
    会根据数组的长度获取随机数据

</>复制代码

  1. function getArrayItems(arr, num) {
  2. //新建一个数组,将传入的数组复制过来,用于运算,而不要直接操作传入的数组;
  3. var temp_array = new Array();
  4. for (var index in arr) {
  5. temp_array.push(arr[index]);
  6. }
  7. //取出的数值项,保存在此数组
  8. var return_array = new Array();
  9. for (var i = 0; i0) {
  10. //在数组中产生一个随机索引
  11. var arrIndex = Math.floor(Math.random()*temp_array.length);
  12. //将此随机索引的对应的数组元素值复制出来
  13. return_array[i] = temp_array[arrIndex];
  14. //然后删掉此索引的数组元素,这时候temp_array变为新的数组
  15. temp_array.splice(arrIndex, 1);
  16. } else {
  17. //数组中数据项取完后,退出循环,比如数组本来只有10项,但要求取出20项.
  18. break;
  19. }
  20. }
  21. return return_array;

}

</>复制代码

  1. svg动画渲染插件

</>复制代码

  1. function clear(id) {
  2. document.getElementById(id).innerHTML = ""
  3. console.log(id,"-----------------")
  4. bodymovin.loadAnimation({
  5. container: document.getElementById(id), // 渲染动画的 dom 元素
  6. renderer: "svg",
  7. loop: false,
  8. autoplay: true,
  9. path: "./js/data.json"
  10. })
  11. }

</>复制代码

  1. var vue = new Vue({
  2. el: "#vue",
  3. data: {
  4. windowBg: false,
  5. restart: false,
  6. passNum: cn,
  7. pass: 1,
  8. grid: 9,
  9. allText: null,
  10. gridList: [],
  11. text: "春天里柳树发芽百花",
  12. one: null,
  13. two: null,
  14. reData: null,
  15. timeDuring: 0
  16. },
  17. methods: {
  18. // 重置函数
  19. reStart () {
  20. this.restart = true
  21. setTimeout(function () {
  22. vue.restart = false
  23. }, 800)
  24. this.playAudio("restart")
  25. this.passNum = cn
  26. this.gridList = JSON.parse(JSON.stringify(this.reData))
  27. },
  28. playAudio (val) {
  29. var x = document.getElementById(val)
  30. x.load()
  31. x.play()
  32. },
  33. setTime () {
  34. this.timeDuring++
  35. if (this.timeDuring === 10) {
  36. this.tip()
  37. }
  38. console.log(this.timeDuring)
  39. setTimeout(function () {
  40. vue.setTime()
  41. }, 1000)
  42. },
  43. tip () {
  44. let a = ""
  45. console.log(choose)
  46. this.gridList.map(val => {
  47. if (!val.r && val.f) {
  48. a = a + val.f
  49. }
  50. })
  51. let b = null
  52. choose.map(val => {
  53. if (a.indexOf(val.a) !== -1 && a.indexOf(val.b) !== -1) {
  54. b = val.a
  55. }
  56. })
  57. if (!b) {
  58. this.getNextPass()
  59. }
  60. if (this.one) {
  61. this.choose(this.one, "t")
  62. }
  63. this.gridList.map(val => {
  64. if (!val.r && val.f === b) {
  65. this.one = null
  66. this.choose(val, "t")
  67. }
  68. })
  69. console.log(a)
  70. },
  71. // 选择函数
  72. choose (item, type) {
  73. if (type !== "t") {
  74. this.timeDuring = 0
  75. }
  76. if (!item.f) {
  77. return false
  78. }
  79. if (this.one && item.x === this.one.x && item.y === this.one.y) {
  80. this.playAudio("touchCard")
  81. item.choose = !item.choose
  82. this.one = null
  83. return false
  84. } else {
  85. this.playAudio("touchCard")
  86. item.choose = !item.choose
  87. if (this.one) {
  88. this.two = item
  89. // font()
  90. // 模拟消除
  91. // 加上timeout效果更好
  92. var _this = this
  93. setTimeout(function () {
  94. _this.clearText()
  95. }, 300)
  96. } else {
  97. this.one = item
  98. // font()
  99. }
  100. }
  101. },
  102. // 消除逻辑
  103. clearText () {
  104. var r = false
  105. dataBase.map(val =>{
  106. if (val.a === this.one.f && val.b === this.two.f) {
  107. r = true
  108. }
  109. })
  110. if (!r) {
  111. this.gridList.map(val => {
  112. if (val.x === this.two.x && val
  113. .y === this.two.y) {
  114. val.choose = false
  115. this.playAudio("error")
  116. }
  117. if (val.x === this.one.x && val
  118. .y === this.one.y) {
  119. val.choose = false
  120. }
  121. })
  122. this.two = false
  123. this.one = false
  124. return false
  125. }
  126. this.gridList.map(val => {
  127. if (val.x === this.one.x && val
  128. .y === this.one.y) {
  129. clear(val.x + "" + val.y)
  130. setTimeout(function () {
  131. val.f = ""
  132. }, 200)
  133. val.r = true
  134. }
  135. if (val.x === this.two.x && val
  136. .y === this.two.y) {
  137. clear(val.x + "" + val.y)
  138. setTimeout(function () {
  139. val.f = ""
  140. }, 200)
  141. val.r = true
  142. this.playAudio("success")
  143. }
  144. })
  145. this.passNum--
  146. console.log(this.passNum)
  147. if (this.passNum === 0) {
  148. this.playAudio("next")
  149. this.windowBg = true
  150. }
  151. // this.sound_error = true
  152. this.one = null
  153. this.two = null
  154. },
  155. // 进入下一关
  156. getNextPass () {
  157. this.one = false
  158. this.timeDuring = 0
  159. this.windowBg = false
  160. cn = cn + 2,
  161. this.pass++
  162. this.passNum = cn
  163. getDataBase()
  164. setTimeout(function () {
  165. font()
  166. }, 1000)
  167. },
  168. //初始化函数
  169. start () {
  170. this.gridList = []
  171. for (var i = 0; i < this.grid; i++) {
  172. for (var j = 0; j < this.grid; j++) {
  173. this.gridList.push({
  174. x: i,
  175. y: j,
  176. f: "",
  177. choose: false,
  178. r: false,
  179. m: false
  180. })
  181. }
  182. }
  183. var l = []
  184. choose.map(val => {
  185. l.push(val.a)
  186. l.push(val.b)
  187. })
  188. $("#bggg").click()
  189. // this.playAudio("bgm")
  190. console.log(l)
  191. this.allText = l
  192. var c = getArrayItems(this.gridList, cn * 2)
  193. console.log(c)
  194. c.map((val, index) => {
  195. val.f = l[index]
  196. })
  197. this.reData = JSON.parse(JSON.stringify(this.gridList))
  198. }
  199. },
  200. created () {
  201. getDataBase()
  202. this.setTime()
  203. }
  204. })

</>复制代码

  1. 其他函数就不一一介绍了
  2. 上个图最后

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/94901.html

相关文章

  • H5游戏 【篇一】 组词游戏

    摘要:小游戏篇一组词游戏项目功能简介词库功能,项目文件里配有格式的中文常用词组词库,每次随机抽取词语进行游戏匹配消除功能,自动在词库中匹配选中词语并进行消除选中动画以及消除动画,均由生成爆炸动画智能提醒系统,秒之后未作操作可提示单词过关判定库描述 H5小游戏 篇一 组词游戏 项目功能简介 词库功能,项目文件里配有csv格式的中文常用词组词库,每次随机抽取词语进行游戏 匹配消除功能,自动在词...

    CloudwiseAPM 评论0 收藏0
  • 十步零基础JavaScript学习路径

    摘要:之前写过一篇天学通前端开发,内容主要讲的就是前端学习路径,今天再来写一篇零基础的学习路径,希望能帮编程零基础的前端爱好者指明方向。十框架三选一,零基础的初学者强烈推荐,如果是后台转前端推荐,如果技术型前端,推荐。 之前写过一篇26天学通前端开发,内容主要讲的就是前端学习路径,今天再来写一篇零基础的JavaScript学习路径,希望能帮编程零基础的前端爱好者指明方向。 一、开发环境和Ja...

    incredible 评论0 收藏0
  • 白鹭引擎王泽:重度H5游戏性能优化技巧标题的文章

    摘要:据不完全统计,这五年中,白鹭引擎累计运转的游戏和微信小游戏的流水数据约为亿。 我们的引擎架构师做某一沙龙活动的演讲速记,纯纯的干货,分享给大家。 王泽:各位开发者下午好!我叫王泽,是白鹭引擎的首席架构师。 今天给大家分享的题目是《重度H5游戏性能优化技巧》。之所以决定用这个题目,是因为我最近几周在广深一带拜访了很多使用白鹭引擎的开发者,发现特别是在广州一带,大部分开发者都在做重度H5游...

    xbynet 评论0 收藏0
  • 你踩过几个?微信H5游戏开发中的那些坑

    摘要:眼下小游戏特别火,不少团队也陆续启动了微信小游戏的项目,并于立项前期进行技术预研究。但从微信官方文档看却能发现不少坑。对微信小游戏和浏览器之间的运行环境差异无感知,非常友好。微信小程序要求开发者的服务器支持协议。 眼下小游戏特别火,不少团队也陆续启动了微信小游戏的项目,并于立项前期进行技术预研究。但从微信官方文档看 , 却能发现不少坑。 一、运行环境的坑 1.API兼容性 1.1、网络...

    calx 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<