Skip to content

Commit bb00f11

Browse files
committed
Merge pull request #2 from SKatiyar/f/seed
F/seed
2 parents e84b634 + de0588c commit bb00f11

20 files changed

Lines changed: 722 additions & 0 deletions

File tree

client/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

client/README.md

Whitespace-only changes.

client/config/development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"env" : "development"
3+
}

client/config/production.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"env" : "production"
3+
}

client/package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "entrapped",
3+
"version": "1.0.0",
4+
"description": "Tiny little minefield of our dreams.",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "webpack-dev-server --hot --progress --colors --port 3000",
9+
"build": "webpack --progress --colors"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/SKatiyar/entrapped"
14+
},
15+
"keywords": [
16+
"mine",
17+
"field",
18+
"boom"
19+
],
20+
"author": "Rabi C Shah",
21+
"license": "ISC",
22+
"bugs": {
23+
"url": "https://github.com/SKatiyar/entrapped/issues"
24+
},
25+
"homepage": "https://github.com/SKatiyar/entrapped",
26+
"devDependencies": {
27+
"babel": "^5.6.14",
28+
"babel-core": "^5.6.18",
29+
"babel-loader": "^5.3.1",
30+
"file-loader": "^0.8.4",
31+
"node-libs-browser": "^0.5.2",
32+
"react-hot-loader": "^1.2.8",
33+
"webpack": "^1.10.1",
34+
"webpack-dev-server": "^1.10.1"
35+
},
36+
"dependencies": {
37+
"flux": "^2.0.3",
38+
"object-assign": "^3.0.0",
39+
"react": "^0.13.3",
40+
"react-router": "^0.13.3"
41+
}
42+
}

client/src/api/api.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
var MinesStore = require('../../src/stores/minestore.js');
4+
var AppDispatcher = require('../dispatchers/app_dispatcher.js');
5+
6+
var _ = require('../../src/utility/utils.js');
7+
8+
var apiUrl = "ws://192.168.0.103:7000";
9+
10+
/* websocket reference */
11+
var conn = null;
12+
13+
module.exports = {
14+
connect: function(nickname) {
15+
console.log('inside connect');
16+
if (window["WebSocket"]) {
17+
conn = new WebSocket(apiUrl + '/players/' + nickname);
18+
19+
conn.onclose = function(evt) {
20+
console.log('connection closed.');
21+
};
22+
23+
conn.onmessage = function(evt) {
24+
//console.log('data from server', evt);
25+
var data = _.getObject(evt.data);
26+
27+
//console.log('data', data);
28+
AppDispatcher.handleServerAction(data);
29+
};
30+
} else {
31+
console.log($("Your browser does not support WebSockets."));
32+
}
33+
},
34+
35+
send: function(data) {
36+
//console.log('sending ', data);
37+
conn.send(data);
38+
},
39+
40+
close: function() {
41+
conn.close();
42+
}
43+
};

client/src/app.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
import React from 'react';
4+
import Router from 'react-router';
5+
import { DefaultRoute, Route, RouteHandler } from 'react-router';
6+
7+
import Home from './components/Home.jsx';
8+
import Minefield from './components/Minefield.jsx';
9+
10+
let App = React.createClass({
11+
render() {
12+
return (
13+
<RouteHandler />
14+
);
15+
}
16+
});
17+
18+
let Routes = (
19+
<Route name="app" path="/" handler={App}>
20+
<Route name="home" path="/home" handler={Home}/>
21+
<Route name="minefield" path="/minefield" handler={Minefield}/>
22+
<DefaultRoute handler={Home} />
23+
</Route>
24+
)
25+
26+
Router.run(Routes, function(Handler) {
27+
React.render(<Handler/>, document.body);
28+
});

client/src/components/Blocks.jsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react/addons';
2+
3+
import Api from '../api/api.js';
4+
/**
5+
* Returns a random integer between min (inclusive) and max (inclusive)
6+
* Using Math.round() will give you a non-uniform distribution!
7+
*/
8+
function getRandomInt(min, max) {
9+
return Math.floor(Math.random() * (max - min + 1)) + min;
10+
}
11+
12+
class Block extends React.Component {
13+
constructor(props) {
14+
super(props);
15+
this.handleClick = this.handleClick.bind(this);
16+
}
17+
18+
render() {
19+
var cx = React.addons.classSet;
20+
var classes = cx({
21+
'block': true,
22+
'block__visited': this.props.status === 0 || this.props.status === 9,
23+
'block__dead': this.props.status === -2
24+
});
25+
26+
return(
27+
<td className={classes} onClick={this.handleClick}></td>
28+
)
29+
}
30+
31+
handleClick() {
32+
var msg = "data:open:[idx=" + this.props.index + "]:[help=9]";
33+
Api.send(msg);
34+
}
35+
};
36+
Block.propTypes = { status: React.PropTypes.number, index: React.PropTypes.number };
37+
Block.defaultProps = { status: 0, index: 0 };
38+
39+
class Blocks extends React.Component {
40+
constructor(props) {
41+
super(props);
42+
}
43+
44+
render() {
45+
var nodes = [];
46+
var size = this.props.size;
47+
48+
/* construct blocks */
49+
for (var i = 0; i < size; i++) {
50+
var _blocks = [];
51+
52+
for (var j = 0; j < size; j++) {
53+
var index = i * size + j;
54+
_blocks.push(<Block key={'block-' + index} status={this.props.mines[index]} index={index} />);
55+
}
56+
57+
nodes.push((<tr key={'blocks-' + i}>{_blocks}</tr>));
58+
}
59+
60+
return (
61+
<table className="blocks">
62+
<tbody>
63+
{nodes}
64+
</tbody>
65+
</table>
66+
);
67+
}
68+
};
69+
Blocks.propTypes = { size: React.PropTypes.number, mines: React.PropTypes.array };
70+
Blocks.defaultProps = { size: 7, mines: [] }
71+
72+
export default Blocks;

client/src/components/Field.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react/addons';
2+
3+
import Blocks from './Blocks.jsx';
4+
5+
class Field extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
}
9+
10+
render() {
11+
var cx = React.addons.classSet;
12+
var classes = cx({
13+
'minefield': true,
14+
'minefield__enemy': this.props.of === "enemy",
15+
'minefield__user': this.props.of === "player"
16+
});
17+
18+
var nodes = [];
19+
for (var i = 1; i <= 5; i++) {
20+
var classname = "fa fa-2x fa-heartbeat heart-icons";
21+
22+
if (i <= this.props.player.life) {
23+
classname = classname + " life-status__active";
24+
}
25+
26+
nodes.push(<i key={"heart" + i} className={classname}></i>);
27+
}
28+
29+
return (
30+
<div className={classes}>
31+
<Blocks size={7} mines={this.props.player.mines} />
32+
<div className="life-status">
33+
<span>
34+
{nodes}
35+
</span>
36+
</div>
37+
<h2 className="minefield__text--instructions">{this.props.player.username}</h2>
38+
</div>
39+
)
40+
}
41+
};
42+
Field.propTypes = { of: React.PropTypes.string, player: React.PropTypes.object };
43+
Field.defaultProps = { of: 'user', player: {} };
44+
45+
export default Field;

client/src/components/Home.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { Router, Link } from 'react-router';
3+
4+
import MinesStore from '../stores/minestore.js';
5+
6+
class Home extends React.Component {
7+
handleChange(e) {
8+
MinesStore.addUsername(e.target.value);
9+
}
10+
11+
render() {
12+
return (
13+
<div className="home">
14+
<h1 className="home__title">Entrapped v0.0</h1>
15+
<blockquote>Tiny little minefield of our dreams.</blockquote>
16+
<div className="nickname">
17+
<input className="nickname__input" placeholder="nickname" onChange={this.handleChange}/>
18+
</div>
19+
<Link to="/minefield">Play</Link>
20+
</div>
21+
)
22+
}
23+
};
24+
25+
export default Home;

0 commit comments

Comments
 (0)