parent
a19dd163ad
commit
44620c2a3f
12 changed files with 231 additions and 107 deletions
@ -1,13 +1,7 @@ |
|||||||
export const SCOREBAR_ACTION = 'SCOREBAR_ACTION'; |
export const SCOREBAR_ACTION = 'SCOREBAR_ACTION'; |
||||||
export const MUNCH_SUCCEEDED = 'SCOREBAR_MUNCH_SUCCEEDED'; |
export const UPDATE = 'SCOREBAR_UPDATE'; |
||||||
export const MUNCH_FAILED = 'SCOREBAR_MUNCH_FAILED'; |
|
||||||
|
|
||||||
export const munchSucceeded = () => ({ |
export const update = () => ({ |
||||||
type: SCOREBAR_ACTION, |
type: SCOREBAR_ACTION, |
||||||
action: MUNCH_SUCCEEDED, |
action: UPDATE |
||||||
}); |
|
||||||
|
|
||||||
export const munchFailed = () => ({ |
|
||||||
type: SCOREBAR_ACTION, |
|
||||||
action: MUNCH_FAILED |
|
||||||
}); |
}); |
||||||
|
@ -0,0 +1,43 @@ |
|||||||
|
import * as ScorebarActions from '../actions/board/scorebar.actions'; |
||||||
|
import { SETTINGS } from '../App'; |
||||||
|
|
||||||
|
let dispatch; |
||||||
|
let lives = 3; |
||||||
|
let currentScore = 0; |
||||||
|
let highScore = 7; |
||||||
|
|
||||||
|
const ScorebarCtrl = { |
||||||
|
setDispatch: d => dispatch = d, |
||||||
|
|
||||||
|
getCurrentScore: () => currentScore, |
||||||
|
getHighScore: () => highScore, |
||||||
|
getLives: () => lives, |
||||||
|
|
||||||
|
munchSucceeded: () => { |
||||||
|
currentScore += 10; |
||||||
|
dispatch(ScorebarActions.update()); |
||||||
|
}, |
||||||
|
|
||||||
|
munchFailed: () => { |
||||||
|
lives--; |
||||||
|
currentScore -= 5; |
||||||
|
dispatch(ScorebarActions.update()); |
||||||
|
}, |
||||||
|
|
||||||
|
eatenByTroggle: () => { |
||||||
|
lives--; |
||||||
|
dispatch(ScorebarActions.update()); |
||||||
|
}, |
||||||
|
|
||||||
|
levelUp: (level) => { |
||||||
|
currentScore += 25; |
||||||
|
dispatch(ScorebarActions.update()); |
||||||
|
}, |
||||||
|
|
||||||
|
reset: () => { |
||||||
|
lives = SETTINGS.LIVES; |
||||||
|
currentScore = 0; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
export default ScorebarCtrl; |
@ -1,24 +1,24 @@ |
|||||||
const Immutable = require('immutable'); |
const Immutable = require('immutable'); |
||||||
|
|
||||||
import * as ScorebarActions from '../../actions/board/scorebar.actions'; |
import * as ScorebarActions from '../../actions/board/scorebar.actions'; |
||||||
import { SETTINGS } from '../../App'; |
import ScorebarCtrl from '../../controllers/scorebar.controller.js'; |
||||||
|
|
||||||
const initial = { current: 0, high: 999, lives: SETTINGS.LIVES }; |
const initial = { |
||||||
|
current: ScorebarCtrl.getCurrentScore(), |
||||||
|
high: ScorebarCtrl.getHighScore(), |
||||||
|
lives: ScorebarCtrl.getLives() |
||||||
|
}; |
||||||
|
|
||||||
const reducer = (state = initial, action) => { |
const reducer = (state = initial, action) => { |
||||||
if (action.type !== ScorebarActions.SCOREBAR_ACTION) { |
if (action.type !== ScorebarActions.SCOREBAR_ACTION) { |
||||||
return state; |
return state; |
||||||
} |
} |
||||||
|
|
||||||
switch (action.action) { |
return Immutable.Map(state) |
||||||
case ScorebarActions.MUNCH_SUCCEEDED: |
.set('current', ScorebarCtrl.getCurrentScore()) |
||||||
return Immutable.Map(state).set('current', state.current + 10).toObject(); |
.set('high', ScorebarCtrl.getHighScore()) |
||||||
|
.set('lives', ScorebarCtrl.getLives()) |
||||||
case ScorebarActions.MUNCH_FAILED: |
.toObject(); |
||||||
return Immutable.Map(state).set('lives', state.lives - 1).toObject(); |
|
||||||
} |
|
||||||
|
|
||||||
return state; |
|
||||||
}; |
}; |
||||||
|
|
||||||
export default reducer; |
export default reducer; |
||||||
|
Loading…
Reference in new issue