diff --git a/App.js b/App.js
index 91a9d74..c0be2cb 100644
--- a/App.js
+++ b/App.js
@@ -7,8 +7,8 @@ import Board from './components/board/board.component';
import Welcome from './components/welcome/welcome.component';
export const SETTINGS = {
- GRID_WIDTH: 3,
- GRID_HEIGHT: 3,
+ GRID_WIDTH: 6,
+ GRID_HEIGHT: 5,
LIVES: 3
};
diff --git a/actions/board/message.actions.js b/actions/board/message.actions.js
index 243b076..d8ee854 100644
--- a/actions/board/message.actions.js
+++ b/actions/board/message.actions.js
@@ -2,12 +2,10 @@ export const MESSAGE_ACTION = 'MESSAGE_ACTION';
export const DISPLAY = 'DISPLAY';
export const HIDE = 'HIDE';
-export const display = (line1, line2, hidden) => ({
+export const display = (message) => ({
type: MESSAGE_ACTION,
action: DISPLAY,
- line1: line1,
- line2: line2,
- hidden: hidden
+ message: message
});
export const hide = () => ({
diff --git a/actions/board/muncher.actions.js b/actions/board/muncher.actions.js
index 35d7af5..6ba10cc 100644
--- a/actions/board/muncher.actions.js
+++ b/actions/board/muncher.actions.js
@@ -4,6 +4,8 @@ export const RIGHT = 'RIGHT';
export const UP = 'UP';
export const DOWN = 'DOWN';
export const MUNCH = 'MUNCH';
+export const FREEZE = 'FREEZE';
+export const UNFREEZE = 'UNFREEZE';
export const moveLeft = () => ({
type: MUNCHER_ACTION,
@@ -29,3 +31,13 @@ export const munch = (x, y) => ({
type: MUNCHER_ACTION,
action: MUNCH
});
+
+export const freeze = () => ({
+ type: MUNCHER_ACTION,
+ action: FREEZE
+});
+
+export const unfreeze = () => ({
+ type: MUNCHER_ACTION,
+ action:UNFREEZE
+});
diff --git a/actions/board/troggle.actions.js b/actions/board/troggle.actions.js
new file mode 100644
index 0000000..bc0486e
--- /dev/null
+++ b/actions/board/troggle.actions.js
@@ -0,0 +1,16 @@
+export const TROGGLE_ACTION = 'TROGGLE_ACTION';
+export const CREATE = 'CREATE';
+export const MOVE = 'MOVE';
+
+export const create = () => ({
+ type: TROGGLE_ACTION,
+ action: CREATE
+});
+
+export const move = (index, muncherX, muncherY) => ({
+ type: TROGGLE_ACTION,
+ action: MOVE,
+ index: index,
+ muncherX: muncherX,
+ muncherY: muncherY
+});
diff --git a/components/board/board.component.js b/components/board/board.component.js
index c76977b..a077654 100644
--- a/components/board/board.component.js
+++ b/components/board/board.component.js
@@ -8,14 +8,16 @@ import Titlebar from './titlebar.component';
import Grid from './grid.component';
import Message from './message.component';
import Muncher from './muncher.component';
+import Troggle from './troggle.component';
import Values from '../../reducers/Values';
import { SETTINGS } from '../../App';
import * as BoardActions from '../../actions/board/board.actions';
-import * as MuncherActions from '../../actions/board/muncher.actions';
import * as ScorebarActions from '../../actions/board/scorebar.actions';
import * as MessageActions from '../../actions/board/message.actions';
+import * as MuncherActions from '../../actions/board/muncher.actions';
+import * as TroggleActions from '../../actions/board/troggle.actions';
const exclamations = [
'Congratulations!',
@@ -28,95 +30,101 @@ const exclamations = [
'Shazam!'
];
-let muncherListener = null;
-let messageListener = null;
-
-export default class Board extends Component {
- componentDidMount(n) {
- muncherListener = this.muncherKeydown.bind(this);
- messageListener = this.messageKeydown.bind(this);
+const troggleMoveTimers = [];
+const troggleCreateTimers = [];
- window.addEventListener('keydown', muncherListener);
- // window.addEventListener('keydown', messageListener);
+// const toggleMoveTimeout = function() {
+// this.props.dispatch(TroggleActions.move());
+// };
- this.props.dispatch(BoardActions.nextLevel());
- };
+const continuations = {
+ muncher: null,
+ message: null
+};
- muncherKeydown(e) {
- switch (e.keyCode) {
- case 32:
- this.munch();
- break;
+let listener = null;
- case 37:
- this.props.dispatch(MuncherActions.moveLeft());
- break;
+export default class Board extends Component {
+ nextLevel() {
+ this.props.dispatch(BoardActions.nextLevel());
- case 38:
- this.props.dispatch(MuncherActions.moveUp());
- break;
+ const troggleCount = 1; //Math.min(Math.ceil(this.props.board.level / 2), 5);
+ for (let i = 0; i < troggleCount; i++) {
+ this.props.dispatch(TroggleActions.create());
+ troggleMoveTimers.push(setTimeout(this.moveTroggle.bind(this, i), 1000));
+ }
- case 39:
- this.props.dispatch(MuncherActions.moveRight());
- break;
+ // toggleTimeout.call(this);
+ };
- case 40:
- this.props.dispatch(MuncherActions.moveDown());
- break;
- }
+ componentDidMount() {
+ listener = this.keydown.bind(this);
+ window.addEventListener('keydown', listener);
+ this.nextLevel();
};
- messageKeydown(e) {
- if (e.keyCode === 32) {
- window.removeEventListener('keydown', messageListener);
- window.addEventListener('keydown', muncherListener);
+ componentWillUnmount() {
+ window.removeEventListener('keydown', listener);
- this.props.dispatch(MessageActions.hide());
- }
+ // destroy all troggle timers
};
- componentWillUnmount() {
- window.removeEventListener('keydown', muncherListener);
- window.removeEventListener('keydown', messageListener);
+ moveTroggle(index) {
+ this.props.dispatch(TroggleActions.move(index));
+ clearTimeout(troggleMoveTimers[index]);
+ troggleMoveTimers[index] = setTimeout(this.moveTroggle.bind(this, index), 1000);
};
- munch() {
- const { board, muncher, dispatch } = this.props;
- const index = muncher.y * SETTINGS.GRID_HEIGHT + muncher.x;
+ // Keydown listener for spacebar, since it is bound to munch event and
+ // message hide event. Couldn't find a more modular way to do this.
+ keydown(e) {
+ if (e.keyCode !== 32) {
+ return;
+ }
- dispatch(MuncherActions.munch());
+ if (this.props.message.hidden === false) {
+ this.props.dispatch(MessageActions.hide());
+ this.props.dispatch(MuncherActions.unfreeze());
- if (board.values[index].valid) {
- dispatch(BoardActions.hideValue(index));
- dispatch(ScorebarActions.munchSucceeded());
+ if (Values.checkComplete(this.props.board.values, this.props.board.level)) {
+ console.warn("NEXT LEVEL")
+ }
}
else {
- window.removeEventListener('keydown', muncherListener);
- window.addEventListener('keydown', messageListener);
-
- const msg = Values.getError(board.values[index].value, board.level);
- dispatch(MessageActions.display(msg, 'Press Spacebar to Continue'));
- dispatch(ScorebarActions.munchFailed());
- }
-
- if (Values.checkComplete(this.props.board.values, board.level)) {
- window.removeEventListener('keydown', muncherListener);
- window.addEventListener('keydown', messageListener);
-
- const msg = exclamations[Math.floor(Math.random() * exclamations.length)];
- dispatch(MessageActions.display(msg, 'Press Spacebar to Continue'));
- dispatch(BoardActions.nextLevel());
+ const index = this.props.muncher.y * SETTINGS.GRID_HEIGHT + this.props.muncher.x
+ const { board, dispatch } = this.props;
+
+ if (board.values[index].valid) {
+ dispatch(BoardActions.hideValue(index));
+ dispatch(ScorebarActions.munchSucceeded());
+ }
+ else {
+ const msg = Values.getError(board.values[index].value, board.level);
+ dispatch(MessageActions.display(msg));
+ dispatch(ScorebarActions.munchFailed());
+ dispatch(MuncherActions.freeze());
+ }
+
+ if (Values.checkComplete(this.props.board.values, board.level)) {
+ const msg = exclamations[Math.floor(Math.random() * exclamations.length)];
+ dispatch(MessageActions.display(msg));
+ }
}
};
render() {
- const { board, muncher, message } = this.props;
+ const { board, message, troggles } = this.props;
+ const troggleElements = [];
+ for (let i = 0; i < troggles.length; i++) {
+ troggleElements.push(