import React from 'react';
import ReactDOM from 'react-dom';
import Immutable from 'immutable';
const Cell = React.createClass({
render() {
let classname = this.props.occupied ? "cell occupied" : "cell";
return
;
},
});
const Board = React.createClass({
//render() {
// let nh = this.props.settings.height || 10,
// nw = this.props.settings.width || 10,
// ot = this.props.settings.offsetTop || 0,
// ol = this.props.settings.offsetLeft || 0,
// cells = [];
// for( let i = 0; i < nh; i++ ) {
// for( let j = 0; j < nw; j++ ) {
// let x = (((j % nw) * 10) + ol) + 'px',
// y = ((i * 10) + ot) + 'px';
// cells.push( | );
// }
// }
// return (
//
// {cells}
//
// );
//},
render() {
let ot = this.props.settings.offsetTop || 0,
ol = this.props.settings.offsetLeft || 0;
let cells = this.props.world.flatMap(function (row, y) {
return row.map(function eachCell(cell, x) {
let xc = ((x * 10) + ol) + 'px',
yc = ((y * 10) + ot) + 'px',
occu = ( !(x%2) && !(y%2) );
console.log('occupied?', x, y, occu);
return | ;
});
}).toJS();
return
{cells}
;
},
});
let settings = {
offsetTop:40,
offsetLeft:10,
width:50,
height:20
};
function generateWorld(w = 10, h = 10) {
let grid = [];
for( let i = 0; i < h; i++ ) {
let row = [];
for( let j = 0; j < w; j++ ) {
row.push(0);
}
grid.push(row);
}
return Immutable.fromJS(grid);
}
let world = generateWorld(100, 20);
ReactDOM.render(
,
document.getElementById('board')
);