function team_symbol(team) {
if (team === "+")
- return "🞥";
+ return "+";
else
- return "🞇";
+ return "o";
}
function undisplay(element) {
events.onerror = function(event) {
if (event.target.readyState === EventSource.CLOSED) {
+ setTimeout(() => {
add_message("danger", "Connection to server lost.");
+ }, 1000);
}
};
* Game and supporting classes *
*********************************************************/
+const scribe_glyphs = [
+ {
+ name: "Single",
+ squares: [1,0,0,
+ 0,0,0,
+ 0,0,0]
+ },
+ {
+ name: "Double",
+ squares: [1,1,0,
+ 0,0,0,
+ 0,0,0]
+ },
+ {
+ name: "Line",
+ squares: [1,1,1,
+ 0,0,0,
+ 0,0,0]
+ },
+ {
+ name: "Pipe",
+ squares: [0,0,1,
+ 1,1,1,
+ 0,0,0]
+ },
+ {
+ name: "Squat-T",
+ squares: [1,1,1,
+ 0,1,0,
+ 0,0,0]
+ },
+ {
+ name: "4-block",
+ squares: [1,1,0,
+ 1,1,0,
+ 0,0,0]
+ },
+ {
+ name: "T",
+ squares: [1,1,1,
+ 0,1,0,
+ 0,1,0]
+ },
+ {
+ name: "Cross",
+ squares: [0,1,0,
+ 1,1,1,
+ 0,1,0]
+ },
+ {
+ name: "6-block",
+ squares: [1,1,1,
+ 1,1,1,
+ 0,0,0]
+ },
+ {
+ name: "Bomber",
+ squares: [1,1,1,
+ 0,1,1,
+ 0,0,1]
+ },
+ {
+ name: "Chair",
+ squares: [0,0,1,
+ 1,1,1,
+ 1,0,1]
+ },
+ {
+ name: "J",
+ squares: [0,0,1,
+ 1,0,1,
+ 1,1,1]
+ },
+ {
+ name: "Earring",
+ squares: [0,1,1,
+ 1,0,1,
+ 1,1,1]
+ },
+ {
+ name: "House",
+ squares: [0,1,0,
+ 1,1,1,
+ 1,1,1]
+ },
+ {
+ name: "H",
+ squares: [1,0,1,
+ 1,1,1,
+ 1,0,1]
+ },
+ {
+ name: "U",
+ squares: [1,0,1,
+ 1,0,1,
+ 1,1,1]
+ },
+ {
+ name: "Ottoman",
+ squares: [1,1,1,
+ 1,1,1,
+ 1,0,1]
+ },
+ {
+ name: "O",
+ squares: [1,1,1,
+ 1,0,1,
+ 1,1,1]
+ },
+ {
+ name: "9-block",
+ squares: [1,1,1,
+ 1,1,1,
+ 1,1,1]
+ }
+];
+
+function copy_to_clipboard(id)
+{
+ const tmp = document.createElement("input");
+ tmp.setAttribute("value", document.getElementById(id).innerHTML);
+ document.body.appendChild(tmp);
+ tmp.select();
+ document.execCommand("copy");
+ document.body.removeChild(tmp);
+}
+
function GameInfo(props) {
if (! props.id)
return null;
return (
<div className="game-info">
- <h2>{props.id}</h2>
- Invite a friend to play by sending this URL: {props.url}
+ <span className="game-id">{props.id}</span>
+ {" "}
+ Share this link to invite a friend:{" "}
+ <span id="game-share-url">{props.url}</span>
+ {" "}
+ <button
+ className="inline"
+ onClick={() => copy_to_clipboard('game-share-url')}
+ >Copy Link</button>
</div>
);
}
return (
<div className="player-info">
- <h2>Players</h2>
+ <span className="players-header">Players: </span>
{props.player.name}
{props.player.team ? ` (${props.player.team})` : ""}
{props.first_move ? "" : " "}
);
}
+function Glyph(props) {
+
+ const glyph_dots = [];
+
+ let last_square = 0;
+ for (let i = 0; i < 9; i++) {
+ if (props.squares[i])
+ last_square = i;
+ }
+
+ const height = Math.floor(20 * (Math.floor(last_square / 3) + 1));
+
+ const viewbox=`0 0 60 ${height}`;
+
+ for (let row = 0; row < 3; row++) {
+ for (let col = 0; col < 3; col++) {
+ if (props.squares[3 * row + col]) {
+ let cy = 10 + 20 * row;
+ let cx = 10 + 20 * col;
+ glyph_dots.push(
+ <circle
+ key={3 * row + col}
+ cx={cx}
+ cy={cy}
+ r="8"
+ />
+ );
+ }
+ }
+ }
+
+ return (<div className="glyph-and-name">
+ {props.name}
+ <div className="glyph">
+ <svg viewBox={viewbox}>
+ <g fill="#287789">
+ {glyph_dots}
+ </g>
+ </svg>
+ </div>
+ </div>
+ );
+}
+
function Square(props) {
let className = "square";
);
}
-class Board extends React.Component {
- render_square(i,j) {
- const value = this.props.squares[i][j];
+function MiniGrid(props) {
+ function grid_square(j) {
+ const value = props.squares[j];
return (
<Square
value={value}
- active={this.props.active && ! value}
- onClick={() => this.props.onClick(i,j)}
+ active={props.active}
+ onClick={() => props.onClick(j)}
/>
);
}
- render() {
- return (
- <div>
- <div className="board-row">
- {this.render_square(0,0)}
- {this.render_square(0,1)}
- {this.render_square(0,2)}
- {" "}
- {this.render_square(1,0)}
- {this.render_square(1,1)}
- {this.render_square(1,2)}
- {" "}
- {this.render_square(2,0)}
- {this.render_square(2,1)}
- {this.render_square(2,2)}
- </div>
- <div className="board-row">
- {this.render_square(0,3)}
- {this.render_square(0,4)}
- {this.render_square(0,5)}
- {" "}
- {this.render_square(1,3)}
- {this.render_square(1,4)}
- {this.render_square(1,5)}
- {" "}
- {this.render_square(2,3)}
- {this.render_square(2,4)}
- {this.render_square(2,5)}
- </div>
- <div className="board-row">
- {this.render_square(0,6)}
- {this.render_square(0,7)}
- {this.render_square(0,8)}
- {" "}
- {this.render_square(1,6)}
- {this.render_square(1,7)}
- {this.render_square(1,8)}
- {" "}
- {this.render_square(2,6)}
- {this.render_square(2,7)}
- {this.render_square(2,8)}
- </div>
-
- <div className="board-row">
- </div>
-
- <div className="board-row">
- {this.render_square(3,0)}
- {this.render_square(3,1)}
- {this.render_square(3,2)}
- {" "}
- {this.render_square(4,0)}
- {this.render_square(4,1)}
- {this.render_square(4,2)}
- {" "}
- {this.render_square(5,0)}
- {this.render_square(5,1)}
- {this.render_square(5,2)}
- </div>
- <div className="board-row">
- {this.render_square(3,3)}
- {this.render_square(3,4)}
- {this.render_square(3,5)}
- {" "}
- {this.render_square(4,3)}
- {this.render_square(4,4)}
- {this.render_square(4,5)}
- {" "}
- {this.render_square(5,3)}
- {this.render_square(5,4)}
- {this.render_square(5,5)}
- </div>
- <div className="board-row">
- {this.render_square(3,6)}
- {this.render_square(3,7)}
- {this.render_square(3,8)}
- {" "}
- {this.render_square(4,6)}
- {this.render_square(4,7)}
- {this.render_square(4,8)}
- {" "}
- {this.render_square(5,6)}
- {this.render_square(5,7)}
- {this.render_square(5,8)}
- </div>
+ return (
+ <div className="mini-grid">
+ {grid_square(0)}
+ {grid_square(1)}
+ {grid_square(2)}
+ {grid_square(3)}
+ {grid_square(4)}
+ {grid_square(5)}
+ {grid_square(6)}
+ {grid_square(7)}
+ {grid_square(8)}
+ </div>
+ );
+}
- <div className="board-row">
- </div>
+class Board extends React.Component {
+ mini_grid(i) {
+ const squares = this.props.squares[i];
+ return (
+ <MiniGrid
+ squares={squares}
+ active={this.props.active}
+ onClick={(j) => this.props.onClick(i,j)}
+ />
+ );
+ }
- <div className="board-row">
- {this.render_square(6,0)}
- {this.render_square(6,1)}
- {this.render_square(6,2)}
- {" "}
- {this.render_square(7,0)}
- {this.render_square(7,1)}
- {this.render_square(7,2)}
- {" "}
- {this.render_square(8,0)}
- {this.render_square(8,1)}
- {this.render_square(8,2)}
- </div>
- <div className="board-row">
- {this.render_square(6,3)}
- {this.render_square(6,4)}
- {this.render_square(6,5)}
- {" "}
- {this.render_square(7,3)}
- {this.render_square(7,4)}
- {this.render_square(7,5)}
- {" "}
- {this.render_square(8,3)}
- {this.render_square(8,4)}
- {this.render_square(8,5)}
- </div>
- <div className="board-row">
- {this.render_square(6,6)}
- {this.render_square(6,7)}
- {this.render_square(6,8)}
- {" "}
- {this.render_square(7,6)}
- {this.render_square(7,7)}
- {this.render_square(7,8)}
- {" "}
- {this.render_square(8,6)}
- {this.render_square(8,7)}
- {this.render_square(8,8)}
+ render() {
+ return (
+ <div className="board-container">
+ <div className="board">
+ {this.mini_grid(0)}
+ {this.mini_grid(1)}
+ {this.mini_grid(2)}
+ {this.mini_grid(3)}
+ {this.mini_grid(4)}
+ {this.mini_grid(5)}
+ {this.mini_grid(6)}
+ {this.mini_grid(7)}
+ {this.mini_grid(8)}
</div>
-
</div>
);
}
game_info: {},
player_info: {},
other_players: [],
- squares: Array(9).fill(null).map(() => Array(9).fill(null)),
+ squares: [...Array(9)].map(() => Array(9).fill(null)),
moves: 0,
next_to_play: "+"
};
onClick={(i,j) => this.handle_click(i, j, first_move)}
/>
</div>
+ </div>,
+ <div key="glyphs" className="glyphs">
+ {
+ scribe_glyphs.map(glyph => {
+ return (
+ <Glyph
+ key={glyph.name}
+ name={glyph.name}
+ squares={glyph.squares}
+ />
+ );
+ })
+ }
</div>
];
}