diff --git a/client/src/Table.js b/client/src/Table.js index 2d1c70e..1cb5c9c 100755 --- a/client/src/Table.js +++ b/client/src/Table.js @@ -15,6 +15,7 @@ import PlayerColor from './PlayerColor.js'; import Dice from './Dice.js'; import Resource from './Resource.js'; import ViewCard from './ViewCard.js'; +import Winner from './Winner.js'; /* Start of withRouter polyfill */ // https://reactrouter.com/docs/en/v6/faq#what-happened-to-withrouter-i-need-it @@ -1073,6 +1074,10 @@ class Table extends React.Component { } } + { game && game.state === 'winner' && + + } + { this.state.cardActive && } diff --git a/client/src/Winner.css b/client/src/Winner.css new file mode 100644 index 0000000..57a70cd --- /dev/null +++ b/client/src/Winner.css @@ -0,0 +1,37 @@ +.Winner { + display: flex; + position: absolute; + left: 0; + right: 40vw; + bottom: 0; + top: 0; + justify-content: center; + align-items: center; + background: rgba(0,0,0,0.5); + z-index: 1000; +} + +.Winner .Title { + align-self: center; + padding: 2px; + font-weight: bold; + margin-bottom: 0.5em; +} + +.Winner .Description { + padding: 1em; + max-width: 20vw; + box-sizing: border-box; +} + +.Winner > * { +/* min-width: 40em;*/ + display: inline-flex; + padding: 0.5em; + flex-direction: column; +} + +.Winner .Resource { + width: 10em; /* 5x7 aspect ratio */ + height: 14em; +} diff --git a/client/src/Winner.js b/client/src/Winner.js new file mode 100644 index 0000000..d830b5b --- /dev/null +++ b/client/src/Winner.js @@ -0,0 +1,49 @@ +import React from "react"; +import "./Winner.css"; +import Paper from '@material-ui/core/Paper'; +import Button from '@material-ui/core/Button'; +import Resource from './Resource.js'; +import { getPlayerName } from './Common.js'; + +const Winner = ({table, color}) => { + const quitClicked = (event) => { + table.setSelected(""); + } + + if (!table.game) { + return <>; + } + + const name = getPlayerName(table.game.sessions, color), + player = table.game.players[color]; + + let description = <>Congratulations, {name}!; + for (let key in table.game.players) { + if (key === color) { + continue; + } + let tmp = table.game.players[key]; + if (tmp.status === 'Not active') { + continue; + } + let line = <>{getPlayerName(table.game.sessions, key)} finished with {tmp.points} victory points. + description = <>{description}

{line}

; + } + + return ( +
+ +
{name} has won with {player.points} victory points!
+
+ +
+ {description} +
+
+ +
+
+ ); +}; + +export default Winner; \ No newline at end of file diff --git a/server/routes/games.js b/server/routes/games.js index 351b66b..c426490 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -2173,10 +2173,17 @@ const sendGame = async (req, res, game, error) => { player.points += MAX_SETTLEMENTS - player.settlements; player.points += 2 * (MAX_CITIES - player.cities); - if (!game.winner && player.points > 10 && session.color === key) { + player.development.forEach(card => { + if (card.type === 'vp' && card.played) { + player.points++; + } + }); + + if (!game.winner && (player.points >= 10 && session.color === key)) { addChatMessage(game, null, `${playerNameFromColor(game, key)} won the game with ${player.points} victory points!`); - game.winner = player; + game.winner = key; game.state = 'winner'; + delete game.turn.roll; } }