Use pure javascript to implement the classic clearance game _ javascript skills

Source: Internet
Author: User
This article will share with you the code for a windows-like mine clearance game that I wrote when I first started learning javascript. I wrote it, but did not add any comments. I will add it here, if you have any need, refer. I wrote a long time ago, but I didn't write comments. (Nima, many of them don't know each other ...)

The disadvantage is that I wanted to write a game ranking statistics. When I was free, I added it (as if every time I said this, I waited for a long time ...)

There is also the lack of implementation: clicking the first grid cannot be a ray Function

  8*10 10*10 12*12  Start again

Timing: 0

    Earlier versions of ie6 + ff oprea Google opera do not support document by default. oncontextmenu event does not find a good alternative method. script var $ = function (id) {return document. getElementById (id)}; window. onload = function ready () {var V = $ ('wh '). value. split ('*') setMineField (Number (V [0]), Number (V [1]); $ ('wh '). onchange = $ ('ready '). onclick = function () {V = $ ('wh '). value. split ('*') setMineField (Number (V [0]), Number (V [1])} // -------------------------------------------------- ----- MineField var mineField = {_ mineW: 30, // The width of each mine must be synchronized with the style _ mineH: 30, _ mineFieldBlock: $ ('Mine '), _ mineFieldEle: $ ('Mine '). getElementsByTagName ('lil'), _ time: $ ('time'), status: 0, // The minefield status 0 has not started yet. 1 has started timing. 2 The game has ended. mineNum: 0, // number of mines clearPlace: 0, // The checkpoint for statistics cleaning. x: 0, // column y: 0, // row density: 0.2, // The mine density. The mine density cannot exceed 0.5. If the mine density is too high, the mineMap array cannot be generated. mineMap: [], // two-dimensional map of the mine area, 0: not Ray-1: Ray time:-1, // timing s debug: false // debug mode} // mineF Ield object endfunction timedCount () {if (mineField. status! = 1) {return false} mineField. time ++; mineField. _ time. innerHTML = mineField. time; setTimeout ("timedCount ()", 1000);} // -------------------------------------- set function setThisMine (str, index) {var allMine = mineField for the Thunder status. _ mineFieldEle; // set whether the thunder flag. if (str = 'seton') {var thisMine = allMine [index]; thisMine. on = thisMine. on <2? ThisMine. on + 1:0; if (thisMine. on = 1) {thisMine. className = 'Mine _ 03';} // flag else if (thisMine. on = 2) {thisMine. className = 'Mine _ 04 '} // cancel flag else if (thisMine. on = 0) {thisMine. className = 'Mine _ 01'} // cancel flag return false;} // display the square if (str = 'show') {if (Object. prototype. toString. call (index) = '[object Array]') {// display a large mineField. clearPlace = mineField. clearPlace + index. length; for (var I = 0; I = 0 & Math. ceil (T + 1)/x) = br-1 & mineField. mineMap [T] = 0) {continue} if (R_T> = 0 & Math. ceil (R_T + 1)/x) = br-1 & mineField. mineMap [R_T] = 0) {continue} if (L> = 0 & Math. ceil (L + 1)/x) = br & mineField. mineMap [L] = 0) {continue} if (R = 0 & Math. ceil (L_T + 1)/x) = br-1 & mineField. mineMap [L_T] =-1) {thisMineNum ++;} if (T> = 0 & Math. ceil (T + 1)/x) = br-1 & mineField. mineMap [T] =-1) {thisMineNum ++;} if (R_T> = 0 & Math. ceil (R_T + 1)/x) = br-1 & mineField. mineMap [R_T] =-1) {thisMineNum ++;} if (L> = 0 & Math. ceil (L + 1)/x) = br & mineField. mineMap [L] =-1) {thisMineNum ++;} if (R = 0 & Math. ceil (T + 1)/x) = br-1 & allMine [T]. on = 0 & mineField. mineMap [T] = 0) {_ allI. push (T);} if (R_T> = 0 & Math. ceil (R_T + 1)/x) = br-1 & allMine [R_T]. on = 0 & mineField. mineMap [R_T] = 0) {_ allI. push (R_T);} if (L> = 0 & Math. ceil (L + 1)/x) = br & allMine [L]. on = 0 & mineField. mineMap [L] = 0) {_ allI. push (L);} if (R = 0 & Math. ceil (L_T + 1)/x) = br-1 & allMine [L_T]. on = 0 & text. indexOf ('_' + L_T + '_') =-1) {allShowMine. push (L_T); allMine [L_T]. on = 3} if (T> = 0 & Math. ceil (T + 1)/x) = br-1 & allMine [T]. on = 0 & text. indexOf ('_' + T + '_') =-1) {allShowMine. push (T); allMine [T]. on = 3} if (R_T> = 0 & Math. ceil (R_T + 1)/x) = br-1 & allMine [R_T]. on = 0 & text. indexOf ('_' + R_T + '_') =-1) {allShowMine. push (R_T); allMine [R_T]. on = 3} if (L> = 0 & Math. ceil (L + 1)/x) = br & allMine [L]. on = 0 & text. indexOf ('_' + L + '_') =-1) {allShowMine. push (L); allMine [L]. on = 3} if (R

    The above is all the content of this article. I hope you will like it.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.