Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuweiyou committed Feb 19, 2018
1 parent 59aa28d commit 7abe433
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
5 changes: 2 additions & 3 deletions 我最在行/src/common/game.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const Https = require('./https')
const timeout = require('./timeout')

async function game (...args) {
async function game ({player, master = false, match = false, theme = 0} = {}) {
try {
const [player, {master = false, match = false, theme = 0} = {}] = args
const https = new Https(player)
// 获取用户信息
const accountsSelf = await https.accountsSelf()
Expand Down Expand Up @@ -38,7 +37,7 @@ async function game (...args) {
console.error(e)
console.log('三秒后自动重试')
await timeout(3000)
return game(...args)
return game({player, master, match, theme})
}
}

Expand Down
4 changes: 1 addition & 3 deletions 我最在行/src/match/event-battle-score.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ const eventbus = require('./eventbus')
module.exports = (socket, data) => {
// 出了分数,结束一局
console.log('单局匹配结束')

// 因为模块之间不能循环引用,所以通过事件通知开局
eventbus.emit('start')
eventbus.emit('over')
}
16 changes: 5 additions & 11 deletions 我最在行/src/match/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const MatchSocket = require('./match-socket')
const game = require('../common/game')
const MatchSocket = require('./match-socket')
const eventbus = require('./eventbus')
const events = {
event_battle_score: require('./event-battle-score'),
Expand All @@ -8,15 +8,9 @@ const events = {
event_round_result: require('./event-round-result')
}

module.exports = player => {
async function start () {
// eslint-disable-next-line no-new
new MatchSocket({
options: await game(player, {match: true}),
events
})
}

eventbus.on('start', start)
module.exports = async player => {
const options = await game({player, match: true})
const start = () => new MatchSocket({options, events})
eventbus.on('over', start)
start()
}
4 changes: 2 additions & 2 deletions 我最在行/src/pk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const events = {

module.exports = async players => {
const rooms = await Promise.all([
game(players[0], {master: true}),
game(players[1])
game({player: players[0], master: true}),
game({player: players[1]})
])
rooms.map(room => new PkSocket({
options: {
Expand Down

0 comments on commit 7abe433

Please sign in to comment.