Last active
February 12, 2020 08:59
-
-
Save conanak99/642ea3cc5dca54e591d7849ee5d48f6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
finishGame({ commit, state }) { | |
commit('removeLosers'); | |
// Đếm những quân xí ngầu thắng | |
var diceDic = countBy(state.dices, dice => dice); | |
for (const key in diceDic) { | |
const multiplier = diceDic[key] + 1; | |
const winners = Object.values(state.board[key]); | |
// Cộng điềm cho những người thắng | |
for (const winner of winners) { | |
commit('updatePlayerPoint', { playerId: winner.id, changedValue: (winner.bet * multiplier) }); | |
} | |
} | |
commit('changeStatus', FINISHED); | |
// Upload danh sách người chơi lên Firebase đến tra điểm | |
const syncPlayer = Object.values(state.players) | |
.filter(p => p.id && p.name && p.avatar) | |
.sort((p1, p2) => p2.point - p1.point); | |
firebase.set(syncPlayer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment