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

feat : 방 나가기 API 구현 #41

Merged
merged 9 commits into from
Dec 5, 2024
Merged

feat : 방 나가기 API 구현 #41

merged 9 commits into from
Dec 5, 2024

Conversation

ckkim817
Copy link
Contributor

@ckkim817 ckkim817 commented Dec 5, 2024


게임 도중 퇴장할 경우 레이팅을 고정값으로 300만큼 감소시킵니다.

if (roomManager.isGameInProgress(roomId)) {
User user = roomManager.getUserById(userId);
if (user.getRating() < 300) {
user.setRating(0);
} else {
roomManager.decreaseRating(userId, 300);
}
}


나간 유저가 호스트 유저였을 경우, 그 다음으로 방에 들어온 유저에게 호스트를 넘깁니다.
마지막으로 남아있던 유저가 나갔을 경우엔 해당 방 스레드를 종료시킵니다.

// userWriter의 1번째 index의 key를 hostUserId로 설정
public void setHostUserId() {
if (!userWriter.isEmpty()) {
this.hostUserId = userWriter.keySet().iterator().next();
} else {
this.roomThread.stopThread();
}
}


방에 참여 중인 유저 닉네임 리스트를 JsonArray로 감싸 반환합니다.

// 방에 참여 중인 유저 닉네임 리스트를 JsonArray로 반환
public JsonArray getUserNicknameList() {
JsonArray userNicknameList = new JsonArray();
userWriter.keySet().forEach(userId -> {
String userNickname = userManager.getUserNicknameById(userId);
JsonObject userNicknameJson = new JsonObject();
userNicknameJson.addProperty("userName", userNickname);
userNicknameList.add(userNicknameJson);
});
return userNicknameList;
}


현재 제 코드에서는 레이팅이 수정된 후 유저 데이터 파일에 따로 저장하는 부분이 없습니다. 9번 만드시면서 구현해놓으신 것 같아 9번 머지하시면 풀 받아서 게임 도중 퇴장 시 레이팅이 감소할 때도 해당 부분 사용해서 DB에 저장할 수 있도록 하겠습니다.

@ckkim817 ckkim817 requested a review from minseok1015 December 5, 2024 19:39
@ckkim817 ckkim817 self-assigned this Dec 5, 2024
Copy link
Collaborator

@minseok1015 minseok1015 left a comment

Choose a reason for hiding this comment

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

넵 늦은 시간까지 고생많으셨습니다. rating관련해서 저랑 겹치는 부분은 머지후 수정하도록 하는게 좋을 것 같습니다!!

Comment on lines 81 to 83
public String getUserNicknameById(int userId) {
return users.get(userId).getNickname();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분 getUserNickname(int userId)으로 겹쳐있어서 머지하고서 수정하도록 하겠습니다.

@ckkim817 ckkim817 merged commit 7a44032 into fix/#37 Dec 5, 2024
@ckkim817 ckkim817 deleted the feat/#39 branch December 5, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants