Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

게임 결과창에서 Back to Lobby 클릭 시 & 게임중 탈주 시 발생하는 에러 해결 #134

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"},
Comment on lines +63 to +70
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

무엇을 위한 상수값인가요?

{"#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
Loading