parent
faeae93892
commit
9b15298747
15 changed files with 101 additions and 109 deletions
@ -0,0 +1,66 @@ |
||||
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'; |
||||
|
||||
const level = 0; |
||||
let dispatch; |
||||
|
||||
const BoardCtrl = { |
||||
setDispatch: (d) => { |
||||
dispatch = d; |
||||
GridCtrl.setDispatch(d); |
||||
MuncherCtrl.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() { |
||||
GridCtrl.generateValues(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; |
@ -1,9 +1,9 @@ |
||||
let show = false; |
||||
|
||||
const MessageLogic = { |
||||
const MessageCtrl = { |
||||
hide: () => show = false, |
||||
show: () => show = true, |
||||
isShowing: () => show |
||||
}; |
||||
|
||||
export default MessageLogic; |
||||
export default MessageCtrl; |
@ -1,67 +0,0 @@ |
||||
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; |
Loading…
Reference in new issue