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.
 
 

35 lines
999 B

/**
* THIS is the Board class.
*/
module.exports = {
keydown(e) {
var x = this.refs.muncher.state.x;
var y = this.refs.muncher.state.y;
switch (e.keyCode) {
case 32:
this.refs.grid.munch(x, y);
break;
case 37: // Left arrow
if (x > 0) {
this.refs.muncher.setState({ x: x - 1 });
}
break;
case 38: // Up arrow
if (y > 0) {
this.refs.muncher.setState({ y: y - 1 });
}
break;
case 39: // Right arrow
if (x < this.refs.grid.props.width - 1) {
this.refs.muncher.setState({ x: x + 1 });
}
break;
case 40: // Down arrow
if (y < this.refs.grid.props.height - 1) {
this.refs.muncher.setState({ y: y + 1 });
}
}
}
};