-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
90 lines (80 loc) · 2.08 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var board = [];
var click = '"none"';
var click2 = '"hide"';
var goodmove = 0;
function success() {
goodmove++;
if (goodmove == 71) {
for(i=0;i<81;i++){
if (document.getElementsByClassName("hide")[i]){
document.getElementsByClassName("hide")[i].style.display="none";
}
}
alert("you win!!!")
}
}
function fail() {
for(i=0;i<81;i++){
if (document.getElementsByClassName("hide")[i]) {
document.getElementsByClassName("hide")[i].style.display="none";
}
}
alert("fail");
}
function show() {
var text="<table border='0' cellpadding='0' cellspacing='0'>";
for(var y=0;y<=8;y++){
text+="<tr>"
for(var x=0;x<=8;x++){
text+= "<td><div class='field'><center>";
if (board[y][x]=="@") {
text+= "<div class='elem'><img height='18' src='https://cdn4.iconfinder.com/data/icons/SUNNYDAY/networking/png/400/bomb.png'></div><div class='hide' onClick='fail();'></div></center></div></td>"
} else {
text+= "<div class='elem'>"+board[y][x]+"</div><div class='hide' onClick='this.style.display="+click+";success();'></div></center></div></td>"
}
text+="";
}
text+="</tr>";
}
text+="</table>";
document.getElementById('game').innerHTML= text;
}
function count(y,x) {
if((x<8)&&(y>0)&&(board[y-1][x+1]!="@")){
board[y-1][x+1]++;};
if((x<8)&&(board[y][x+1]!="@")){
board[y][x+1]++;};
if((x<8)&&(y<8)&&(board[y+1][x+1]!="@")){
board[y+1][x+1]++;};
if((y>0)&&(board[y-1][x]!="@")){
board[y-1][x]++;};
if((y<8)&&(board[y+1][x]!="@")){
board[y+1][x]++;};
if((x>0)&&(y>0)&&(board[y-1][x-1]!="@")){
board[y-1][x-1]++;};
if((x>0)&&(board[y][x-1]!="@")){
board[y][x-1]++;};
if((x>0)&&(y<8)&&(board[y+1][x-1]!="@")){
board[y+1][x-1]++;};
}
function bomb() {
for (var i=1; i<=10;) {
var y= Math.round(Math.random()*8);
var x= Math.round(Math.random()*8);
if (board[y][x]!="@") {
board[y][x]="@";
i++;
count(y,x);
}
}
}
function start() {
for (var y=0; y<=8; y++) {
board[y]=[];
for(var x=0;x<=8;x++){
board[y][x]=0;
}
}
bomb();
show();
}