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
978 B
35 lines
978 B
var Grid = require('./Grid');
|
|
|
|
module.exports = {
|
|
|
|
keydown: function(e) {
|
|
var x = this.refs.ourhero1.state.x;
|
|
var y = this.refs.ourhero1.state.y;
|
|
|
|
switch (e.keyCode) {
|
|
case 32:
|
|
this.munch(x, y);
|
|
break;
|
|
|
|
case 37: // Left arrow
|
|
if (x > 0) {
|
|
this.refs.ourhero1.setState({ x: x - 1 });
|
|
}
|
|
break;
|
|
case 38: // Up arrow
|
|
if (y > 0) {
|
|
this.refs.ourhero1.setState({ y: y - 1 });
|
|
}
|
|
break;
|
|
case 39: // Right arrow
|
|
x < 2 ?
|
|
this.refs.ourhero1.setState({ x: x + 1 }) :
|
|
this.refs.ourhero1.setState({ x: 0 })
|
|
break;
|
|
case 40: // Down arrow
|
|
if (y < 2) {
|
|
this.refs.ourhero1.setState({ y: y + 1 });
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|