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.
43 lines
1.1 KiB
43 lines
1.1 KiB
import * as MuncherActions from '../../actions/board/muncher.actions';
|
|
import { SETTINGS } from '../../App';
|
|
|
|
const initial = { x: 0, y: 0 };
|
|
|
|
const reducer = (state = initial, action) => {
|
|
if (action.type !== MuncherActions.MUNCHER_ACTION) {
|
|
return state;
|
|
}
|
|
|
|
switch (action.action) {
|
|
case MuncherActions.LEFT:
|
|
if (state.x === 0) {
|
|
return state;
|
|
}
|
|
return { x: state.x - 1, y: state.y };
|
|
|
|
case MuncherActions.RIGHT:
|
|
if (state.x === SETTINGS.GRID_WIDTH - 1) {
|
|
return state;
|
|
}
|
|
return { x: state.x + 1, y: state.y };
|
|
|
|
case MuncherActions.UP:
|
|
if (state.y === 0) {
|
|
return state;
|
|
}
|
|
return { x: state.x, y: state.y - 1 };
|
|
|
|
case MuncherActions.DOWN:
|
|
if (state.y === SETTINGS.GRID_HEIGHT - 1) {
|
|
return state;
|
|
}
|
|
return { x: state.x, y: state.y + 1 };
|
|
|
|
case MuncherActions.MUNCH:
|
|
return state;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default reducer;
|
|
|