Schafkopf-Server/Sources/App/GameSummary/EnglishGameSummarizer.swift
2021-12-21 09:53:20 +01:00

40 lines
943 B
Swift

import Foundation
struct EnglishGameSummarizer: GameSummarizer {
let game: GameStatistics
private var winText: String {
game.didWin ? "won" : "lost"
}
private var gameText: String {
"game"
}
private var coPlayerNames: String {
switch game.coPlayers.count {
case 0:
return ""
case 1:
return " with \(game.coPlayers[0])"
case 2:
return " with \(game.coPlayers[0]) and \(game.coPlayers[1])"
default:
return ""
}
}
private var costText: String {
guard game.cost >= 100 else {
return "\(game.cost) cents"
}
return String(format: "%d.%02d €", game.cost / 100, game.cost % 100)
}
var text: String {
"\(game.leader) \(winText) a \(gameText)\(coPlayerNames) collecting \(game.leaderPoints) points. " +
"The game cost \(costText)."
}
}