You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
var React = require('react');
|
|
var Cell = require('./Cell');
|
|
var Character = require('./Character');
|
|
var UserInput = require('./Input');
|
|
var Values = require('./Values');
|
|
var Game = require('./Game');
|
|
|
|
module.exports = React.createClass({
|
|
generateValues() {
|
|
return Values.generate(this.props.width * this.props.height, Game.level);
|
|
},
|
|
|
|
getInitialState() {
|
|
return {
|
|
values: this.generateValues()
|
|
};
|
|
},
|
|
|
|
componentDidMount() {
|
|
window.addEventListener('keydown', UserInput.keydown.bind(this));
|
|
},
|
|
|
|
munch(x, y) {
|
|
var i = y * this.props.width + x;
|
|
|
|
if (this.state.values[i] === "") {
|
|
return;
|
|
}
|
|
|
|
if (Values.validate(this.state.values[i], Game.level)) {
|
|
this.state.values[i] = "";
|
|
this.setState({ values: this.state.values });
|
|
}
|
|
|
|
if (Game.checkWin(this.state.values) === true) {
|
|
Game.state.nextLevel();
|
|
this.setState({ values: this.generateValues() });
|
|
}
|
|
//Game.checkLoss();
|
|
},
|
|
|
|
render() {
|
|
var cells = [];
|
|
var i;
|
|
|
|
for (var x = 0; x < this.props.width; x++) {
|
|
for (var y = 0; y < this.props.height; y++) {
|
|
i = y * this.props.width + x;
|
|
cells.push(<Cell value={this.state.values[i]} x={x} y={y} key={i} />);
|
|
}
|
|
}
|
|
|
|
return (<div>
|
|
{cells}
|
|
<Character ref='ourhero1' />
|
|
</div>);
|
|
}
|
|
});
|
|
|