99 lines
2.6 KiB
Swift
99 lines
2.6 KiB
Swift
//
|
|
// BlackjackGameData.swift
|
|
// Blackjack
|
|
//
|
|
// Persistent game data model for iCloud sync.
|
|
//
|
|
|
|
import Foundation
|
|
import CasinoKit
|
|
|
|
/// Saved round result for history.
|
|
struct SavedRoundResult: Codable, Equatable {
|
|
let date: Date
|
|
let mainResult: String // "blackjack", "win", "lose", "push", "bust", "surrender"
|
|
let hadSplit: Bool
|
|
let totalWinnings: Int
|
|
}
|
|
|
|
/// Persistent game data that syncs to iCloud.
|
|
struct BlackjackGameData: PersistableGameData {
|
|
static let gameIdentifier = "blackjack"
|
|
|
|
var roundsPlayed: Int { roundHistory.count }
|
|
var lastModified: Date
|
|
|
|
static var empty: BlackjackGameData {
|
|
BlackjackGameData(
|
|
lastModified: Date(),
|
|
balance: 10_000,
|
|
roundHistory: [],
|
|
totalWinnings: 0,
|
|
biggestWin: 0,
|
|
biggestLoss: 0,
|
|
blackjackCount: 0,
|
|
bustCount: 0
|
|
)
|
|
}
|
|
|
|
var balance: Int
|
|
var roundHistory: [SavedRoundResult]
|
|
var totalWinnings: Int
|
|
var biggestWin: Int
|
|
var biggestLoss: Int
|
|
var blackjackCount: Int
|
|
var bustCount: Int
|
|
}
|
|
|
|
/// Persistent settings data that syncs to iCloud.
|
|
struct BlackjackSettingsData: PersistableGameData {
|
|
static let gameIdentifier = "blackjack_settings"
|
|
var lastModified: Date
|
|
var roundsPlayed: Int = 0 // Settings don't track rounds, use 0
|
|
|
|
static var empty: BlackjackSettingsData {
|
|
BlackjackSettingsData(
|
|
lastModified: Date(),
|
|
roundsPlayed: 0,
|
|
gameStyle: "vegas",
|
|
deckCount: 6,
|
|
tableLimits: "low",
|
|
startingBalance: 10_000,
|
|
dealerHitsSoft17: false,
|
|
doubleAfterSplit: true,
|
|
resplitAces: false,
|
|
lateSurrender: true,
|
|
blackjackPayout: 1.5,
|
|
insuranceAllowed: true,
|
|
showAnimations: true,
|
|
dealingSpeed: 1.0,
|
|
showCardsRemaining: true,
|
|
showHistory: true,
|
|
showHints: true,
|
|
soundEnabled: true,
|
|
hapticsEnabled: true,
|
|
soundVolume: 1.0
|
|
)
|
|
}
|
|
|
|
var gameStyle: String
|
|
var deckCount: Int
|
|
var tableLimits: String
|
|
var startingBalance: Int
|
|
var dealerHitsSoft17: Bool
|
|
var doubleAfterSplit: Bool
|
|
var resplitAces: Bool
|
|
var lateSurrender: Bool
|
|
var blackjackPayout: Double
|
|
var insuranceAllowed: Bool
|
|
var showAnimations: Bool
|
|
var dealingSpeed: Double
|
|
var showCardsRemaining: Bool
|
|
var showHistory: Bool
|
|
var showHints: Bool
|
|
var soundEnabled: Bool
|
|
var hapticsEnabled: Bool
|
|
var soundVolume: Float
|
|
}
|
|
|