diff --git a/src/main/client/public/stone1.wav b/src/main/client/public/stone1.wav index 4c58417..0ba7f88 100644 Binary files a/src/main/client/public/stone1.wav and b/src/main/client/public/stone1.wav differ diff --git a/src/main/client/src/component/Chat.jsx b/src/main/client/src/component/Chat.jsx index 2a6089b..6e4966b 100644 --- a/src/main/client/src/component/Chat.jsx +++ b/src/main/client/src/component/Chat.jsx @@ -108,7 +108,14 @@ export const Chat = ({chatId, className}) => { } bottomElement={<> {messages.map(message => ( -

{message.user + ": " + message.message}

+

+ { + message.user ? ( + {message.user + ": " + message.message} + ) : ( + {message.message} + )} +

))} } /> diff --git a/src/main/client/src/feature/game/GamePanel.jsx b/src/main/client/src/feature/game/GamePanel.jsx index a5a3034..8b95b00 100644 --- a/src/main/client/src/feature/game/GamePanel.jsx +++ b/src/main/client/src/feature/game/GamePanel.jsx @@ -1,6 +1,7 @@ import { useCallback, useContext, + useEffect, } from "react" import { useParams, @@ -18,10 +19,6 @@ import { } from "react-icons" import { StompContext, - BLACK, - WHITE, - TERRITORY_B, - TERRITORY_W, base, } from "src/util.js" import { @@ -48,7 +45,6 @@ import { moveForward, countingAgreed, gameHasEnded, - isReviewing, } from "./state.js" export const GamePanel = ({gameState, setGameState}) => { @@ -70,6 +66,7 @@ function Panel({gameState, setGameState}) { let {black, white, viewPos, counting, board} = gameState let movesLength = gameState.moves.length let navigate = useNavigate() + let onExit = useCallback(() => { navigate(base + "/lobby") }, [navigate]) @@ -103,7 +100,6 @@ function Panel({gameState, setGameState}) { if (!board.length) { return Loading... } - let result = gameHasEnded(gameState) ? getScore(board) : undefined return ( <>
@@ -192,28 +188,7 @@ function Panel({gameState, setGameState}) {
} - {result && !isReviewing(gameState) && ( -
- {(result.w > result.b ? "W+" : "B+") + Math.abs(result.b - result.w)} -
- )} ) } - -function getScore(board) { - let w = 0, b = 0 - for (let y = 0; y < board.length; y++) { - for (let x = 0; x < board[y].length; x++) { - let { color } = board[y][x] - if ((color & WHITE) || (color & TERRITORY_W)) { - w++ - } - if ((color & BLACK) || (color & TERRITORY_B)) { - b++ - } - } - } - return {w, b} -} diff --git a/src/main/java/com/bernd/GameController.java b/src/main/java/com/bernd/GameController.java index c31d3fa..c68e9c8 100644 --- a/src/main/java/com/bernd/GameController.java +++ b/src/main/java/com/bernd/GameController.java @@ -4,10 +4,14 @@ import com.bernd.game.MoveList; import com.bernd.model.AcceptRequest; import com.bernd.model.ActiveGame; +import com.bernd.model.Chat; +import com.bernd.model.ChatMessage; +import com.bernd.model.ChatRequest; import com.bernd.model.Game; import com.bernd.model.Move; import com.bernd.model.OpenGame; import com.bernd.model.ViewGame; +import com.bernd.util.Auth; import com.bernd.util.RandomString; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -82,6 +86,12 @@ public void action(Move move, Principal p) { Game updated = game.update(updatedMove); games.put(updated); Move lastMove = game.getLastMove(); + if (lastMove.end()) { + Chat chat = chats.get(game.id()); + ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), game.getScore(), null); + chat.messages().add(message); + operations.convertAndSend("/topic/chat/" + chat.id(), message); + } operations.convertAndSend("/topic/move/" + game.id(), lastMove.removeColor()); } diff --git a/src/main/java/com/bernd/model/Game.java b/src/main/java/com/bernd/model/Game.java index 0691cdd..2c8456d 100644 --- a/src/main/java/com/bernd/model/Game.java +++ b/src/main/java/com/bernd/model/Game.java @@ -4,6 +4,7 @@ import com.bernd.game.Direction; import com.bernd.game.MoveList; import com.bernd.game.Toggle; +import com.bernd.game.Board; import com.bernd.util.BoardUpdateImpl; import com.bernd.util.Util; import org.apache.logging.log4j.LogManager; @@ -190,4 +191,21 @@ public int remainingHandicap() { public boolean isForbidden(Move move) { return move.x() == forbidden[0] && move.y() == forbidden[1]; } + + public String getScore() { + int w = 0; + int b = 0; + for (int y = 0; y < board().length; y++){ + for (int x = 0; x < board[y].length; x++){ + int color = board[y][x]; + if ((color & (Board.W | Board.TERRITORY_W)) != 0) { + w++; + } + if ((color & (Board.B | Board.TERRITORY_B)) != 0) { + b++; + } + } + } + return w > b ? "W+" + w : "B+" + b; + } }