X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=tictactoe%2Ftictactoe.jsx;h=ca0bce3fd4985bf8636893cbfeae92ea4235508b;hp=f0e9e88d6a83f6a9262cbb47a467f293a431b3a7;hb=9848e7d60b7ad9153b5763801382b880535e8cc6;hpb=d3a035c38d6deff85f63e313430ac7e45955e2a9 diff --git a/tictactoe/tictactoe.jsx b/tictactoe/tictactoe.jsx index f0e9e88..ca0bce3 100644 --- a/tictactoe/tictactoe.jsx +++ b/tictactoe/tictactoe.jsx @@ -91,18 +91,59 @@ function GameInfo(props) { ); } +function TeamButton(props) { + return ; +} + +function TeamChoices(props) { + let other_team; + if (props.player.team === "X") + other_team = "O"; + else + other_team = "X"; + + if (props.player.team === "") { + if (props.first_move) { + return null; + } else { + return [ + , + " ", + + ]; + } + } else { + return ; + } +} + function PlayerInfo(props) { if (! props.player.id) return null; + const choices = ; + return (

Players

{props.player.name} {props.player.team ? ` (${props.player.team})` : ""} - {", "} - {props.opponent.name} - {props.opponent.team ? ` (${props.opponent.team})` : ""} + {props.first_move ? "" : " "} + {choices} + {props.opponents.map(opponent => ( + + {", "} + {opponent.name} + {opponent.team ? ` (${opponent.team})` : ""} + + ))}
); } @@ -186,7 +227,7 @@ class Game extends React.Component { this.state = { game_info: {}, player_info: {}, - opponent_info: {}, + opponent_info: [], history: [ { squares: Array(9).fill(null) @@ -210,8 +251,15 @@ 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); + if (idx >= 0) { + new_opponents[idx] = info; + } else { + new_opponents.push(info); + } this.setState({ - opponent_info: info + opponent_info: new_opponents }); } @@ -321,15 +369,12 @@ class Game extends React.Component { />, ,
- - {" "} -
{status}