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.
50 lines
1.1 KiB
50 lines
1.1 KiB
import * as MuncherActions from '../../actions/board/muncher.actions';
|
|
import BoardCtrl from './board.controller';
|
|
import SETTINGS from '../../AppSettings';
|
|
|
|
let x = 0;
|
|
let y = 0;
|
|
let dispatch;
|
|
|
|
const MuncherCtrl = {
|
|
getX: () => x,
|
|
getY: () => y,
|
|
setDispatch: d => dispatch = d,
|
|
|
|
move: (e) => {
|
|
e.preventDefault();
|
|
|
|
switch (e.keyCode) {
|
|
case 37:
|
|
if (x !== 0) {
|
|
x -= 1;
|
|
}
|
|
break;
|
|
|
|
case 38:
|
|
if (y !== 0) {
|
|
y -= 1;
|
|
}
|
|
break;
|
|
|
|
case 39:
|
|
if (x !== SETTINGS.GRID_WIDTH - 1) {
|
|
x += 1;
|
|
}
|
|
break;
|
|
|
|
case 40:
|
|
if (y !== SETTINGS.GRID_HEIGHT - 1) {
|
|
y += 1;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (e.keyCode >= 37 || e.keyCode <= 40) {
|
|
dispatch(MuncherActions.update(x, y));
|
|
BoardCtrl.checkCollision();
|
|
}
|
|
}
|
|
};
|
|
|
|
export default MuncherCtrl;
|
|
|