git ssb

4+

Dominic / nomic



Commit bc05386ef4a5abeb622a5c1b6361cf5719d9865c

add helper to print current turn

mix irving committed on 8/13/2017, 3:24:37 AM
Parent: 4d3dec1ae29aecc29509c5669ac22916d9256368

Files changed

printTurn.jsadded
printTurn.jsView
@@ -1,0 +1,32 @@
1 +const { players, currentTurn } = require('./state')
2 +
3 +printTurn()
4 +
5 +function printTurn () {
6 + const orderedPlayers = alphabetize(players)
7 + const currentPlayer = getCurrentTurnPlayer(orderedPlayers, currentTurn)
8 +
9 + orderedPlayers
10 + .forEach((p, index) => {
11 +
12 + const symbol = p.key === currentPlayer.key
13 + ? '> '
14 + : ' '
15 + process.stdout.write(`${symbol} ${p.name}\n`)
16 + })
17 +}
18 +
19 +function alphabetize (players) {
20 + return Object.keys(players)
21 + .map(k => Object.assign({}, players[k], { key: k }))
22 + .sort((a, b) => a.surname > b.surname ? 1 : -1)
23 +}
24 +
25 +function getCurrentTurnPlayer (orderedPlayers, currentTurn) {
26 + return orderedPlayers[(currentTurn - 1) % orderedPlayers.length]
27 +
28 + // This is going to break real bad when:
29 + // - people join the game
30 + // - people are 'inactive' in some capacity
31 +}
32 +

Built with git-ssb-web