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.
99 lines
3.3 KiB
99 lines
3.3 KiB
require('../../sass/board/board.scss');
|
|
|
|
import { Component } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { getState } from 'react-redux';
|
|
import Scorebar from './scorebar.component';
|
|
import Titlebar from './titlebar.component';
|
|
import Grid from './grid.component';
|
|
import Message from './message.component';
|
|
import Muncher from './muncher.component';
|
|
import Troggles from './troggles.component';
|
|
|
|
import ValuesLogic from '../../logic/values.logic.js';
|
|
// import TroggleAI from '../../reducers/TroggleAI';
|
|
import { SETTINGS } from '../../App';
|
|
|
|
import * as BoardActions from '../../actions/board/board.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';
|
|
|
|
let listener = null;
|
|
let nextLevelFlag = false;
|
|
|
|
export default class Board extends Component {
|
|
refocus() {
|
|
this.props.dispatch(MessageActions.hide());
|
|
ReactDOM.findDOMNode(this.refs.muncher).focus();
|
|
};
|
|
|
|
componentDidMount() {
|
|
ReactDOM.findDOMNode(this.refs.muncher).focus();
|
|
listener = this.refocus.bind(this);
|
|
window.addEventListener('click', listener);
|
|
this.nextLevel();
|
|
};
|
|
|
|
componentWillUnmount() {
|
|
window.removeEventListener('keydown', listener);
|
|
};
|
|
|
|
nextLevel() {
|
|
this.props.dispatch(BoardActions.nextLevel());
|
|
// this.props.dispatch(TroggleActions.clearAll());
|
|
// this.clearTroggleTimers();
|
|
// this.createTroggles();
|
|
};
|
|
|
|
messageNext() {
|
|
if (nextLevelFlag === true) {
|
|
this.nextLevel();
|
|
nextLevelFlag = false;
|
|
}
|
|
this.props.dispatch(MessageActions.hide());
|
|
ReactDOM.findDOMNode(this.refs.muncher).focus();
|
|
};
|
|
|
|
muncherNext(x, y) {
|
|
const index = y * SETTINGS.GRID_WIDTH + x;
|
|
|
|
if (this.props.values[index].valid) {
|
|
this.props.dispatch(BoardActions.hideValue(index));
|
|
this.props.dispatch(ScorebarActions.munchSucceeded());
|
|
|
|
// State will not have been updated; temporary state created for checking.
|
|
const tmp = this.props.values.slice(0);
|
|
tmp[index].show = false;
|
|
if (ValuesLogic.checkComplete(tmp, this.props.level)) {
|
|
nextLevelFlag = true;
|
|
this.props.dispatch(MessageActions.exclaim());
|
|
ReactDOM.findDOMNode(this.refs.message).focus();
|
|
}
|
|
}
|
|
else {
|
|
const msg = ValuesLogic.getError(this.props.values[index].value, this.props.level);
|
|
this.props.dispatch(MessageActions.show(msg));
|
|
this.props.dispatch(ScorebarActions.munchFailed());
|
|
ReactDOM.findDOMNode(this.refs.message).focus();
|
|
}
|
|
|
|
};
|
|
|
|
render() {
|
|
return (<div className='board'>
|
|
<Scorebar />
|
|
<Titlebar title={this.props.title} />
|
|
<Message ref='message' next={this.messageNext.bind(this)} />
|
|
<Grid values={this.props.values} />
|
|
<Muncher ref='muncher' onMunch={this.muncherNext.bind(this)} />
|
|
</div>);
|
|
};
|
|
};
|
|
|
|
const select = (state) => {
|
|
return state.board;
|
|
}
|
|
|
|
export default connect(select)(Board);
|
|
|