-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
game-api.ts
50 lines (41 loc) · 1.3 KB
/
game-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// The Game API facade
import Reports from './reports'
import Wallets from './wallets'
import Users from './users'
import GameEngine, { GameState } from './game-engine'
export default class GameAPI {
#wallets: Wallets
#reports: Reports
#users: Users
#gameEngine: GameEngine
constructor() {
this.#wallets = new Wallets()
this.#reports = new Reports()
this.#users = new Users()
this.#gameEngine = new GameEngine()
}
getBalance(userId: string): number {
// Get a players balance
return this.#wallets.getBalance(userId)
}
gameState(): GameState {
// Get the current game state
return this.#gameEngine.getGameState()
}
getHistory(): { [id: string]: [number, string] } {
// get the game history
return this.#reports.getHistory()
}
changePwd(userId: string, password: string): boolean {
// change users password
return this.#users.changePwd(userId, password)
}
submitEntry(userId: string, entry: number): boolean {
// submit a bet
return this.#gameEngine.submitEntry(userId, entry)
}
registerUser(value: { [id: string]: string }): string {
// register a new user and returns the new id
return this.#users.registerUser(value)
}
}