Skip to content

Commit 23e8df0

Browse files
Scott WeyScott Wey
authored andcommitted
initial commit
0 parents  commit 23e8df0

File tree

20 files changed

+5864
-0
lines changed

20 files changed

+5864
-0
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "eslint-config-airbnb",
3+
"env": {"browser":true}
4+
}

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
npm-debug.log

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "bun",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"eslint": "^3.7.0",
7+
"eslint-config-airbnb": "^12.0.0",
8+
"eslint-plugin-import": "^1.16.0",
9+
"eslint-plugin-jsx-a11y": "^2.2.2",
10+
"eslint-plugin-react": "^6.3.0",
11+
"react-scripts": "0.6.1"
12+
},
13+
"dependencies": {
14+
"aphrodite": "^0.6.0",
15+
"react": "^15.3.2",
16+
"react-dom": "^15.3.2",
17+
"react-redux": "^4.4.5",
18+
"redux": "^3.6.0",
19+
"redux-thunk": "^2.1.0",
20+
"reselect": "^2.5.4"
21+
},
22+
"scripts": {
23+
"start": "react-scripts start",
24+
"build": "react-scripts build",
25+
"test": "react-scripts test --env=jsdom",
26+
"eject": "react-scripts eject"
27+
}
28+
}

public/favicon.ico

24.3 KB
Binary file not shown.

public/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet">
7+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
8+
<!--
9+
Notice the use of %PUBLIC_URL% in the tag above.
10+
It will be replaced with the URL of the `public` folder during the build.
11+
Only files inside the `public` folder can be referenced from the HTML.
12+
13+
Unlike "/favicon.ico" or "favico.ico", "%PUBLIC_URL%/favicon.ico" will
14+
work correctly both with client-side routing and a non-root public URL.
15+
Learn how to configure a non-root public URL by running `npm run build`.
16+
-->
17+
<title>Bun Quest</title>
18+
</head>
19+
<body>
20+
<div id="root"></div>
21+
<!--
22+
This HTML file is a template.
23+
If you open it directly in the browser, you will see an empty page.
24+
25+
You can add webfonts, meta tags, or analytics to this file.
26+
The build step will place the bundled scripts into the <body> tag.
27+
28+
To begin the development, run `npm start`.
29+
To create a production bundle, use `npm run build`.
30+
-->
31+
</body>
32+
</html>

src/components/Button.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { PropTypes } from 'react';
2+
import { StyleSheet, css } from 'aphrodite';
3+
4+
const style = StyleSheet.create({
5+
default: {
6+
padding: '2px 10px',
7+
backgroundColor: 'white',
8+
':hover:enabled': { backgroundColor: '#5588ff',
9+
color: 'white' },
10+
':active:enabled': { backgroundColor: '#3366dd' },
11+
':disabled': { color: '#dbdbdb',
12+
borderColor: '#dbdbdb',
13+
backgroundColor: '#fdfdfd' },
14+
border: '1px solid #5588ff',
15+
borderRadius: '3px',
16+
color: '#5588ff',
17+
outline: 'none',
18+
margin: '3px',
19+
fontSize: '1em',
20+
textTransform: 'uppercase',
21+
}
22+
});
23+
24+
const Button = props => <button className={css(style.default)} {...props}>{props.children}</button>;
25+
export default Button;

src/components/BuyButton.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { PropTypes } from 'react';
2+
import Button from './Button'
3+
4+
const BuyButton = ({ canBuy, onClick, children }) => {
5+
if (canBuy) {
6+
return (<Button onClick={onClick}>{children}</Button>);
7+
}
8+
return (<Button disabled>{children}</Button>);
9+
};
10+
11+
12+
export default BuyButton;

src/components/Producer.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { PropTypes } from 'react';
2+
import BuyButton from './BuyButton';
3+
4+
const Producer = ({ producer, buyAction, money }) => {
5+
const { name, description, product, price: basePrice, scaling, count } = producer;
6+
const price = Math.ceil(basePrice * Math.pow(scaling, count));
7+
const boundBuy = buyAction.bind(undefined, price);
8+
const enoughMoney = money >= price;
9+
return (
10+
<div>
11+
<h3>{name}</h3>
12+
{description} <br />
13+
Produces { product } buns at a time. You have {count}. <br />
14+
Price: {price} <br />
15+
<BuyButton canBuy={enoughMoney} onClick={boundBuy}>Buy</BuyButton>
16+
<hr />
17+
</div>
18+
);
19+
};
20+
21+
Producer.propTypes = {
22+
producer: PropTypes.object.isRequired,
23+
buyAction: PropTypes.func.isRequired,
24+
money: PropTypes.number.isRequired,
25+
};
26+
27+
export default Producer;

src/components/ProducerList.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { PropTypes } from 'react';
2+
import Producer from './Producer'
3+
4+
const ProducerList = ({ game: { producers: producerArray, money }, buyAction }) => {
5+
const producers = producerArray.map((producer, id) => (
6+
<Producer key={id} producer={producer} buyAction={buyAction.bind(undefined, id)} money={money} />
7+
));
8+
return (
9+
<div>
10+
{producers}
11+
</div>
12+
);
13+
};
14+
15+
export default ProducerList;

src/components/Ticker.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { connect } from 'react-redux';
3+
import { bindActionCreators } from 'redux';
4+
import { moneyPerTickSelector } from '../selectors/perTickSelector';
5+
import * as gameActions from '../ducks/game';
6+
7+
class Ticker extends Component {
8+
componentDidMount() {
9+
this.interval = setInterval(this.props.tick, this.props.interval);
10+
}
11+
12+
componentWillUpdate() {
13+
clearInterval(this.interval);
14+
}
15+
16+
componentDidUpdate() {
17+
this.interval = setInterval(this.props.tick, this.props.interval);
18+
}
19+
20+
componentWillUnmount() {
21+
clearInterval(this.interval);
22+
}
23+
24+
render() {
25+
const { interval, moneyPerTick } = this.props;
26+
return (<span>{moneyPerTick / (parseFloat(interval) / 1000)} buns per second</span>);
27+
}
28+
}
29+
30+
Ticker.propTypes = {
31+
tick: PropTypes.func.isRequired,
32+
interval: PropTypes.number.isRequired,
33+
moneyPerTick: PropTypes.number.isRequired,
34+
};
35+
36+
const stateToProps = state => ({ interval: state.game.interval, moneyPerTick: moneyPerTickSelector(state) });
37+
const dispatchToProps = dispatch => bindActionCreators(gameActions, dispatch);
38+
39+
export default connect(stateToProps, dispatchToProps)(Ticker);

0 commit comments

Comments
 (0)