events.addEventListener("player-enter", event => {
const info = JSON.parse(event.data);
- window.game.set_opponent_info(info);
+ window.game.set_other_player_info(info);
});
events.addEventListener("player-update", event => {
if (info.id === window.game.state.player_info.id)
window.game.set_player_info(info);
else
- window.game.set_opponent_info(info);
+ window.game.set_other_player_info(info);
});
events.addEventListener("move", event => {
{props.player.team ? ` (${props.player.team})` : ""}
{props.first_move ? "" : " "}
{choices}
- {props.opponents.map(opponent => (
- <span key={opponent.id}>
+ {props.other_players.map(other => (
+ <span key={other.id}>
{", "}
- {opponent.name}
- {opponent.team ? ` (${opponent.team})` : ""}
+ {other.name}
+ {other.team ? ` (${other.team})` : ""}
</span>
))}
</div>
this.state = {
game_info: {},
player_info: {},
- opponent_info: [],
+ other_players: [],
history: [
{
squares: Array(9).fill(null)
});
}
- set_opponent_info(info) {
- const new_opponents = [...this.state.opponent_info];
- const idx = new_opponents.findIndex(o => o.id === info.id);
+ set_other_player_info(info) {
+ const other_players_copy = [...this.state.other_players];
+ const idx = other_players_copy.findIndex(o => o.id === info.id);
if (idx >= 0) {
- new_opponents[idx] = info;
+ other_players_copy[idx] = info;
} else {
- new_opponents.push(info);
+ other_players_copy.push(info);
}
this.setState({
- opponent_info: new_opponents
+ other_players: other_players_copy
});
}
}
else if (first_move)
{
- if (state.opponent_info.length == 0) {
- status = "You can make the first move or wait for an opponent to join.";
+ if (state.other_players.length == 0) {
+ status = "You can move or wait for another player to join.";
} else {
let qualifier;
- if (state.opponent_info.length == 1) {
+ if (state.other_players.length == 1) {
qualifier = "Either";
} else {
qualifier = "Any";
}
else
{
- status = "Waiting for your opponent to ";
- if (state.opponent_info.length == 0) {
+ status = "Waiting for another player to ";
+ if (state.other_players.length == 0) {
status += "join.";
} else {
status += "move.";
game={this}
first_move={first_move}
player={state.player_info}
- opponents={state.opponent_info}
+ other_players={state.other_players}
/>,
<div key="game" className="game">
<div>{status}</div>