Matching Game based on JS
来源:互联网 发布:淘宝店铺售假扣24分 编辑:程序博客网 时间:2024/06/08 16:48
Using JavaScript to realize a matching game in web browse.
Purpose: find the extra “smile” in the left side, compared to the right side. Each time we click the ‘right’ smile, the number of pic will increase by 5. In this case, the difficulty will increase correspondingly.
So JS code is as follow:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>Match Game - Part4</title> <style> img { position: absolute; } div { position: absolute; width: 500px; height: 500px; } #rightSide { left: 500px; border-left: 1px solid black; } </style> <script> var numberofFaces = 5; function generateFaces(){ var num = numberofFaces; var theBody = document.getElementsByTagName("body")[0]; var theleftside = document.getElementById("leftSide"); // can't put this line outside of func because at this time, the page doesn't load "leftside" div, //so the variable "theleftside" will be null. This is the most common mistake for the beginner. while(num>0){ var imgNode = document.createElement("img"); var x = 400 * Math.random(); var y = 400 * Math.random(); imgNode.src = "http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png"; imgNode.style.top = x + "px"; imgNode.style.left = y + "px"; theleftside.appendChild(imgNode); num--; } var therightside = document.getElementById("rightSide"); var leftsideimg = theleftside.cloneNode(true); leftsideimg.removeChild(leftsideimg.lastChild); therightside.appendChild(leftsideimg); theleftside.lastChild.onclick = function nextLevel(event){ event.stopPropagation(); numberofFaces += 5; // delete all the children while(theleftside.firstChild){ theleftside.removeChild(theleftside.firstChild); } while(therightside.firstChild){ therightside.removeChild(therightside.firstChild); } generateFaces(); }; theBody.onclick = function gameOver() { alert("Game Over!"); theBody.onclick = null; theleftside.lastChild.onclick = null; } } </script></head><body onload="generateFaces()"><h1>Matching Game</h1><p>Click on the extra smiling face on the left.</p><div id="leftSide"></div><div id="rightSide"></div></body></html>
0 0
- Matching Game based on JS
- Meshless Deformations Based on Shape Matching
- Unsupervised Image Matching based on Manifold Alignment(笔记)
- Generating a string with elements from an array based on pattern matching
- Based Off Versus Based On
- Review of codeforces 492C Vanya and Computer Game based on Python
- TypeSelect based on TypeTraits
- webkit based on win
- Spider based on scrapy
- iperf based on linux
- Dash Based On Plotly
- [Patch-Based Matching 1] related work
- Based on or Basing on, 为何写作多用 Based on?
- content based routing based on header value
- Simple Sync is a simple sync function-wrapper for node js, based on fibers module.
- Harris algorithm based on openCV
- OB52 based on Company Code
- CAMShift Algorithm Based on OpenCV
- Linux学习(1):ls命令
- 【Android】新版Android Studio 2.0 Preview 4 下载链接 百度网盘
- 动态规划学习之最长上升子序列
- 得到一个字符串的哈希Hash值
- could not find java SE Runtime Environment/Error: could not find java.dll
- Matching Game based on JS
- 在Windows上调优DB2
- 窗口看门狗的真正作用
- Android studio中cannot reload avd list问题解决
- 【转载】大力推荐使用chrome浏览器
- 使用AFNetworking时遇到了 property synthesis 相关的 error
- linux下用qt写的的串口小程序
- AutoLayout 和 autoresizing
- iOS 无线部署