Files
KnockOutWhist-Web/knockoutwhistweb/app/dto/subDTO/PodiumPlayerDTO.scala
Janis 8d697fd311 feat: BAC-30 Implement Jackson Mapping via DTOs (#102)
Reviewed-on: #102
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
2025-12-06 10:17:04 +01:00

47 lines
1.2 KiB
Scala

package dto.subDTO
import de.knockoutwhist.control.GameLogic
import de.knockoutwhist.player.AbstractPlayer
import de.knockoutwhist.rounds.Match
case class PodiumPlayerDTO(
player: PlayerDTO,
position: Int,
roundsWon: Int,
tricksWon: Int
)
object PodiumPlayerDTO {
def apply(gameLogic: GameLogic, player: AbstractPlayer): PodiumPlayerDTO = {
val matchImplOpt = gameLogic.getCurrentMatch
if (matchImplOpt.isEmpty) {
throw new IllegalStateException("No current match available in game logic")
}
val matchImpl: Match = matchImplOpt.get
var roundsWon = 0
var tricksWon = 0
for (round <- matchImpl.roundlist) {
if (round.winner.contains(player)) {
roundsWon += 1
}
for (trick <- round.tricklist) {
if (trick.winner.contains(player)) {
tricksWon += 1
}
}
}
PodiumPlayerDTO(
player = PlayerDTO(player),
position = if (gameLogic.getWinner.contains(player)) {
1
} else {
2
},
roundsWon = roundsWon,
tricksWon = tricksWon
)
}
}