-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsupport2048.js
More file actions
132 lines (114 loc) · 3.03 KB
/
support2048.js
File metadata and controls
132 lines (114 loc) · 3.03 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Created by hc on 2016/10/21.
*/
documentWidth = window.screen.availWidth;
gridWidth = 0.92 * documentWidth;
cellWidth = 0.18 * documentWidth;
cellMargain = 0.04 * documentWidth;
function getPosTop(i,j) {
return cellMargain + i * ( cellMargain + cellWidth );
}
function getPosLeft(i,j) {
return cellMargain + j * ( cellMargain + cellWidth );
}
function getNumberCellBackgroundColor( number ){
switch( number ){
case 2:return "#eee4da";break;
case 4:return "#ede0c8";break;
case 8:return "#f2b179";break;
case 16:return "#f59563";break;
case 32:return "#f67c5f";break;
case 64:return "#f65e3b";break;
case 128:return "#edcf72";break;
case 256:return "#edcc61";break;
case 512:return "#9c0";break;
case 1024:return "#33b5e5";break;
case 2048:return "#09c";break;
case 4096:return "#a6c";break;
case 8192:return "#93c";break;
}
return "black";
}
function getNumberColor( number ){
if( number <= 4 )
return "#776e65";
return "white";
}
function nospace( border ) {
for(var i=0; i<4; i++ ) {
for (var j = 0; j < 4; j++) {
if(border[i][j] == 0) {
return false;
}
}
}
return true ;
}
function canMoveLeft( border ) {
for(var i=0; i<4; i++ ) {
for (var j = 1; j < 4; j++) {
if(border[i][j] != 0) {
if(border[i][j-1] == 0 || border[i][j-1] == border[i][j]) {
return true;
}
}
}
}
return false;
}
function canMoveRight( border ) {
for( var i=0; i<4; i++ ) {
for( var j = 2; j >= 0; j-- ) {
if( border[i][j] != 0 ) {
if(border[i][j+1] == 0 || border[i][j+1] == border[i][j]) {
return true;
}
}
}
}
return false;
}
function canMoveUp( border ) {
for( var j=0; j<4; j++ ) {
for( var i = 1; i < 4; i++ ) {
if( border[i][j] != 0 ) {
if(border[i-1][j] == 0 || border[i-1][j] == border[i][j]) {
return true;
}
}
}
}
return false;
}
function canMoveDown( border ) {
for( var j=0; j<4; j++ ) {
for( var i = 2; i >= 0; i-- ) {
if( border[i][j] != 0 ) {
if(border[i+1][j] == 0 || border[i+1][j] == border[i][j]) {
return true;
}
}
}
}
return false;
}
function noBlockHorizontal(row,col1,col2,boarder) {
for(var i=col1+1; i<col2; i++)
if (boarder[row][i] != 0)
return false;
return true;
}
function noBlockVertical(col,row1,row2,boarder) {
for(var i=row1+1; i<row2; i++)
if (boarder[i][col] != 0)
return false;
return true;
}
function nomove( board ){
if( canMoveLeft( board ) ||
canMoveRight( board ) ||
canMoveUp( board ) ||
canMoveDown( board ) )
return false;
return true;
}