codegard1/blackjack

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 to AppActions.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

  1. Human player enters his/her name at the landing screen (i.e. NewPlayer form - not yet created)
  2. onClick action for the NewPlayer form's Okay button calls AppActions.newPlayer and adds two new objects to the _playersList in GameStore: one for the human player, and one for the 'Dealer'
  3. Once this is done, _newGame is immediately invoked, which sets up the default 'state' for the Game (e.g. minimumBet, turnCount, etc.)
  4. 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
  5. Rename _newGame to _resetGame
  6. Call _resetGame for the Reset Game button in OptionsPanel

Interim until NewPlayer form exists

  1. 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