-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathclient.ts
More file actions
47 lines (32 loc) · 1.02 KB
/
Copy pathclient.ts
File metadata and controls
47 lines (32 loc) · 1.02 KB
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
// The Facade Example Use Case
import GameAPI from './game-api'
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
async function facadeExample() {
const gameAPI = new GameAPI()
const user = { user_name: 'sean' }
const userId = gameAPI.registerUser(user)
await sleep(500)
gameAPI.submitEntry(userId, 5)
await sleep(500)
console.log()
console.log('---- GameState Snapshot ----')
console.log(gameAPI.gameState())
await sleep(1000)
const HISTORY = gameAPI.getHistory()
console.log()
console.log('---- Reports History ----')
Object.keys(HISTORY).forEach((key) => {
console.log(`${key} : ${HISTORY[key][0]} : ${HISTORY[key][1]}`)
})
await sleep(1000)
console.log()
console.log('---- User Balance ----')
console.log(user.user_name + ' : ' + gameAPI.getBalance(userId))
await sleep(1000)
console.log()
console.log('---- GameState Snapshot ----')
console.log(gameAPI.gameState())
}
facadeExample()