Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { List } from 'immutable';
class Game extends Compoent {
constructor(props) {
super(props);
this.generateGame();
}
generateGame = (finalCount = 20) => {
// get a filled puzzle generated
const solution = makePuzzle();
// pluck values from cells to create the game
const { puzzle } = pluck(solution, finalCount);
// initialize the board with choice counts
const board = makeBoard({ puzzle });
this.setState({
board, history: List.of(board), historyOffSet: 0, solution,
});
}
updateBoard = (newBoard) => {
let { history } = this.state;
const { historyOffSet } = this.state;
// anything before current step is still in history
history = history.slice(0, historyOffSet + 1);
// add itself onto the history
history = history.push(newBoard);
// update the game
this.setState({ board: newBoard, history, historyOffSet: history.size - 1 });
};
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.