parent
0296107742
commit
be7f760ccd
23 changed files with 337 additions and 288 deletions
@ -1,33 +0,0 @@ |
||||
var State = require('./State'); |
||||
var actions = Object.create(null); |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
module.exports = { |
||||
level: 0, |
||||
|
||||
subscribe(event, callback) { |
||||
if (actions[event] === undefined) { |
||||
actions[event] = []; |
||||
} |
||||
|
||||
actions[event].push(callback); |
||||
}, |
||||
|
||||
publish(event) { |
||||
if (actions[event] === undefined) { |
||||
return; |
||||
} |
||||
|
||||
var args = Array.prototype.slice.call(arguments, 1); |
||||
|
||||
actions[event].forEach(function(callback) { |
||||
callback.apply(null, args); |
||||
}); |
||||
} |
||||
}; |
||||
|
||||
module.exports.subscribe('level/complete', function() { |
||||
module.exports.level++; |
||||
}); |
@ -0,0 +1,27 @@ |
||||
import React, { Component } from 'react'; |
||||
import { connect } from 'react-redux'; |
||||
|
||||
import Board from '../board/Board'; |
||||
import Welcome from '../welcome/Welcome'; |
||||
import { MODE } from './Constants'; |
||||
|
||||
export class App extends Component { |
||||
render() { |
||||
const { mode } = this.props; |
||||
|
||||
switch (mode) { |
||||
case MODE.WELCOME: |
||||
return <Welcome />; |
||||
case MODE.BOARD: |
||||
return <Board />; |
||||
} |
||||
}; |
||||
}; |
||||
|
||||
const select = (state) => { |
||||
return { |
||||
mode: state.mode |
||||
} |
||||
}; |
||||
|
||||
export default connect(select)(App); |
@ -0,0 +1,8 @@ |
||||
export const MODE = { |
||||
WELCOME: 'WELCOME', |
||||
BOARD: 'BOARD' |
||||
}; |
||||
|
||||
export const ACTIONS = { |
||||
NEXT: 'NEXT' |
||||
}; |
@ -0,0 +1,4 @@ |
||||
import { ACTIONS } from './Constants'; |
||||
|
||||
export const nextMode = |
||||
() => ({ type: ACTIONS.NEXT }); |
@ -0,0 +1,15 @@ |
||||
import { MODE, ACTIONS } from './Constants.js'; |
||||
|
||||
export const modeReducer = (state = MODE.WELCOME, action) => { |
||||
if (action.type === ACTIONS.NEXT) { |
||||
switch (state) { |
||||
case MODE.BOARD: |
||||
return MODE.WELCOME; |
||||
case MODE.WELCOME: |
||||
return MODE.BOARD; |
||||
}; |
||||
} |
||||
else { |
||||
return MODE.WELCOME; |
||||
} |
||||
}; |
@ -1,68 +1,60 @@ |
||||
require('../../sass/board/grid.scss'); |
||||
|
||||
var React = require('react'); |
||||
var Values = require('./Values'); |
||||
var State = require('../State'); |
||||
import { Component } from 'react'; |
||||
import GridCell from './GridCell'; |
||||
// var Values = require('./Values');
|
||||
|
||||
var Cell = React.createClass({ |
||||
render() { |
||||
var classname = ['cell', 'x' + this.props.x, 'y' + this.props.y]; |
||||
|
||||
return (<div className={classname.join(' ')}>{this.props.value}</div>); |
||||
} |
||||
}); |
||||
|
||||
module.exports = React.createClass({ |
||||
export default class Grid extends Component { |
||||
generateValues() { |
||||
return Values.generate(this.props.width * this.props.height, State.level); |
||||
}, |
||||
// return Values.generate(this.props.width * this.props.height, State.level);
|
||||
}; |
||||
|
||||
getInitialState() { |
||||
return { values: this.generateValues() }; |
||||
}, |
||||
// getInitialState() {
|
||||
// return { values: this.generateValues() };
|
||||
// },
|
||||
|
||||
componentDidMount() { |
||||
State.subscribe('level/next', this.levelNext); |
||||
}, |
||||
// State.subscribe('level/next', this.levelNext);
|
||||
}; |
||||
|
||||
checkComplete() { |
||||
if (Values.checkComplete(this.state.values, State.level) === true) { |
||||
State.publish('level/complete'); |
||||
} |
||||
}, |
||||
// if (Values.checkComplete(this.state.values, State.level) === true) {
|
||||
// State.publish('level/complete');
|
||||
// }
|
||||
}; |
||||
|
||||
levelNext() { |
||||
this.setState({ values: this.generateValues() }); |
||||
}, |
||||
// this.setState({ values: this.generateValues() });
|
||||
}; |
||||
|
||||
munch(x, y) { |
||||
var i = y * this.props.width + x; |
||||
|
||||
if (this.state.values[i] === "") { |
||||
return; |
||||
} |
||||
|
||||
if (Values.validate(this.state.values[i], State.level)) { |
||||
this.state.values[i] = ""; |
||||
this.setState({ values: this.state.values }, this.checkComplete); |
||||
State.publish('munch/successful'); |
||||
} |
||||
else { |
||||
State.publish('munch/failed', this.state.values[i]); |
||||
} |
||||
}, |
||||
// var i = y * this.props.width + x;
|
||||
//
|
||||
// if (this.state.values[i] === "") {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (Values.validate(this.state.values[i], State.level)) {
|
||||
// this.state.values[i] = "";
|
||||
// this.setState({ values: this.state.values }, this.checkComplete);
|
||||
// State.publish('munch/successful');
|
||||
// }
|
||||
// else {
|
||||
// State.publish('munch/failed', this.state.values[i]);
|
||||
// }
|
||||
}; |
||||
|
||||
render() { |
||||
var cells = []; |
||||
var i; |
||||
const cells = []; |
||||
let i; |
||||
|
||||
for (var x = 0; x < this.props.width; x++) { |
||||
for (var y = 0; y < this.props.height; y++) { |
||||
for (let x = 0; x < this.props.width; x++) { |
||||
for (let y = 0; y < this.props.height; y++) { |
||||
i = y * this.props.width + x; |
||||
cells.push(<Cell value={this.state.values[i]} x={x} y={y} key={i} />); |
||||
// cells.push(<GridCell value={this.state.values[i]} x={x} y={y} key={i} />);
|
||||
} |
||||
} |
||||
|
||||
return (<div className='grid'>{cells}</div>); |
||||
} |
||||
}); |
||||
}; |
||||
}; |
||||
|
@ -0,0 +1,9 @@ |
||||
import { Component } from 'react'; |
||||
|
||||
export default class GridCell extends Component { |
||||
render() { |
||||
const classname = ['cell', 'x' + this.props.x, 'y' + this.props.y]; |
||||
|
||||
return (<div className={classname.join(' ')}>{this.props.value}</div>); |
||||
} |
||||
}; |
@ -1,20 +1,21 @@ |
||||
require('../../sass/board/muncher.scss'); |
||||
|
||||
var React = require('react'); |
||||
import { Component } from 'react'; |
||||
|
||||
module.exports = React.createClass({ |
||||
getInitialState() { |
||||
return { |
||||
x: 0, |
||||
y: 0 |
||||
}; |
||||
}, |
||||
export default class Muncher extends Component{ |
||||
// getInitialState() {
|
||||
// return {
|
||||
// x: 0,
|
||||
// y: 0
|
||||
// };
|
||||
// },
|
||||
|
||||
render() { |
||||
var classname = ['muncher', 'x' + this.state.x, 'y' + this.state.y]; |
||||
// const classname = ['muncher', 'x' + this.state.x, 'y' + this.state.y];
|
||||
|
||||
return ( |
||||
<div className={classname.join(' ')}></div> |
||||
<div className='muncher'></div> |
||||
// <div className={classname.join(' ')}></div>
|
||||
); |
||||
} |
||||
}); |
||||
}; |
||||
}; |
||||
|
@ -1,42 +1,42 @@ |
||||
require('../../sass/board/scorebar.scss'); |
||||
|
||||
var React = require('react'); |
||||
var State = require('../State'); |
||||
import { Component } from 'react'; |
||||
|
||||
module.exports = React.createClass({ |
||||
getInitialState() { |
||||
return { |
||||
currentScore: 0, |
||||
highScore: 0, |
||||
lives: 3 |
||||
}; |
||||
}, |
||||
export default class Scorebar extends Component { |
||||
// getInitialState() {
|
||||
// return {
|
||||
// currentScore: 0,
|
||||
// highScore: 0,
|
||||
// lives: 3
|
||||
// };
|
||||
// },
|
||||
|
||||
componentDidMount() { |
||||
State.subscribe('munch/successful', this.updateScore); |
||||
State.subscribe('munch/failed', this.updateLives); |
||||
}, |
||||
// // State.subscribe('munch/successful', this.updateScore);
|
||||
// State.subscribe('munch/failed', this.updateLives);
|
||||
}; |
||||
|
||||
updateScore() { |
||||
var score = this.state.currentScore; |
||||
this.setState({ currentScore: score + 10 }); |
||||
}, |
||||
// var score = this.state.currentScore;
|
||||
// this.setState({ currentScore: score + 10 });
|
||||
}; |
||||
|
||||
updateLives() { |
||||
var lives = this.state.lives; |
||||
this.setState({ lives: lives - 1 }); |
||||
}, |
||||
// var lives = this.state.lives;
|
||||
// this.setState({ lives: lives - 1 });
|
||||
}; |
||||
|
||||
render() { |
||||
var lives = []; |
||||
for (var i = 0; i < this.state.lives; i++) { |
||||
lives.push(<div className='life' key={i}></div>); |
||||
} |
||||
// for (var i = 0; i < this.state.lives; i++) {
|
||||
// lives.push(<div className='life' key={i}></div>);
|
||||
// }
|
||||
|
||||
return (<div className='scorebar'> |
||||
<div className='item current-score'>{this.state.currentScore}</div> |
||||
<div className='item high-score'>{this.state.highScore}</div> |
||||
<div className='item lives'>{lives}</div> |
||||
</div>); |
||||
} |
||||
}); |
||||
// return (<div className='scorebar'>
|
||||
// <div className='item current-score'>{this.state.currentScore}</div>
|
||||
// <div className='item high-score'>{this.state.highScore}</div>
|
||||
// <div className='item lives'>{lives}</div>
|
||||
// </div>);
|
||||
return <h1>Scorebar</h1>; |
||||
}; |
||||
}; |
||||
|
@ -1,25 +1,17 @@ |
||||
require('../../sass/board/titlebar.scss'); |
||||
|
||||
var React = require('react'); |
||||
var State = require('../State'); |
||||
var Values = require('./Values'); |
||||
|
||||
module.exports = React.createClass({ |
||||
getInitialState() { |
||||
return { |
||||
title: Values.getDescription(State.level) |
||||
}; |
||||
}, |
||||
import { Component } from 'react'; |
||||
|
||||
export default class Titlebar extends Component { |
||||
componentDidMount() { |
||||
State.subscribe('level/next', this.levelNext); |
||||
}, |
||||
// State.subscribe('level/next', this.levelNext);
|
||||
}; |
||||
|
||||
levelNext() { |
||||
this.setState({ title: Values.getDescription(State.level) }); |
||||
}, |
||||
// this.setState({ title: Values.getDescription(State.level) });
|
||||
}; |
||||
|
||||
render() { |
||||
return (<div className='titlebar'>{this.state.title}</div>); |
||||
} |
||||
}); |
||||
return (<div className='titlebar'>DYNAMIC TITLE</div>); |
||||
}; |
||||
}; |
||||
|
@ -0,0 +1,21 @@ |
||||
require('../sass/reset.scss'); |
||||
|
||||
import { render } from 'react-dom'; |
||||
import { createStore, combineReducers } from 'redux' |
||||
import { Provider } from 'react-redux'; |
||||
|
||||
import App from './app/App'; |
||||
import * as reducers from './app/Reducers'; |
||||
|
||||
const combinedReducers = combineReducers({ |
||||
mode: reducers.modeReducer |
||||
}); |
||||
|
||||
const store = createStore(combinedReducers); |
||||
|
||||
ReactDOM.render( |
||||
<Provider store={store}> |
||||
<App /> |
||||
</Provider>, |
||||
document.getElementById('app') |
||||
); |
@ -1,36 +0,0 @@ |
||||
require('../sass/reset.scss'); |
||||
|
||||
var React = require('react'); |
||||
var ReactDom = require('react-dom'); |
||||
var Board = require('./board/Board'); |
||||
var Welcome = require('./welcome/Welcome'); |
||||
var State = require('./State'); |
||||
|
||||
var App = React.createClass({ |
||||
getInitialState() { |
||||
return { |
||||
screen: 'board' |
||||
}; |
||||
}, |
||||
|
||||
handleKeydown(e) { |
||||
if (this.state.screen === 'welcome' && e.keyCode === 32) { |
||||
this.setState({ screen: 'board' }); |
||||
} |
||||
}, |
||||
|
||||
componentDidMount() { |
||||
window.addEventListener('keydown', this.handleKeydown); |
||||
}, |
||||
|
||||
render() { |
||||
if (this.state.screen === 'welcome') { |
||||
return (<Welcome />); |
||||
} |
||||
else if (this.state.screen === 'board') { |
||||
return (<Board />); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
ReactDom.render(<App />, document.getElementById('app')); |
@ -0,0 +1,13 @@ |
||||
import { Component } from 'react'; |
||||
|
||||
export default class HighScoreEntry extends Component { |
||||
render() { |
||||
return ( |
||||
<div className='entry'> |
||||
<div className='rank'>{this.props.rank}</div> |
||||
<div className='initials'>{this.props.initials}</div> |
||||
<div className='score'>{this.props.score}</div> |
||||
</div> |
||||
); |
||||
} |
||||
}; |
@ -1,32 +1,26 @@ |
||||
require('../../sass/welcome/highscores.scss'); |
||||
|
||||
var React = require('react'); |
||||
import { Component } from 'react'; |
||||
import HighScoreEntry from './HighScoreEntry'; |
||||
|
||||
var Entry = React.createClass({ |
||||
export default class HighScores extends Component { |
||||
render() { |
||||
return ( |
||||
<div className='entry'> |
||||
<div className='rank'>{this.props.rank}</div> |
||||
<div className='initials'>{this.props.initials}</div> |
||||
<div className='score'>{this.props.score}</div> |
||||
</div> |
||||
); |
||||
} |
||||
}); |
||||
const vals = [ |
||||
{ initials: "ABA", score: "219283", rank: "1" }, |
||||
{ initials: "ABA", score: "107112", rank: "2" }, |
||||
{ initials: "ABA", score: "81091", rank: "3" }, |
||||
{ initials: "ABA", score: "67747", rank: "4" }, |
||||
{ initials: "ABA", score: "9283", rank: "5" }, |
||||
{ initials: "ABA", score: "928", rank: "6" } |
||||
]; |
||||
|
||||
|
||||
module.exports = React.createClass({ |
||||
render() { |
||||
var entries = []; |
||||
entries.push(<Entry initials="ABA" score="219283" rank="1" key="0" />); |
||||
entries.push(<Entry initials="ABA" score="107112" rank="2" key="1" />); |
||||
entries.push(<Entry initials="ABA" score="81091" rank="3" key="2" />); |
||||
entries.push(<Entry initials="ABA" score="67747" rank="4" key="3" />); |
||||
entries.push(<Entry initials="ABA" score="9283" rank="5" key="4" />); |
||||
entries.push(<Entry initials="ABA" score="928" rank="6" key="5" />); |
||||
vals.map(function(v, i) { |
||||
entries.push(<HighScoreEntry initials={v.initials} score={v.score} rank={v.rank} key={i} />); |
||||
}); |
||||
|
||||
return ( |
||||
<div className='highscores'>{entries}</div> |
||||
); |
||||
} |
||||
}); |
||||
}; |
||||
|
@ -0,0 +1,31 @@ |
||||
import { Component } from 'react'; |
||||
|
||||
const blinkTimer = null; |
||||
|
||||
const toggleTimeout = function() { |
||||
//var hidden = this.state.hidden; which was false
|
||||
//this.setState({ hidden: !hidden });
|
||||
//blinkTimer = setTimeout(toggleTimeout.bind(this), 600);
|
||||
}; |
||||
|
||||
export default class NewGame extends Component { |
||||
componentDidMount() { |
||||
//toggleTimeout.call(this);
|
||||
}; |
||||
|
||||
componentWillUnmount() { |
||||
clearTimeout(blinkTimer); |
||||
}; |
||||
|
||||
render() { |
||||
const classname = ['newgame']; |
||||
|
||||
//if (this.state.hidden === true) {
|
||||
// classname.push('hidden');
|
||||
//}
|
||||
|
||||
return ( |
||||
<div className={classname.join(' ')}>Press Space Bar To Play</div> |
||||
); |
||||
}; |
||||
}; |
@ -0,0 +1,24 @@ |
||||
0 info it worked if it ends with ok |
||||
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'start' ] |
||||
2 info using npm@3.7.3 |
||||
3 info using node@v5.8.0 |
||||
4 verbose stack Error: missing script: start |
||||
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:147:19) |
||||
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:57:5 |
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:345:5 |
||||
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:309:45) |
||||
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:343:3) |
||||
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:113:5) |
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:300:12 |
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 |
||||
4 verbose stack at tryToString (fs.js:414:3) |
||||
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:401:12) |
||||
5 verbose cwd /Users/tonklin/Development/bb/number-munchers |
||||
6 error Darwin 15.3.0 |
||||
7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start" |
||||
8 error node v5.8.0 |
||||
9 error npm v3.7.3 |
||||
10 error missing script: start |
||||
11 error If you need help, you may report this error at: |
||||
11 error <https://github.com/npm/npm/issues> |
||||
12 verbose exit [ 1, true ] |
Loading…
Reference in new issue