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.
26 lines
767 B
26 lines
767 B
require('immutable');
|
|
import * as MuncherActions from '../../actions/board/muncher.actions';
|
|
|
|
const reducer = (state = { x: 0, y: 0 }, action) => {
|
|
if (action.type !== MuncherActions.MUNCHER_ACTION) {
|
|
return state;
|
|
}
|
|
|
|
switch (action.action) {
|
|
case MuncherActions.LEFT:
|
|
return { x: state.x - 1, y: state.y };
|
|
case MuncherActions.RIGHT:
|
|
return { x: state.x + 1, y: state.y };
|
|
case MuncherActions.UP:
|
|
return { x: state.x, y: state.y - 1 };
|
|
case MuncherActions.DOWN:
|
|
return { x: state.x, y: state.y + 1 };
|
|
case MuncherActions.MUNCH:
|
|
console.log("Muncher's mouth moved!");
|
|
return state;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default reducer;
|
|
|