Skip to content

Commit

Permalink
Merge pull request #114 from DeveloperAcademy-POSTECH/feat/#113-AddWi…
Browse files Browse the repository at this point in the history
…nCase

[Feat] #113-진행자를 이겼을 때 isWin으로 설정 및 리스트 정렬 수정
  • Loading branch information
HyunJaeyeon authored Dec 4, 2024
2 parents 8182a35 + 0ea2afe commit 14ff728
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions PepperoniV2/Presentation/Game/RankingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct RankingView: View {
ScrollView {
ForEach(rankedPlayers.indices, id: \.self) { index in
let player = rankedPlayers[index]
let isWin = player.score > rankedPlayers.first(where: { $0.isHost })?.score ?? 0
let isHost = player.isHost
let isWin = !isHost && (player.score / 3) >= (rankedPlayers.first(where: { $0.isHost })?.score ?? 0) / 3

RankRow(player: player,
rank: index + 1,
Expand Down Expand Up @@ -63,7 +64,15 @@ struct RankingView: View {
)
}
.onAppear {
rankedPlayers = gameViewModel.players.sorted { $0.score > $1.score }
rankedPlayers = gameViewModel.players.sorted {
if $0.score / 3 != $1.score / 3 {
// 점수를 기준으로 내림차순 정렬
return $0.score / 3 > $1.score / 3
} else {
// 점수가 같으면 진행자가 아닌 참가자가 우선
return !$0.isHost && $1.isHost
}
}
rowVisible = Array(repeating: false, count: rankedPlayers.count) // 초기화
}
.navigationBarBackButtonHidden(true)
Expand Down Expand Up @@ -229,8 +238,8 @@ struct RankingView_Previews: PreviewProvider {
let samplePlayers = [
Player(nickname: "참가자1", turn:0, score: 300),
Player(nickname: "참가자3", turn:1, score: 297),
Player(nickname: "진행자", turn:2, score: 273, isHost: true),
Player(nickname: "참가자4", turn:3, score: 130),
Player(nickname: "진행자", turn:2, score: 296, isHost: true),
Player(nickname: "참가자4", turn:3, score: 294),
Player(nickname: "참가자5", turn:0, score: 100),
Player(nickname: "참가자2", turn:1, score: 0)
]
Expand Down

0 comments on commit 14ff728

Please sign in to comment.