import * as MuncherActions from '../actions/board/muncher.actions'; import { SETTINGS } from '../App'; let x = 0; let y = 0; let dispatch; const MuncherCtrl = { getX: () => x, getY: () => y, setDispatch: d => dispatch = d, move: (e) => { switch (e.keyCode) { case 37: if (x !== 0) { x -= 1; dispatch(MuncherActions.update()); } break; case 38: if (y !== 0) { y -= 1; dispatch(MuncherActions.update()); } break; case 39: if (x !== SETTINGS.GRID_WIDTH - 1) { x += 1; dispatch(MuncherActions.update()); } break; case 40: if (y !== SETTINGS.GRID_HEIGHT - 1) { y += 1; dispatch(MuncherActions.update()); } break; } } }; export default MuncherCtrl;