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
1.0 KiB
35 lines
1.0 KiB
const Immutable = require('immutable');
|
|
import * as MuncherActions from '../../actions/board/muncher.actions';
|
|
import { SETTINGS } from '../../App';
|
|
|
|
const initial = { x: 0, y: 0, frozen: false };
|
|
|
|
const reducer = (state = initial, action) => {
|
|
if (action.type !== MuncherActions.MUNCHER_ACTION) {
|
|
return state;
|
|
}
|
|
|
|
switch (action.action) {
|
|
case MuncherActions.LEFT:
|
|
return Immutable.Map(state).set('x', state.x - 1).toObject();
|
|
|
|
case MuncherActions.RIGHT:
|
|
return Immutable.Map(state).set('x', state.x + 1).toObject();
|
|
|
|
case MuncherActions.UP:
|
|
return Immutable.Map(state).set('y', state.y - 1).toObject();
|
|
|
|
case MuncherActions.DOWN:
|
|
return Immutable.Map(state).set('y', state.y + 1).toObject();
|
|
|
|
case MuncherActions.FREEZE:
|
|
return Immutable.Map(state).set('frozen', true).toObject();
|
|
|
|
case MuncherActions.UNFREEZE:
|
|
return Immutable.Map(state).set('frozen', false).toObject();
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default reducer;
|
|
|