|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
import React from 'react';
|
|
2
|
2
|
import Cell from './Cell';
|
|
3
|
3
|
import Controls from './Controls';
|
|
4
|
|
-import { generateNewGrid } from './lib';
|
|
|
4
|
+import { generateNewGrid, updateGridDimensions } from './lib';
|
|
5
|
5
|
|
|
6
|
6
|
const DEFAULT_WIDTH = 20;
|
|
7
|
7
|
const DEFAULT_HEIGHT = 10;
|
|
|
@@ -80,23 +80,13 @@ class Board extends React.Component<{}, State> {
|
|
80
|
80
|
this.setState({ height: dimensions.height });
|
|
81
|
81
|
}
|
|
82
|
82
|
|
|
83
|
|
- const width = dimensions.width ?? this.state.width;
|
|
84
|
|
- const height = dimensions.height ?? this.state.height;
|
|
85
|
|
-
|
|
86
|
|
- const grid = [...this.state.grid];
|
|
87
|
|
- while (grid.length < height) {
|
|
88
|
|
- grid.push(Array(width).fill(false));
|
|
89
|
|
- }
|
|
90
|
|
-
|
|
91
|
|
- const newGrid = grid.map((row) => {
|
|
92
|
|
- while (row.length < width) {
|
|
93
|
|
- row.push(false);
|
|
94
|
|
- }
|
|
95
|
|
-
|
|
96
|
|
- return row;
|
|
97
|
|
- });
|
|
|
83
|
+ const grid = updateGridDimensions(
|
|
|
84
|
+ { width: this.state.width, height: this.state.height },
|
|
|
85
|
+ dimensions,
|
|
|
86
|
+ this.state.grid,
|
|
|
87
|
+ );
|
|
98
|
88
|
|
|
99
|
|
- this.setState({ grid: newGrid });
|
|
|
89
|
+ this.setState({ grid });
|
|
100
|
90
|
};
|
|
101
|
91
|
|
|
102
|
92
|
render() {
|