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.
67 lines
2.0 KiB
67 lines
2.0 KiB
import { SETTINGS } from '../App.js';
|
|
|
|
import * as ScorebarActions from '../actions/board/scorebar.actions';
|
|
import * as MessageActions from '../actions/board/message.actions';
|
|
|
|
import TroggleLogic from './troggle.logic';
|
|
import MessageLogic from './message.logic';
|
|
import MuncherLogic from './muncher.logic';
|
|
import GridLogic from './grid.logic';
|
|
|
|
const level = 0;
|
|
let dispatch;
|
|
|
|
const BoardLogic = {
|
|
setDispatch: (d) => {
|
|
dispatch: d,
|
|
GridLogic.setDispatch(d);
|
|
MuncherLogic.setDispatch(d);
|
|
},
|
|
|
|
munch() {
|
|
const index = MuncherLogic.getY() * SETTINGS.GRID_WIDTH + MuncherLogic.getX();
|
|
|
|
if (GridLogic.getValues()[index].valid) {
|
|
GridLogic.hideValue(index);
|
|
|
|
if (GridLogic.isCompleted() === true) {
|
|
dispatch(MessageActions.exclaim());
|
|
}
|
|
}
|
|
else {
|
|
const msg = Values.getError(values[index].value, level);
|
|
dispatch(MessageActions.show(msg));
|
|
}
|
|
},
|
|
|
|
keyListener(e) {
|
|
if (e.keyCode === 32 && GridLogic.isCompleted() === true) {
|
|
this.nextLevel();
|
|
dispatch(MessageActions.hide());
|
|
}
|
|
else if (e.keyCode === 32 && MessageLogic.isShowing() === true) {
|
|
dispatch(MessageActions.hide());
|
|
}
|
|
else if (e.keyCode === 32 && MessageLogic.isShowing() === false) {
|
|
this.munch();
|
|
}
|
|
else if (MessageLogic.isShowing() === false) {
|
|
MuncherLogic.move(e);
|
|
}
|
|
},
|
|
|
|
nextLevel() {
|
|
GridLogic.generateValues(level);
|
|
// TroggleLogic.clearAll(this.props.dispatch);
|
|
// TroggleLogic.createTroggles(this.props.dispatch);
|
|
},
|
|
|
|
// if (troggles[i].x === muncher.x && troggles[i].y === muncher.y) {
|
|
// this.props.dispatch(MessageActions.show("You've been eaten by a troggle!"));
|
|
// this.props.dispatch(ScorebarActions.munchFailed());
|
|
// TroggleLogic.frozen = true;
|
|
// ReactDOM.findDOMNode(this.refs.message).focus();
|
|
// }
|
|
};
|
|
|
|
export default BoardLogic;
|
|
|