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.
70 lines
2.1 KiB
70 lines
2.1 KiB
import { SETTINGS } from '../App.js';
|
|
|
|
import * as ScorebarActions from '../actions/board/scorebar.actions';
|
|
import * as MessageActions from '../actions/board/message.actions';
|
|
|
|
import TroggleCtrl from './troggle.controller';
|
|
import MessageCtrl from './message.controller';
|
|
import MuncherCtrl from './muncher.controller';
|
|
import GridCtrl from './grid.controller';
|
|
import TitlebarCtrl from './titlebar.controller';
|
|
|
|
let level = -1;
|
|
let dispatch;
|
|
|
|
const BoardCtrl = {
|
|
setDispatch: (d) => {
|
|
dispatch = d;
|
|
GridCtrl.setDispatch(d);
|
|
MuncherCtrl.setDispatch(d);
|
|
TitlebarCtrl.setDispatch(d);
|
|
},
|
|
|
|
munch() {
|
|
const index = MuncherCtrl.getY() * SETTINGS.GRID_WIDTH + MuncherCtrl.getX();
|
|
|
|
if (GridCtrl.getValues()[index].valid) {
|
|
GridCtrl.hideValue(index);
|
|
|
|
if (GridCtrl.isCompleted() === true) {
|
|
dispatch(MessageActions.exclaim());
|
|
}
|
|
}
|
|
else {
|
|
dispatch(MessageActions.show(`Uh oh - ${GridCtrl.getValues()[index].value} is not a match.`));
|
|
}
|
|
},
|
|
|
|
keyListener(e) {
|
|
if (e.keyCode === 32 && GridCtrl.isCompleted() === true) {
|
|
this.nextLevel();
|
|
dispatch(MessageActions.hide());
|
|
}
|
|
else if (e.keyCode === 32 && MessageCtrl.isShowing() === true) {
|
|
dispatch(MessageActions.hide());
|
|
}
|
|
else if (e.keyCode === 32 && MessageCtrl.isShowing() === false) {
|
|
this.munch();
|
|
}
|
|
else if (MessageCtrl.isShowing() === false) {
|
|
MuncherCtrl.move(e);
|
|
}
|
|
},
|
|
|
|
nextLevel() {
|
|
level++;
|
|
GridCtrl.generateValues(level);
|
|
TitlebarCtrl.setTitle(level);
|
|
// TroggleCtrl.clearAll(this.props.dispatch);
|
|
// TroggleCtrl.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());
|
|
// TroggleCtrl.frozen = true;
|
|
// ReactDOM.findDOMNode(this.refs.message).focus();
|
|
// }
|
|
};
|
|
|
|
export default BoardCtrl;
|
|
|