Implement NewPlayer to test Flux
Closed this issue · 3 comments
Implement _newPlayer
in GameStore as a second test that Flux is working properly
- add constant
GAME_NEWPLAYER
in AppConstants - implement
newPlayer
handler in AppActions - implement
_newPlayer
in GameStore - add method
_onNewPlayer
in Table to pass params toAppActions.newPlayer()
- bind
_onNewPlayer
to Table
At this point I am realizing that I need to think a little harder about the flow of actions in my code.
For example: in Table, _newGame
calls _newPlayer
once for each item in an array called players
that is defined locally. This was done to make _newGame
more legible and because starting a new game and adding a new player to the game are idiomatically different tasks for the "game engine". So it makes sense to separate them.
In the context of flux, this difference is especially clear, since the unidirectional data flow means I must decide whether to keep the two methods dependent on one another or figure out a more functional approach.
New 'Game Plan' for newGame
- Human player enters his/her name at the landing screen (i.e. NewPlayer form - not yet created)
onClick
action for the NewPlayer form's Okay button callsAppActions.newPlayer
and adds two new objects to the _playersList in GameStore: one for the human player, and one for the 'Dealer'- Once this is done,
_newGame
is immediately invoked, which sets up the default 'state' for the Game (e.g. minimumBet, turnCount, etc.) - In this scenario,
_newGame
is identical to_resetgame
in Table since all it does is set the default values for the state, independent of the players - Rename
_newGame
to_resetGame
- Call
_resetGame
for the Reset Game button in OptionsPanel
Interim until NewPlayer form exists
- Do call
_newPlayer
from within_newGame
in GameStore, once for each name passed to_newGame
marking as invalid because this is not the right way to implement flux