forked from xiaorui16888/AutoJsCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2048游戏机(3).js
145 lines (122 loc) · 2.5 KB
/
2048游戏机(3).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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
"ui";
ui.statusBarColor("#AA0000");
ui.layout(
<frame background="#AA0000">
<vertical align="top" margin="5">
<text id="text" bg="#ffffff" h="430" gravity="center" color="#111111" size="40"></text>
<linear>
<vertical w="170">
</vertical>
<vertical>
<linear>
<button margin="0 0 0 60" h="60" w="60" id="up" text="上"></button>
</linear>
<linear>
<button h="60" w="60" id="left" text="左"></button>
<button h="60" w="60" id="ok" text="ok"></button>
<button h="60" w="60" id="right" text="右"></button>
</linear>
<linear>
<button margin="0 0 0 60" h="60" w="60" id="down" text="下"></button>
</linear>
</vertical>
</linear>
</vertical>
</frame>
);
//console.show()
clear();
display()
function display() {
ui.text.text(toText(screen));
}
ui.up.click(() => {
});
ui.left.click(() => {
});
ui.down.click(() => {
down()
display()
});
ui.left.click(() => {
});
ui.ok.click(() => {
random()
//toast(String(screen))
display()
});
function down() {
for (y = 3; y > 0; y--) {
for (x = 0; x < 4; x++) {
if (screen[y][x] == 0) {
if(y != 0){
screen[y][x] = screen[y - 1][x]
screen[y - 1][x] = 0
}
else{
screen[0][x] = 0
}
}
if(screen[y][x]==[y-1][x]&&screen[y][x]!=0){
toast(x+","+y)
screen[y][x]*=2
screen[y-1][x]=0
}
}
}
}
function random() {
var blank = 0
for (y = 0; y < 4; y++) {
for (x = 0; x < 4; x++) {
if (screen[y][x] == 0) {
blank++
}
}
}
var random = Math.floor(Math.random() * blank)
toast(random)
blank = 0
lab:
for (y = 0; y < 4; y++) {
for (x = 0; x < 4; x++) {
if (screen[y][x] == 0) {
if (blank == random) {
screen[y][x] = 2
break lab;
}
blank++
}
}
}
}
function clear() {
screen = new Array();
width = 4;
height = 4;
for (y = 0; y <= height; y++) {
screen[y] = new Array();
for (x = 0; x <= width; x++) {
screen[y][x] = 0;
}
}
}
function set(x, y, str) {
if (str == null) {
str = 0
}
if (y <= height && x <= width && y > 0 && x > 0) {
screen[round(y)][round(x)] = str
}
return arr
}
function toText(arr) {
var text = new String();
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
text = text + arr[y][x] + " "
}
text = text + "\n"
}
return String(text)
}