Skip to content

Commit b4e55a1

Browse files
Christopher Straussh908714124
Christopher Strauss
authored andcommitted
Ergebnis message
1 parent bf7b93b commit b4e55a1

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

src/main/client/public/stone1.wav

-42.4 KB
Binary file not shown.

src/main/client/src/component/Chat.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ export const Chat = ({chatId, className}) => {
108108
</>}
109109
bottomElement={<>
110110
{messages.map(message => (
111-
<p key={message.n}>{message.user + ": " + message.message}</p>
111+
<p key={message.n}>
112+
{
113+
message.user ? (
114+
<span>{message.user + ": " + message.message}</span>
115+
) : (
116+
<span className="italic text-gray-400">{message.message}</span>
117+
)}
118+
</p>
112119
))}
113120
</>}
114121
/>

src/main/client/src/feature/game/GamePanel.jsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
useCallback,
33
useContext,
4+
useEffect,
45
} from "react"
56
import {
67
useParams,
@@ -18,10 +19,6 @@ import {
1819
} from "react-icons"
1920
import {
2021
StompContext,
21-
BLACK,
22-
WHITE,
23-
TERRITORY_B,
24-
TERRITORY_W,
2522
base,
2623
} from "src/util.js"
2724
import {
@@ -48,7 +45,6 @@ import {
4845
moveForward,
4946
countingAgreed,
5047
gameHasEnded,
51-
isReviewing,
5248
} from "./state.js"
5349

5450
export const GamePanel = ({gameState, setGameState}) => {
@@ -70,6 +66,7 @@ function Panel({gameState, setGameState}) {
7066
let {black, white, viewPos, counting, board} = gameState
7167
let movesLength = gameState.moves.length
7268
let navigate = useNavigate()
69+
7370
let onExit = useCallback(() => {
7471
navigate(base + "/lobby")
7572
}, [navigate])
@@ -103,7 +100,6 @@ function Panel({gameState, setGameState}) {
103100
if (!board.length) {
104101
return <span>Loading...</span>
105102
}
106-
let result = gameHasEnded(gameState) ? getScore(board) : undefined
107103
return (
108104
<>
109105
<div className="flex-none flex w-full gap-x-2">
@@ -192,28 +188,7 @@ function Panel({gameState, setGameState}) {
192188
</Button>
193189
</div>
194190
</>}
195-
{result && !isReviewing(gameState) && (
196-
<div className="flex-none">
197-
{(result.w > result.b ? "W+" : "B+") + Math.abs(result.b - result.w)}
198-
</div>
199-
)}
200191
<Chat className="mt-1" chatId={gameId}/>
201192
</>
202193
)
203194
}
204-
205-
function getScore(board) {
206-
let w = 0, b = 0
207-
for (let y = 0; y < board.length; y++) {
208-
for (let x = 0; x < board[y].length; x++) {
209-
let { color } = board[y][x]
210-
if ((color & WHITE) || (color & TERRITORY_W)) {
211-
w++
212-
}
213-
if ((color & BLACK) || (color & TERRITORY_B)) {
214-
b++
215-
}
216-
}
217-
}
218-
return {w, b}
219-
}

src/main/java/com/bernd/GameController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
import com.bernd.game.MoveList;
55
import com.bernd.model.AcceptRequest;
66
import com.bernd.model.ActiveGame;
7+
import com.bernd.model.Chat;
8+
import com.bernd.model.ChatMessage;
9+
import com.bernd.model.ChatRequest;
710
import com.bernd.model.Game;
811
import com.bernd.model.Move;
912
import com.bernd.model.OpenGame;
1013
import com.bernd.model.ViewGame;
14+
import com.bernd.util.Auth;
1115
import com.bernd.util.RandomString;
1216
import org.springframework.http.HttpStatus;
1317
import org.springframework.http.ResponseEntity;
@@ -82,6 +86,12 @@ public void action(Move move, Principal p) {
8286
Game updated = game.update(updatedMove);
8387
games.put(updated);
8488
Move lastMove = game.getLastMove();
89+
if (lastMove.end()) {
90+
Chat chat = chats.get(game.id());
91+
ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), game.getScore(), null);
92+
chat.messages().add(message);
93+
operations.convertAndSend("/topic/chat/" + chat.id(), message);
94+
}
8595
operations.convertAndSend("/topic/move/" + game.id(), lastMove.removeColor());
8696
}
8797

src/main/java/com/bernd/model/Game.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.bernd.game.Direction;
55
import com.bernd.game.MoveList;
66
import com.bernd.game.Toggle;
7+
import com.bernd.game.Board;
78
import com.bernd.util.BoardUpdateImpl;
89
import com.bernd.util.Util;
910
import org.apache.logging.log4j.LogManager;
@@ -190,4 +191,21 @@ public int remainingHandicap() {
190191
public boolean isForbidden(Move move) {
191192
return move.x() == forbidden[0] && move.y() == forbidden[1];
192193
}
194+
195+
public String getScore() {
196+
int w = 0;
197+
int b = 0;
198+
for (int y = 0; y < board().length; y++){
199+
for (int x = 0; x < board[y].length; x++){
200+
int color = board[y][x];
201+
if ((color & (Board.W | Board.TERRITORY_W)) != 0) {
202+
w++;
203+
}
204+
if ((color & (Board.B | Board.TERRITORY_B)) != 0) {
205+
b++;
206+
}
207+
}
208+
}
209+
return w > b ? "W+" + w : "B+" + b;
210+
}
193211
}

0 commit comments

Comments
 (0)