From ee6203880ca1df381aa0d08eac9fac2931fed083 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 6 Jun 2020 05:02:08 -0700 Subject: [PATCH] Rename "opponent" in both the interface and the code The code was incorrect, since what was called "opponent_info" was really just a list of other players (some of which could be on the same team rather than an opposing team) so the new name of "other_players" is more accurate. In the UI, we also now use "another player" instead of "opponent" to just be more friendly I suppose. --- tictactoe/tictactoe.jsx | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tictactoe/tictactoe.jsx b/tictactoe/tictactoe.jsx index 3e75573..dbfc5ef 100644 --- a/tictactoe/tictactoe.jsx +++ b/tictactoe/tictactoe.jsx @@ -47,7 +47,7 @@ events.addEventListener("player-info", event => { 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 => { @@ -56,7 +56,7 @@ 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 => { @@ -137,11 +137,11 @@ function PlayerInfo(props) { {props.player.team ? ` (${props.player.team})` : ""} {props.first_move ? "" : " "} {choices} - {props.opponents.map(opponent => ( - + {props.other_players.map(other => ( + {", "} - {opponent.name} - {opponent.team ? ` (${opponent.team})` : ""} + {other.name} + {other.team ? ` (${other.team})` : ""} ))} @@ -227,7 +227,7 @@ class Game extends React.Component { this.state = { game_info: {}, player_info: {}, - opponent_info: [], + other_players: [], history: [ { squares: Array(9).fill(null) @@ -250,16 +250,16 @@ class Game extends React.Component { }); } - 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 }); } @@ -342,11 +342,11 @@ class Game extends React.Component { } 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"; @@ -367,8 +367,8 @@ class Game extends React.Component { } 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."; @@ -387,7 +387,7 @@ class Game extends React.Component { game={this} first_move={first_move} player={state.player_info} - opponents={state.opponent_info} + other_players={state.other_players} />,
{status}
-- 2.43.0