Show proper game summary
This commit is contained in:
@ -2,38 +2,84 @@ import Foundation
|
||||
|
||||
struct EnglishGameSummarizer: GameSummarizer {
|
||||
|
||||
let game: GameSummary
|
||||
let table: FinishedTable
|
||||
|
||||
private var winText: String {
|
||||
game.didWin ? "won" : "lost"
|
||||
table.selectorDidWin ? "won" : "lost"
|
||||
}
|
||||
|
||||
private var gameText: String {
|
||||
"game"
|
||||
switch table.game {
|
||||
case .rufBlatt:
|
||||
return "the call of Blatt"
|
||||
case .rufEichel:
|
||||
return "the call of Eichel"
|
||||
case .rufSchelln:
|
||||
return "the call of Schelln"
|
||||
case .bettel:
|
||||
return "the Bettel"
|
||||
case .geier:
|
||||
return "the Geier"
|
||||
case .wenz:
|
||||
return "the Wenz"
|
||||
case .hochzeit:
|
||||
return "the wedding"
|
||||
case .soloBlatt:
|
||||
return "the Solo Blatt"
|
||||
case .soloEichel:
|
||||
return "the Solo Eichel"
|
||||
case .soloHerz:
|
||||
return "the Solo Herz"
|
||||
case .soloSchelln:
|
||||
return "the Solo Schelln"
|
||||
}
|
||||
}
|
||||
|
||||
private var coPlayerNames: String {
|
||||
switch game.coPlayers.count {
|
||||
let coPlayers = table.coPlayers
|
||||
switch coPlayers.count {
|
||||
case 0:
|
||||
return ""
|
||||
case 1:
|
||||
return " with \(game.coPlayers[0])"
|
||||
return " with \(coPlayers[0].name)"
|
||||
case 2:
|
||||
return " with \(game.coPlayers[0]) and \(game.coPlayers[1])"
|
||||
return " with \(coPlayers[0].name) and \(coPlayers[1].name)"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
private var costText: String {
|
||||
guard game.cost >= 100 else {
|
||||
return "\(game.cost) cents"
|
||||
let cost = table.cost
|
||||
guard cost >= 100 else {
|
||||
return "\(cost) cents"
|
||||
}
|
||||
return String(format: "%d.%02d €", game.cost / 100, game.cost % 100)
|
||||
return String(format: "%d.%02d €", cost / 100, cost % 100)
|
||||
}
|
||||
|
||||
private var costExplanation: String {
|
||||
var components = [String]()
|
||||
components.append("Game \(table.game.basicCost)")
|
||||
if !table.isBettel {
|
||||
if table.isSchwarz {
|
||||
components.append("Schwarz")
|
||||
} else if table.isSchneider {
|
||||
components.append("Schneider")
|
||||
}
|
||||
if table.leadingTrumps > 0 {
|
||||
components.append("\(table.leadingTrumps) Laufende")
|
||||
}
|
||||
}
|
||||
components.append("\(table.totalNumberOfDoubles)x doubled")
|
||||
return components.joined(separator: ", ")
|
||||
}
|
||||
|
||||
var text: String {
|
||||
"\(game.leader) \(winText) a \(gameText)\(coPlayerNames) collecting \(game.leaderPoints) points. " +
|
||||
"The game cost \(costText)."
|
||||
let start = "\(table.gameSelector.name) \(winText) the \(gameText)"
|
||||
let cost = " The game costs \(costText) (\(costExplanation))."
|
||||
guard table.game != .bettel else {
|
||||
return start + cost
|
||||
}
|
||||
return start + "\(coPlayerNames) with \(table.selectorTeamPoints) points." + cost
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ import Foundation
|
||||
|
||||
protocol GameSummarizer {
|
||||
|
||||
init(game: GameSummary)
|
||||
var table: FinishedTable { get }
|
||||
|
||||
init(table: FinishedTable)
|
||||
|
||||
var text: String { get }
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ import Foundation
|
||||
|
||||
struct GermanGameSummarizer: GameSummarizer {
|
||||
|
||||
let game: GameSummary
|
||||
let table: FinishedTable
|
||||
|
||||
var winText: String {
|
||||
game.didWin ? "gewinnt" : "verliert"
|
||||
private var winText: String {
|
||||
table.selectorDidWin ? "gewinnt" : "verliert"
|
||||
}
|
||||
|
||||
var gameText: String {
|
||||
switch GameType(id: game.game)! {
|
||||
private var gameText: String {
|
||||
switch table.game {
|
||||
case .rufBlatt:
|
||||
return "den Ruf Blatt"
|
||||
case .rufEichel:
|
||||
@ -35,28 +35,51 @@ struct GermanGameSummarizer: GameSummarizer {
|
||||
}
|
||||
}
|
||||
|
||||
var coPlayerNames: String {
|
||||
switch game.coPlayers.count {
|
||||
private var coPlayerNames: String {
|
||||
let coPlayers = table.coPlayers
|
||||
switch coPlayers.count {
|
||||
case 0:
|
||||
return ""
|
||||
case 1:
|
||||
return " mit \(game.coPlayers[0])"
|
||||
return " mit \(coPlayers[0].name)"
|
||||
case 2:
|
||||
return " mit \(game.coPlayers[0]) und \(game.coPlayers[1])"
|
||||
return " mit \(coPlayers[0].name) und \(coPlayers[1].name)"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
var costText: String {
|
||||
guard game.cost >= 100 else {
|
||||
return "\(game.cost) Cent"
|
||||
private var costText: String {
|
||||
let cost = table.cost
|
||||
guard cost >= 100 else {
|
||||
return "\(cost) Cent"
|
||||
}
|
||||
return String(format: "%d.%02d €", game.cost / 100, game.cost % 100)
|
||||
return String(format: "%d.%02d €", cost / 100, cost % 100)
|
||||
}
|
||||
|
||||
private var costExplanation: String {
|
||||
var components = [String]()
|
||||
components.append("Grundspiel \(table.game.basicCost)")
|
||||
if !table.isBettel {
|
||||
if table.isSchwarz {
|
||||
components.append("Schwarz")
|
||||
} else if table.isSchneider {
|
||||
components.append("Schneider")
|
||||
}
|
||||
if table.leadingTrumps > 0 {
|
||||
components.append("\(table.leadingTrumps) Laufende")
|
||||
}
|
||||
}
|
||||
components.append("\(table.totalNumberOfDoubles)x gedoppelt")
|
||||
return components.joined(separator: ", ")
|
||||
}
|
||||
|
||||
var text: String {
|
||||
"\(game.leader) \(winText) \(gameText)\(coPlayerNames) mit \(game.leaderPoints) Punkten. " +
|
||||
"Das Spiel kostet \(costText)."
|
||||
let start = "\(table.gameSelector.name) \(winText) \(gameText)"
|
||||
let cost = " Das Spiel kostet \(costText) (\(costExplanation))."
|
||||
guard table.game != .bettel else {
|
||||
return start + cost
|
||||
}
|
||||
return start + "\(coPlayerNames) mit \(table.selectorTeamPoints) Punkten." + cost
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user