Skip to content

Commit eedb0d1

Browse files
committed
Update logic of creating new dots
1 parent e688319 commit eedb0d1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

pages/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Levels = ({current}) => {
4343
flexDirection: 'column-reverse'
4444
}}>
4545
{colors.map((c, i) => {
46-
return <div style={{
46+
return <div key={c} style={{
4747
background: c,
4848
opacity: current >= i ? 1 : 0.2,
4949
width: `${width / colors.length}px`,
@@ -142,17 +142,20 @@ class Page extends React.Component {
142142
for (let j = 0; j < 7; j++) {
143143
const l = checkTile(map[i][j])
144144
if (l.length > 2) {
145-
const newColoredDot = Math.floor(Math.random() * l.length)
145+
const newColoredDot = l.reduce((min, d) => {
146+
if (d.y > min.y) return d
147+
if (d.y === min.y && d.x < min.x) return d
148+
return min
149+
}, {x: 10, y: -1})
150+
151+
freshDots.push(
152+
this.newDotAt(
153+
newColoredDot.x,
154+
newColoredDot.y,
155+
newColoredDot.type + 1
156+
)
157+
)
146158
l.forEach((d, i) => {
147-
if (i === newColoredDot) {
148-
freshDots.push(
149-
this.newDotAt(
150-
d.x,
151-
d.y,
152-
Math.floor(Math.random() * (this.state.level + 1))
153-
)
154-
)
155-
}
156159
keep[d.x][d.y] = false
157160
})
158161
this.state.blocksKilled++

0 commit comments

Comments
 (0)