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 againTiming: 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.