git ssb

4+

Dominic / nomic



Tree: bc05386ef4a5abeb622a5c1b6361cf5719d9865c

Files: bc05386ef4a5abeb622a5c1b6361cf5719d9865c / printTurn.js

824 bytesRaw
1const { players, currentTurn } = require('./state')
2
3printTurn()
4
5function 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
19function 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
25function 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
33

Built with git-ssb-web