Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
fix #6 修复关卡切换时,AI 玩家的 controller-saga 无法找到 AI 玩家的 BUG
Browse files Browse the repository at this point in the history
修复 DEV.TEST_STAGE 没有效果的问题
  • Loading branch information
feichao93 committed Apr 12, 2018
1 parent 24d3d30 commit 688d707
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions app/sagas/AIPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cancelled, fork, put, race, select, take, takeEvery } from 'redux-saga/effects'
import { cancel, fork, put, race, select, take, takeEvery } from 'redux-saga/effects'
import AITankCtx from '../ai/AITankCtx'
import AIWorkerSaga from '../ai/AIWorkerSaga'
import { State } from '../reducers'
Expand All @@ -11,11 +11,6 @@ import fireController from './fireController'
export default function* AIPlayer(playerName: string, tankId: TankId) {
const ctx = new AITankCtx(playerName)
try {
yield takeEvery(hitPredicate, hitHandler)
yield fork(directionController, playerName, ctx.directionControllerCallback)
yield fork(fireController, playerName, ctx.fireControllerCallback)
yield fork(generateBulletCompleteNote)

yield put<Action>({
type: 'ADD_PLAYER',
player: new PlayerRecord({
Expand All @@ -24,6 +19,12 @@ export default function* AIPlayer(playerName: string, tankId: TankId) {
side: 'ai',
}),
})

yield takeEvery(hitPredicate, hitHandler)
yield fork(directionController, playerName, ctx.directionControllerCallback)
yield fork(fireController, playerName, ctx.fireControllerCallback)
yield fork(generateBulletCompleteNote)

yield put<Action>({ type: 'ACTIVATE_PLAYER', playerName, tankId })

// prettier-ignore
Expand All @@ -32,15 +33,15 @@ export default function* AIPlayer(playerName: string, tankId: TankId) {
take('END_GAME'),
AIWorkerSaga(ctx),
])
yield put<Action>({ type: 'REQ_ADD_AI_PLAYER' })
yield cancel() // cancel 自身来取消前面 fork 的各个 saga
// TODO 应该还有更好的方法来处理这里的逻辑
} finally {
const tank: TankRecord = yield select(selectors.playerTank, playerName)
if (tank != null) {
yield put<Action>({ type: 'REMOVE_TANK', tankId: tank.tankId })
}
// 我们在这里不移除 AI 玩家,因为 AI 玩家的子弹可能还处于活跃状态
if (!(yield cancelled())) {
yield put<Action>({ type: 'REQ_ADD_AI_PLAYER' })
}
}

/* ----------- below are function definitions ----------- */
Expand Down
8 changes: 4 additions & 4 deletions app/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ let defaultStages = filenames
.sortBy(s => Number(s.name))

if (DEV.TEST_STAGE) {
defaultStages = defaultStages.push(
defaultStages = defaultStages.unshift(
StageConfig.fromJS({
name: '1',
custom: true,
name: 'test',
custom: false,
difficulty: 1,
map: [
'X X X X X X X X X X X X X ',
Expand All @@ -31,7 +31,7 @@ if (DEV.TEST_STAGE) {
'X X X X X Xf Tf Tf X X X X X ',
'X X X X X X E Tf X X X X X ',
],
enemies: ['5*basic'],
enemies: ['1*basic'],
}),
)
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

该 GitHub 仓库的版本是经典坦克大战的复刻版本,基于原版素材,使用 React 将各类素材封装为对应的组件。素材使用 SVG 进行渲染以展现游戏的像素风,可以先调整浏览器缩放再进行游戏,1080P 屏幕下使用 200% 缩放为最佳。此游戏使用网页前端技术进行开发,主要使用 React 进行页面展现,使用 Immutable.js 作为数据结构工具库,使用 redux 管理游戏状态,以及使用 redux-saga 处理复杂的游戏逻辑。

目前游戏仍在开发中,只支持单人游戏,AI 设置不太合理。如果游戏过程中发现任何 BUG 的话,请给我提 [issue](https://github.com/shinima/battle-city/issues/new)
目前游戏仍在开发中,只支持单人游戏,AI 设置不太合理。如果游戏过程中发现任何 BUG 的话,欢迎提 [issue](https://github.com/shinima/battle-city/issues/new)(\*^_^\*)

### 开发进度:

Expand Down

0 comments on commit 688d707

Please sign in to comment.