-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLoopyBoard.jsx
85 lines (72 loc) · 2.11 KB
/
LoopyBoard.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from "react";
import Board from "../Board/Board";
/**
* LoopyBoard: Display a double sized grid, where every second cell as actually
* the "border" between two cells, since the puzzle involves drawing the lines
* between the cells e.g.:
*
* .-.-.
* |2x2|
* .x.x.
* |2x2|
* .-.-.
*/
class LoopyBoard extends React.Component {
constructor(props) {
super(props);
this.state = {
x: this.props.params.n,
y: this.props.params.m
};
}
getLiteralBackgrounds() {
let backgrounds = {
// Small circle in the -1 cells
"-1": "radial-gradient(black 15%, #ffffff 16%)",
// Black in the filled borders (cellBackgrounds makes it the right shape)
1: "linear-gradient(black, black)",
};
return backgrounds;
}
getCellBorders() {
let borders = [];
const { x, y } = this.state;
for (let i = 0; i < x*2+1; i++) {
borders[i] = [];
for (let j = 0; j < y*2+1; j++) {
borders[i].push({
border: "none"
});
}
}
return borders
}
getCellBackgrounds() {
let backgrounds = [];
const { x, y } = this.state;
for (let i = 0; i < x*2+1; i++) {
backgrounds[i] = [];
for (let j = 0; j < y*2+1; j++) {
// Use cellBackgrounds to create a "frame" which gets filled in by literalBackgrounds
if (j % 2 == 1 && i % 2 === 0) {
//hortizontal bar
backgrounds[i].push("linear-gradient(white 42%, transparent 43%, transparent 55%, white 56%)");
} else if (j % 2 == 0 && i % 2 === 1) {
//vertical bar
backgrounds[i].push("linear-gradient(to right, white 42%, transparent 43%, transparent 55%, white 56%)");
} else {
backgrounds[i].push("none");
}
}
}
return backgrounds
}
render() {
return <Board {...this.props}
cellBorders={this.getCellBorders()}
cellBackgrounds={this.getCellBackgrounds()}
literalBackgrounds={this.getLiteralBackgrounds()}
hiddenLiterals={[-1, 1, 0]}/>;
}
}
export default LoopyBoard;