Last active
April 13, 2018 08:08
-
-
Save VivienAdnot/6e6e863f43dfe0b1c58a9960d33761de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const buildMap = (bombPositions) => { | |
let positions = Array.from({length: 10}, (value, x) => { | |
return Array.from({length: 10}, (value, y) => { | |
return { | |
position: {x, y}, | |
value: (isPositionBomb(bombPositions, {x, y}) | |
? 'B' | |
: getNeighborBombPositions(bombPositions, {x, y}).length | |
), | |
visibility: 'hidden' // visible, marked | |
}; | |
}); | |
}); | |
return positions; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Board extends Component { | |
constructor(props) { | |
super(props); | |
this.bombPositions = buildBombPositions(); | |
this.state = { | |
boardMap: buildMap(this.bombPositions), | |
gameStatus: 'playing' //won, lost | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onSquareLeftClick = (position) => { | |
this.setState((prevState) => { | |
prevState.boardMap[position.x][position.y].visibility = 'visible'; | |
return { | |
boardMap: prevState.boardMap | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment