Player actions, playable cards
This commit is contained in:
@ -76,7 +76,7 @@ final class Database {
|
||||
- Parameter isPublic: Indicates that this is a game joinable by everyone
|
||||
- Returns: The table id
|
||||
*/
|
||||
func createTable(named name: TableName, player: PlayerName, isPublic: Bool) -> TableId {
|
||||
func createTable(named name: TableName, player: PlayerName, isPublic: Bool) -> TableInfo {
|
||||
tables.createTable(named: name, player: player, isPublic: isPublic)
|
||||
}
|
||||
|
||||
@ -105,4 +105,11 @@ final class Database {
|
||||
}
|
||||
return tables.performAction(player: player, action: action)
|
||||
}
|
||||
|
||||
func play(card: Card, playerToken: SessionToken) -> PlayCardResult {
|
||||
guard let player = players.registeredPlayerExists(withSessionToken: playerToken) else {
|
||||
return .invalidToken
|
||||
}
|
||||
return tables.play(card: card, player: player)
|
||||
}
|
||||
}
|
||||
|
@ -90,12 +90,12 @@ final class TableManagement: DiskWriter {
|
||||
- Parameter isPublic: Indicates that this is a game joinable by everyone
|
||||
- Returns: The table id
|
||||
*/
|
||||
func createTable(named name: TableName, player: PlayerName, isPublic: Bool) -> TableId {
|
||||
func createTable(named name: TableName, player: PlayerName, isPublic: Bool) -> TableInfo {
|
||||
let table = Table(newTable: name, isPublic: isPublic)
|
||||
_ = table.add(player: name)
|
||||
_ = table.add(player: player)
|
||||
tables[table.id] = table
|
||||
writeTableToDisk(table: table)
|
||||
return table.id
|
||||
return table.compileInfo(for: player)!
|
||||
}
|
||||
|
||||
/// A list of all public tables
|
||||
@ -171,4 +171,11 @@ final class TableManagement: DiskWriter {
|
||||
}
|
||||
return table.perform(action: action, forPlayer: player)
|
||||
}
|
||||
|
||||
func play(card: Card, player: PlayerName) -> PlayCardResult {
|
||||
guard let table = currentTable(for: player) else {
|
||||
return .noTableJoined
|
||||
}
|
||||
return table.play(card: card, player: player)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user