Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Player has won!" message changes if player leaves game #51

Open
equationcrunchor opened this issue Aug 2, 2020 · 2 comments
Open

"Player has won!" message changes if player leaves game #51

equationcrunchor opened this issue Aug 2, 2020 · 2 comments

Comments

@equationcrunchor
Copy link

It appears that after the game ends, the game remembers the position of the player that won (e.g. the fourth player). However, if a player leaves, changing the order of players, the name in the banner message will change to the player who is now in that position, regardless of who actually won.

@octachrome
Copy link
Owner

Thanks for the bug report. Not sure when I'll get around to fixing this, I don't know how simple it will be.

@k-hendricks
Copy link

I noticed the same issue today. Looking through your code (which is incredibly clear and well-documented btw), I think one could just add an if statement on line 208 of game.js that checks if the winnerid is set when a player is leaving in the state WAITING_FOR_PLAYERS.

if (state.state.winnerIdx != null) {
  if (state.state.winnerIdx == playerIdx) {
    setState({
                  name: stateNames.WAITING_FOR_PLAYERS,
                  winnerIdx: null,
                  playerIdx: null
              });
   }
   else if (state.state.winnerIdx > playerIdx) {
      setState({
                      name: stateNames.WAITING_FOR_PLAYERS,
                      winnerIdx: state.state.winnerIdx - 1,
                      playerIdx: null
                  });
   }
}

So if the player who is leaving is the winner, the winner gets set to null (but their win will still be recorded in the game history), or if the leaving player's index is lower than the winner, the winner index is decremented.

I understand if you'd rather add a new state that differentiates between WAITING_FOR_PLAYERS and WAITING_TO_PLAY_AGAIN which would obviously be a larger change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants