parent
be7f760ccd
commit
c34013313e
13 changed files with 224 additions and 98 deletions
@ -1,8 +1,23 @@ |
||||
export const MODE = { |
||||
WELCOME: 'WELCOME', |
||||
BOARD: 'BOARD' |
||||
BOARD: 'BOARD', |
||||
NEXT: 'NEXT' |
||||
}; |
||||
|
||||
export const ACTIONS = { |
||||
NEXT: 'NEXT' |
||||
export const BLINK = { |
||||
TOGGLE: 'TOGGLE' |
||||
}; |
||||
|
||||
export const VALUES = { |
||||
FOO: 'FOO', |
||||
GENERATE: 'GENERATE', |
||||
UPDATE: 'UPDATE' |
||||
}; |
||||
|
||||
export const MUNCHER = { |
||||
MOVE: 'MOVE', |
||||
LEFT: 'LEFT', |
||||
RIGHT: 'RIGHT', |
||||
UP: 'UP', |
||||
DOWN: 'DOWN' |
||||
}; |
||||
|
@ -1,4 +1,29 @@ |
||||
import { ACTIONS } from './Constants'; |
||||
import { MODE, BLINK, VALUES, MUNCHER } from './Constants'; |
||||
|
||||
export const nextMode = |
||||
() => ({ type: ACTIONS.NEXT }); |
||||
() => ({ type: MODE.NEXT }); |
||||
|
||||
export const toggleBlink = |
||||
() => ({ type: BLINK.TOGGLE }); |
||||
|
||||
export const generateValues = |
||||
(count, level) => ({ |
||||
type: VALUES.FOO, |
||||
action: VALUES.GENERATE, |
||||
count: count, |
||||
level: level |
||||
}); |
||||
|
||||
export const updateValues = |
||||
(i, level) => ({ |
||||
type: VALUES.FOO, |
||||
action: VALUES.UPDATE, |
||||
index: i, |
||||
level: level |
||||
}); |
||||
|
||||
export const moveMuncher = |
||||
(direction) => ({ |
||||
type: MUNCHER.MOVE, |
||||
direction: direction |
||||
}); |
||||
|
@ -0,0 +1,4 @@ |
||||
export const GRID = { |
||||
W: 3, |
||||
H: 3 |
||||
} |
@ -1,21 +1,69 @@ |
||||
require('../../sass/board/muncher.scss'); |
||||
|
||||
import { Component } from 'react'; |
||||
import { connect } from 'react-redux'; |
||||
import { MUNCHER } from '../app/Constants'; |
||||
import * as creators from '../app/Creators'; |
||||
|
||||
export default class Muncher extends Component{ |
||||
// getInitialState() {
|
||||
// return {
|
||||
// x: 0,
|
||||
// y: 0
|
||||
// };
|
||||
// },
|
||||
let listener = null; |
||||
|
||||
export class Muncher extends Component { |
||||
keydown(e) { |
||||
const x = this.props.x; |
||||
const y = this.props.y; |
||||
|
||||
switch (e.keyCode) { |
||||
case 32: |
||||
console.warn('munch (leave this here until sure event listener has been removed'); |
||||
this.props.dispatch(creators.updateValues(0, 0)); |
||||
// var i = y * this.props.width + x;
|
||||
//
|
||||
// this.setState({ values: this.state.values }, this.checkComplete);
|
||||
// State.publish('munch/successful');
|
||||
// }
|
||||
// else {
|
||||
// State.publish('munch/failed', this.state.values[i]);
|
||||
// }
|
||||
break; |
||||
|
||||
case 37: |
||||
this.props.dispatch(creators.moveMuncher(MUNCHER.LEFT)); |
||||
break; |
||||
case 38: |
||||
this.props.dispatch(creators.moveMuncher(MUNCHER.UP)); |
||||
break; |
||||
case 39: |
||||
this.props.dispatch(creators.moveMuncher(MUNCHER.RIGHT)); |
||||
break; |
||||
case 40: |
||||
this.props.dispatch(creators.moveMuncher(MUNCHER.DOWN)); |
||||
break; |
||||
} |
||||
}; |
||||
|
||||
componentDidMount() { |
||||
listener = this.keydown.bind(this); |
||||
window.addEventListener('keydown', listener); |
||||
}; |
||||
|
||||
componentWillUnmount() { |
||||
window.removeEventListener('keydown', listener); |
||||
}; |
||||
|
||||
render() { |
||||
// const classname = ['muncher', 'x' + this.state.x, 'y' + this.state.y];
|
||||
const classname = ['muncher', 'x' + this.props.x, 'y' + this.props.y]; |
||||
|
||||
return ( |
||||
<div className='muncher'></div> |
||||
// <div className={classname.join(' ')}></div>
|
||||
<div className={classname.join(' ')}></div> |
||||
); |
||||
}; |
||||
}; |
||||
|
||||
const select = (state) => { |
||||
return { |
||||
x: state.muncher.x, |
||||
y: state.muncher.y |
||||
} |
||||
}; |
||||
|
||||
export default connect(select)(Muncher); |
||||
|
Loading…
Reference in new issue