Skip to content

Commit

Permalink
Merge pull request #134 from HandTris/#133
Browse files Browse the repository at this point in the history
๊ฒŒ์ž„ ๊ฒฐ๊ณผ์ฐฝ์—์„œ Back to Lobby ํด๋ฆญ ์‹œ & ๊ฒŒ์ž„์ค‘ ํƒˆ์ฃผ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ ํ•ด๊ฒฐ
  • Loading branch information
seonghoo1217 authored Jul 14, 2024
2 parents 15bbe5b + e109729 commit 65ebe12
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ public GameRoom exitGameRoom(@UserNicknameFromJwt String nickname, String roomCo
Pair<String, MemberRecordDetailRes> memberDetails = memberProfileService.getMemberProfileWithStatsByNickname(nickname);
GameMemberEssentialDTO dto = new GameMemberEssentialDTO(nickname, memberDetails.getFirst(), memberDetails.getSecond());

if (!gameMember.isPresentMember(dto)) {
if (!gameMember.isPresentMember(nickname)) {
throw new MemberNotFoundException();
}

// gameMember์—์„œ ํ•ด๋‹น ์œ ์ € ์‚ญ์ œ
gameMember.removeMember(dto);
gameMember.removeMember(nickname);

// Redis์— ์—…๋ฐ์ดํŠธ
// ๋งŒ์•ฝ ์ธ์›์ด 0๋ช…์ด๋ผ๋ฉด
if (gameRoom.getParticipantCount() == 0) {
gameRoomRepository.delete(gameRoom);
redisTemplate.delete(key);
} else {
}
// ์ธ์›์ด ๋‚จ์•„์žˆ๋‹ค๋ฉด
else {
redisTemplate.delete(key);
redisTemplate.opsForValue().set(key, gameMember.toString());
}
return gameRoom;
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/jungle/HandTris/domain/GameMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ public void addMember(GameMemberEssentialDTO dto) {
this.members.add(dto);
}

public void removeMember(GameMemberEssentialDTO dto) {
this.members.remove(dto);
public void removeMember(String nickname) {

GameMemberEssentialDTO foundDTO = this.members.stream().filter(gameMemberEssentialDTO -> gameMemberEssentialDTO.nickname().equals(nickname)).findAny().orElse(null);
this.members.remove(foundDTO);
}

public boolean isPresentMember(GameMemberEssentialDTO dto) {
return this.members.contains(dto);
public boolean isPresentMember(String nickname) {

GameMemberEssentialDTO foundDTO = this.members.stream().filter(gameMemberEssentialDTO -> gameMemberEssentialDTO.nickname().equals(nickname)).findAny().orElse(null);
return foundDTO != null;
}

public GameMember(String id, GameMemberEssentialDTO member) {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/jungle/HandTris/presentation/TetrisController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,26 @@ public void handleDisconnect(SimpMessageHeaderAccessor headerAccessor, @Destinat
// message์—์„œ isStart ํ™•์ธ
boolean isStart = headerAccessor.getFirstNativeHeader("isStart").equals("true");
if (isStart) {
String[][] emptyBoard = {{}};
String[][] emptyBoard = {{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "orange", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"},
{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}};
// ํƒˆ์ฃผ ์œ ์ €์˜ ์ƒ๋Œ€์—๊ฒŒ ์Šน๋ฆฌ ๋ฉ”์„ธ์ง€ ๋ณด๋‚ด๊ธฐ ------------------------------
TetrisMessageReq win = new TetrisMessageReq(emptyBoard, true, false, false);
String otherUser = headerAccessor.getHeader("otherUser").toString();
Expand Down

0 comments on commit 65ebe12

Please sign in to comment.