Skip to content

Commit 9aa6482

Browse files
committed
Correct behaviour of out of table dots
1 parent 0db639b commit 9aa6482

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pages/index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,19 @@ class Page extends React.Component {
9696
}
9797

9898
settleDots (dots) {
99-
const newMap = Array.from({length: 7}).map(_ =>
100-
Array.from({length: 7}).map(_ => null)
101-
)
99+
const newMap = {}
100+
for (let i = 0; i < 7; i++) {
101+
newMap[i] = {}
102+
for (let j = -1; j < 7; j++) {
103+
newMap[i][j] = null
104+
}
105+
}
102106
dots.forEach(d => {
103107
newMap[d.x][d.y] = d
104108
})
105109
for (let i = 0; i < 7; i++) {
106110
var firstFree = null
107-
for (let j = 6; j >= 0; j--) {
111+
for (let j = 6; j >= -1; j--) {
108112
if (!newMap[i][j] && firstFree === null) {
109113
firstFree = j
110114
}
@@ -117,12 +121,16 @@ class Page extends React.Component {
117121
}
118122

119123
cleanupDots (dots, cb) {
120-
const map = Array.from({length: 7}).map(_ =>
121-
Array.from({length: 7}).map(_ => null)
122-
)
123-
const keep = Array.from({length: 7}).map(_ =>
124-
Array.from({length: 7}).map(_ => true)
125-
)
124+
const map = {}
125+
const keep = {}
126+
for (let i = 0; i < 7; i++) {
127+
map[i] = {}
128+
keep[i] = {}
129+
for (let j = -1; j < 7; j++) {
130+
map[i][j] = null
131+
keep[i][j] = true
132+
}
133+
}
126134
dots.forEach(d => {
127135
map[d.x][d.y] = d
128136
})
@@ -141,14 +149,14 @@ class Page extends React.Component {
141149
}
142150
let freshDots = []
143151
for (let i = 0; i < 7; i++) {
144-
for (let j = 0; j < 7; j++) {
152+
for (let j = -1; j < 7; j++) {
145153
const l = checkTile(map[i][j])
146154
if (l.length > 2) {
147155
const newColoredDot = l.reduce((min, d) => {
148156
if (d.y > min.y) return d
149157
if (d.y === min.y && d.x < min.x) return d
150158
return min
151-
}, {x: 10, y: -1})
159+
}, {x: 10, y: -2})
152160

153161
freshDots.push(
154162
this.newDotAt(
@@ -214,7 +222,6 @@ class Page extends React.Component {
214222
}
215223
}
216224
})
217-
if (newDots.some(d => d.y < 0)) return this.gameOver()
218225
this.setState({
219226
...this.state,
220227
dots: inactiveDots.concat(newDots),
@@ -233,6 +240,7 @@ class Page extends React.Component {
233240
dots: newRun
234241
})
235242
if (oldRun.length === newRun.length) {
243+
if (newRun.some(d => d.y < 0)) return this.gameOver()
236244
return this.setState({
237245
...this.state,
238246
floatingDots: [this.newDot(4), this.newDot(5)]

0 commit comments

Comments
 (0)