Organize files
This commit is contained in:
130
Sources/App/Model/Games/GameClass.swift
Normal file
130
Sources/App/Model/Games/GameClass.swift
Normal file
@ -0,0 +1,130 @@
|
||||
import Foundation
|
||||
|
||||
extension GameType {
|
||||
|
||||
var gameClass: GameClass {
|
||||
switch self {
|
||||
case .rufEichel, .rufBlatt, .rufSchelln, .hochzeit:
|
||||
return .ruf
|
||||
case .bettel:
|
||||
return .bettel
|
||||
case .wenz, .geier:
|
||||
return .wenz
|
||||
case .soloEichel, .soloBlatt, .soloHerz, .soloSchelln:
|
||||
return .solo
|
||||
}
|
||||
}
|
||||
|
||||
enum GameClass: String {
|
||||
case none = "none"
|
||||
case ruf = "ruf"
|
||||
case hochzeit = "hochzeit"
|
||||
case bettel = "bettel"
|
||||
case wenz = "wenz"
|
||||
case geier = "geier"
|
||||
case solo = "solo"
|
||||
|
||||
var cost: Int {
|
||||
switch self {
|
||||
case .none: return 0
|
||||
case .ruf: return 5
|
||||
case .hochzeit: return 10
|
||||
case .bettel: return 15
|
||||
case .wenz, .geier, .solo: return 20
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
mutating func increase() -> Bool {
|
||||
switch self {
|
||||
case .none:
|
||||
self = .ruf
|
||||
case .ruf:
|
||||
self = .bettel
|
||||
case .hochzeit:
|
||||
self = .bettel
|
||||
case .bettel:
|
||||
self = .wenz
|
||||
case .wenz, .geier:
|
||||
self = .solo
|
||||
case .solo:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func increased() -> GameClass? {
|
||||
switch self {
|
||||
case .none:
|
||||
return .ruf
|
||||
case .ruf:
|
||||
return .bettel
|
||||
case .hochzeit:
|
||||
return .bettel
|
||||
case .bettel:
|
||||
return .wenz
|
||||
case .wenz, .geier:
|
||||
return .solo
|
||||
case .solo:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var allowsWedding: Bool {
|
||||
switch self {
|
||||
case .none, .ruf:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func allows(game: GameType) -> Bool {
|
||||
availableGames.contains(game)
|
||||
}
|
||||
|
||||
var availableGames: [GameType] {
|
||||
switch self {
|
||||
case .none, .ruf:
|
||||
return GameType.allCases
|
||||
case .hochzeit, .bettel:
|
||||
return [.bettel, .wenz, .geier, .soloEichel, .soloBlatt, .soloHerz, .soloSchelln]
|
||||
case .wenz, .geier:
|
||||
return [.wenz, .geier, .soloEichel, .soloBlatt, .soloHerz, .soloSchelln]
|
||||
case .solo:
|
||||
return [.soloEichel, .soloBlatt, .soloHerz, .soloSchelln]
|
||||
}
|
||||
}
|
||||
|
||||
var availableClasses: [GameClass] {
|
||||
switch self {
|
||||
case .none, .ruf:
|
||||
return [.ruf, .bettel, .wenz, .geier, .solo]
|
||||
case .hochzeit, .bettel:
|
||||
return [.bettel, .wenz, .geier, .solo]
|
||||
case .wenz, .geier:
|
||||
return [.wenz, .geier, .solo]
|
||||
case .solo:
|
||||
return [.solo]
|
||||
}
|
||||
}
|
||||
|
||||
var classesWhenOutbidding: [GameClass] {
|
||||
increased()?.availableClasses ?? []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension GameType.GameClass: Comparable {
|
||||
|
||||
static func < (lhs: GameType.GameClass, rhs: GameType.GameClass) -> Bool {
|
||||
lhs.rawValue < rhs.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
extension GameType.GameClass: GameConvertible {
|
||||
|
||||
var id: GameId {
|
||||
rawValue
|
||||
}
|
||||
}
|
6
Sources/App/Model/Games/GameConvertible.swift
Normal file
6
Sources/App/Model/Games/GameConvertible.swift
Normal file
@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
protocol GameConvertible {
|
||||
|
||||
var id: GameId { get }
|
||||
}
|
28
Sources/App/Model/Games/GamePhase.swift
Normal file
28
Sources/App/Model/Games/GamePhase.swift
Normal file
@ -0,0 +1,28 @@
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
The phase of a table
|
||||
*/
|
||||
enum GamePhase: String, Codable {
|
||||
|
||||
/// The table is not yet full, so no game can be started
|
||||
case waitingForPlayers = "waiting"
|
||||
|
||||
/// The players are specifying if they want to double ("legen")
|
||||
case collectingDoubles = "doubles"
|
||||
|
||||
/// The game negotiation is ongoing
|
||||
case bidding = "bidding"
|
||||
|
||||
/// The game must be selected by the player
|
||||
case selectGame = "select"
|
||||
|
||||
/// The game is in progress
|
||||
case playing = "play"
|
||||
|
||||
/// The player must select a card to give to the wedding offerer
|
||||
case selectWeddingCard = "wedding"
|
||||
|
||||
/// The game is over
|
||||
case gameFinished = "done"
|
||||
}
|
83
Sources/App/Model/Games/GameType.swift
Normal file
83
Sources/App/Model/Games/GameType.swift
Normal file
@ -0,0 +1,83 @@
|
||||
import Foundation
|
||||
|
||||
/// The string id of a game
|
||||
typealias GameId = String
|
||||
|
||||
enum GameType: String, CaseIterable, Codable {
|
||||
|
||||
case rufEichel = "ruf-eichel"
|
||||
case rufBlatt = "ruf-blatt"
|
||||
case rufSchelln = "ruf-schelln"
|
||||
case hochzeit = "hochzeit"
|
||||
case bettel = "bettel"
|
||||
case wenz = "wenz"
|
||||
case geier = "geier"
|
||||
case soloEichel = "solo-eichel"
|
||||
case soloBlatt = "solo-blatt"
|
||||
case soloHerz = "solo-herz"
|
||||
case soloSchelln = "solo-schelln"
|
||||
|
||||
init?(id: GameId) {
|
||||
self.init(rawValue: id)
|
||||
}
|
||||
|
||||
var isCall: Bool {
|
||||
switch self {
|
||||
case .rufEichel, .rufBlatt, .rufSchelln:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var calledSuit: Card.Suit? {
|
||||
switch self {
|
||||
case .rufEichel:
|
||||
return .eichel
|
||||
case .rufBlatt:
|
||||
return .blatt
|
||||
case .rufSchelln:
|
||||
return .schelln
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var isSingleGame: Bool {
|
||||
switch self {
|
||||
case .rufEichel, .rufBlatt, .rufSchelln, .hochzeit:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
var basicCost: Int {
|
||||
gameClass.cost
|
||||
}
|
||||
|
||||
var sortingType: CardOrder.Type {
|
||||
switch self {
|
||||
case .wenz:
|
||||
return WenzCardOrder.self
|
||||
case .geier:
|
||||
return GeierCardOrder.self
|
||||
case .soloEichel:
|
||||
return SoloEichelCardOrder.self
|
||||
case .soloBlatt:
|
||||
return SoloBlattCardOrder.self
|
||||
case .soloSchelln:
|
||||
return SoloSchellnCardOrder.self
|
||||
default:
|
||||
return NormalCardOrder.self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension GameType: GameConvertible {
|
||||
|
||||
var id: GameId {
|
||||
rawValue
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user