-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.full.html
119 lines (110 loc) · 3.01 KB
/
index.full.html
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
<script>
(function(){
var run = 0, imp = 0;
function up(){
run = 1;
var
pos = 2,
rows = [1,1,1,1,,,,1,1,1],
rowsLen = 10,
profit = 0,
hTop = 4,
row,
col,
timer = setInterval(function(){
/**
* Move user
*/
if (imp > 1) {
imp--;
// up
--pos || _stop();
} else if (imp) {
imp--;
} else {
// down
pos < 9 ? pos++ : _stop();
}
/**
* Move field
*
* ????010 - true -> 000011
* ???0110 - true -> 000111
* ??01110 - true -> 001111
* ?011110 - true -> 011111
* 0111110 - false
*/
for (row = rowsLen; row--;) {
rows[row] <<= 1;
if (rows[row] & 2) {
for (w = 1; 5 > w++;) {
if (!(rows[row] & 1 << w)) {
rows[row] |= 1;
break;
}
}
}
}
/**
* Add new objects
*
*
* 000011111 -> 0% (0 * 12.5) 0
* 000111110 -> 0% (0 * 12.5) 1
* 001111100 -> 12.5% (1 * 12.5) 2
* 011111000 -> 25.0% (2 * 12.5) 3
* 111110000 -> 37.5% (3 * 12.5) ..
* 111100000 -> 50.0% (4 * 12.5)
* 111000000 -> 62.5% (5 * 12.5)
* 110000000 -> 75.0% (6 * 12.5)
* 100000000 -> 87.5% (7 * 12.5)
* 000000000 -> 100.0% (8 * 12.5)
*/
for (var tryNum = 0;; tryNum++) {
if (rows[0] & 1 << tryNum) {
if (tryNum > 1 && (tryNum - 2) * 125 + profit > _rnd(124, 999)) {
hTop = _rnd(hTop > 2 ? hTop - 1 : 2, hTop < 5 ? hTop + 1 : 5); // 2..5, prev +/- 1
for (h = 0; h < hTop; h++) {
rows[h] |= 1;
}
for (h = hTop + 3; h < rowsLen; h++) {
rows[h] |= 1;
}
}
break;
}
}
/**
* Render
*/
var text = '';
for (row = 0; row < rowsLen; row++) {
for (col = 30; col--;) {
text += col == 28 && row == pos ? 0 : (
rows[row] & 1 << col ? "+" : (
!row || row == rowsLen - 1 ? "-" : " "
)
);
}
text += "\n";
}
profit += (rows[0] & 1 << 29) && !(rows[0] & 1 << 28) ? 1 : 0;
text += "\n"+profit;
P.innerHTML = text;
if (rows[pos] & 1 << 28) {
_stop();
}
}, 250);
var _rnd = function(min, max){
return ~~(Math.random() * (max - min + 1)) + min; // Math.floor(n) == ~~(n), n > 0
}
var _stop = function(){
clearInterval(timer);
run && alert(':(');
run = 0;
}
}
onkeyup = function(e){ e.which == 38 && (run ? imp = 3 : up()); };
})();
</script>
<body><pre id=P>press up!