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

Ludo Game Die can be rolled even after it is a player's turn to move #4263

Open
botwhytho opened this issue Jan 5, 2025 · 4 comments
Open

Comments

@botwhytho
Copy link

In the video below, one can see two instances where the game label says 'Player A to move' but one can continue rolling the dice. The game state actually respects the first die roll and when the player moves the piece it uses that but it is confusing to be able to continue rolling the dice. BlDoubleClickEvent event handler should be temporarily removed while a player makes a move and added back right after.

LudoDieBug2.mp4
@botwhytho
Copy link
Author

PR Created feenkcom/gtoolkit-demos#16

@onierstrasz
Copy link
Contributor

Haha! Thanks. I'll have a look ...

@onierstrasz
Copy link
Contributor

In the proposed solution, there is a lot of logic added to GtLudoGameElement>>#initializeFor:. A cleaner solution would be to have the GtLudoDieElement hold a reference to the game instead of the die (or instead of just the die), and then ask the game to roll the die. The game will then know if the die can be rolled. This would also require the initialization of the DieELement to be changed in GtLudoBoardElement>>#addDieElement. In this way we would keep game logic out of the UI elements.

@onierstrasz
Copy link
Contributor

onierstrasz commented Jan 9, 2025

Summary of new changes:

  • Add GtLudoGame>>#rollDie to roll the die only if self playerToRoll
  • Add GtLudoGame>>#rollDie: for testing purposes to take an explicit die value
  • Add GtLudoGameExamples>>#playerArollsTwice to test this scenario:
example := GtLudoGameExamples new.
game := example playerAentersTokenA.
game rollDie: 4.
example assert: game die topFace equals: 4.
game rollDie: 5.
example assert: game die topFace equals: 4.
game
  • Refactor GtLudoDieElement to evaluate a stored doubleClickAction which is initialized to [ self die roll ]
  • Update GtLudoBoardElement>>#addDieElement to changed the doubleClickAction to [ self game rollDie ], which performs the necessary check.

onierstrasz added a commit to feenkcom/gtoolkit-demos that referenced this issue Jan 9, 2025
syrel pushed a commit that referenced this issue Jan 9, 2025
Metacello new
    baseline: 'GToolkitForPharo9';
    repository: 'github://feenkcom/gtoolkit:v1.0.1441/src';
    load

All commits (including upstream repositories) since last build:
feenkcom/gtoolkit-demos@a95e96 by Oscar Nierstrasz
Signing test


feenkcom/gtoolkit-demos@04bc88 by Oscar Nierstrasz
[#4263] Fixed double clicking die of game in progress. 


feenkcom/iceberg-git-cli@b4cc04 by Sven Van Caekenberghe
Added PureGitPackage>>#applyIncomingChanges


feenkcom/gt4git@df9e3e by Sven Van Caekenberghe
Added apply action to PureGitPackage>>#gtViewIncomingChangesFor:
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

2 participants