parent
697ef18407
commit
49baf89a5e
10 changed files with 134 additions and 93 deletions
@ -1,68 +1,32 @@ |
|||||||
require('../../sass/board/troggle.scss'); |
require('../../sass/board/troggle.scss'); |
||||||
|
|
||||||
import { Component } from 'react'; |
import { Component } from 'react'; |
||||||
|
import { connect } from 'react-redux'; |
||||||
|
|
||||||
const troggleMoveTimers = []; |
import Troggle from './troggle.component'; |
||||||
const troggleCreateTimers = []; |
import TroggleLogic from '../../logic/troggle.logic.js'; |
||||||
|
|
||||||
export default class Troggles extends Component { |
export class Troggles extends Component { |
||||||
componentWillUnmount() { |
componentWillUnmount() { |
||||||
// this.clearTroggleTimers();
|
TroggleLogic.clearTimers(); |
||||||
} |
}; |
||||||
|
|
||||||
// clearTroggleTimers() {
|
|
||||||
// troggleMoveTimers.forEach((timer) => {
|
|
||||||
// clearTimeout(timer);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// troggleCreateTimers.forEach((timer) => {
|
|
||||||
// clearTimeout(timer);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// createTroggle(index) {
|
|
||||||
// const newCoords = TroggleAI.create();
|
|
||||||
// this.props.dispatch(TroggleActions.create(newCoords.x, newCoords.y));
|
|
||||||
// troggleMoveTimers.push(setTimeout(this.moveTroggle.bind(this, index), 1000));
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// createTroggles() {
|
|
||||||
// const troggleCount = 3; //Math.min(Math.ceil(this.props.board.level / 2), 5);
|
|
||||||
// for (let i = 0; i < troggleCount; i++) {
|
|
||||||
// setTimeout(this.createTroggle.bind(this, i), (i + 1) * 5000);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// moveTroggle(index) {
|
|
||||||
// const newCoords = TroggleAI.move(
|
|
||||||
// this.props.troggles[index].x,
|
|
||||||
// this.props.troggles[index].y,
|
|
||||||
// this.props.muncher.x,
|
|
||||||
// this.props.muncher.y
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// if (newCoords.x === this.props.muncher.x && newCoords.y === this.props.muncher.y) {
|
|
||||||
// this.props.dispatch(MessageActions.show("You've been eaten by a troggle!"));
|
|
||||||
// this.props.dispatch(TroggleActions.clearAll());
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// this.props.dispatch(TroggleActions.move(index, newCoords.x, newCoords.y));
|
|
||||||
// clearTimeout(troggleMoveTimers[index]);
|
|
||||||
// troggleMoveTimers[index] = setTimeout(this.moveTroggle.bind(this, index), 1000);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
render() { |
render() { |
||||||
const classname = ['troggle', 'x' + this.props.x, 'y' + this.props.y]; |
const { troggles, muncher } = this.props; |
||||||
|
|
||||||
// const troggleElements = [];
|
const troggleElements = Array.from(Array(troggles.length), (v, i) => { |
||||||
// for (let i = 0; i < troggles.length; i++) {
|
return <Troggle x={troggles[i].x} y={troggles[i].y} mx={muncher.x} my={muncher.y} key={i} />; |
||||||
// troggleElements[i] = <Troggle x={troggles[i].x} y={troggles[i].y} key={i} />;
|
}); |
||||||
// }
|
|
||||||
// {troggleElements}
|
|
||||||
|
|
||||||
return ( |
return <div className='troggles'>{troggleElements}</div> |
||||||
<div className={classname.join(' ')}></div> |
|
||||||
); |
|
||||||
}; |
}; |
||||||
}; |
}; |
||||||
|
|
||||||
|
const select = (state) => { |
||||||
|
return { |
||||||
|
troggles: state.troggles, |
||||||
|
muncher: state.muncher |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
export default connect(select)(Troggles); |
||||||
|
Loading…
Reference in new issue