Centralize input handling through UserInterface for future pygame UI support #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using the game, users had to switch between the console and UI to provide input in certain situations (bank deposits/withdrawals, tavern betting, stats viewing). This created a poor user experience and prevented the future implementation of a pygame-based UI, as direct
input()calls were scattered throughout the location code.Solution
This PR centralizes all user input handling through the
UserInterfaceclass by:getInput()method to theUserInterfaceclass that handles all text/numeric input consistentlyinput()calls in location code with calls touserInterface.getInput()Changes
Core Changes
src/ui/userInterface.py: AddedgetInput(prompt)method to centralize input handlingsrc/location/bank.py: Updateddeposit()andwithdraw()to useuserInterface.getInput()src/location/tavern.py: UpdatedchangeBet()to useuserInterface.getInput()src/location/home.py: UpdateddisplayStats()to useuserInterface.getInput()Test Updates
getInput()methodBenefits
✅ No more context switching - All input now flows through a single interface
✅ Future-ready - Pygame UI can be implemented by simply overriding
UserInterfacemethods✅ Cleaner code - Reduced duplication and improved separation of concerns
✅ Fully tested - Comprehensive test coverage with no regressions
Example
Before:
After:
This architectural improvement makes it straightforward to swap in alternative UI implementations (pygame, web UI, etc.) in the future without modifying any location-specific code.
Fixes #[issue_number]
Original prompt
Fixes #42
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.