-
Notifications
You must be signed in to change notification settings - Fork 130
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
User/nareshh74/refactor 1 #49
Open
kumarnareshh74
wants to merge
18
commits into
martinsson:master
Choose a base branch
from
nareshh74:user/nareshh74/refactor_1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
User/nareshh74/refactor 1 #49
kumarnareshh74
wants to merge
18
commits into
martinsson:master
from
nareshh74:user/nareshh74/refactor_1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added a new validation check to ensure the number of players does not exceed 6. If the number of players is greater than 6, an ArgumentException is thrown with the message "You need at most 6 players to play the game". This complements the existing check for a minimum of 2 players, ensuring the game is played with 2 to 6 players.
Refactored the Game class in Game.cs to utilize a new Player class in Player.cs, encapsulating player data and behavior. Updated Game methods to operate on Player objects instead of separate lists. Removed DidPlayerWin from Game, now handled by Player. Updated TriviaTests.cs for better test reporting.
Changed visibility of several fields and methods in the `Game` class within the `Trivia` namespace from public or default to private. This includes fields like `popQuestions`, `scienceQuestions`, `sportsQuestions`, `rockQuestions`, `currentPlayer`, and `isGettingOutOfPenaltyBox`, as well as methods `CreateRockQuestion` and `Add`.
Refactored the handling of the penalty box state from the `Game` class to the `Player` class, encapsulating the logic within the `Player` class for better code organization and readability. - Removed `isGettingOutOfPenaltyBox` from `Game` class. - Added `_isGettingOutOfPenaltyBox` field to `Player` class. - Introduced `MightGetOutOfPenaltyBox`, `CantGetOutOfPenaltyBox`, and `CanGetOutOfPenaltyBox` methods in `Player` class. - Updated `Game` class to use new `Player` methods for penalty box state. - Modified `AskQuestion` in `Game` class to use `this.CurrentCategory()`. - Enhanced object-oriented design by delegating state management to `Player` class.
Refactored the logic for advancing to the next player by introducing a new method `GiveTurnToNextPlayer()`. This method increments the `currentPlayer` index and wraps it around if it exceeds the number of players. The method replaces repeated code blocks, making the code cleaner and reducing redundancy.
… pretty stable so encapsulated it - kept it static for now Refactored the `Game` class to delegate question preparation and asking to a new static `Questions` class in `Questions.cs`. The `Questions` class now handles the creation and management of different categories of questions (`popQuestions`, `scienceQuestions`, `sportsQuestions`, and `rockQuestions`). Introduced `PrepareQuestions` method to initialize questions and `Ask` method to handle question logic. Removed `CreateRockQuestion` method and individual question lists from `Game` class.
Refactored the Game constructor to call a private initializer. Updated Roll method to handle penalty box logic more clearly: - Players stay in the penalty box on even rolls. - Players exit the penalty box on odd rolls. - Removed redundant else block and streamlined logic. Modified AskQuestion to use Questions.Ask directly and print category.
Refactored the `WasCorrectlyAnswered` method in `Game.cs` to simplify the logic for handling players in the penalty box by removing nested `if` statements. Renamed `DidPlayerWin` method in `Player.cs` to `YetToWin` to better reflect its purpose. Corrected a typo in the console output message from "Answer was corrent!!!!" to "Answer was correct!!!!". Updated test approval files to reflect these changes.
Added a call to TakeOutOfPenaltyBox() for the current player when the answer is correct. This ensures the player is taken out of the penalty box before updating the purse and printing the success message.
Removed the `Name` property and the `Player` constructor in `Player.cs`. Overrode the `ToString` method to return the player's name. Updated `Game.cs` to use the overridden `ToString` method instead of accessing the `Name` property directly.
Renamed `currentPlayer` to `_currentPlayerIndex` in the `Game` class for consistency. Updated all references and logic in methods like `Roll`, `WasCorrectlyAnswered`, `GiveTurnToNextPlayer`, and `WrongAnswer` to use the new variable name. Ensured consistent usage of `_currentPlayerIndex` for tracking the current player's index.
Refactored the `Roll`, `WasCorrectlyAnswered`, and `WrongAnswer` methods in `Game.cs` to introduce a local variable `currentPlayer`. This change reduces repetitive code and improves readability by replacing multiple direct accesses to `this._players[_currentPlayerIndex]` with the `currentPlayer` variable.
- Updated `Game` class to use `QuestionsDeck` for managing questions. - Added `QuestionList` class to manage questions for specific categories. - Refactored `Questions` class into `QuestionsDeck` with a `Dictionary` for category mapping. - Implemented singleton pattern in `QuestionsDeck` and replaced `Ask` method with `AskNextQuestionFromCategory`.
Changed method call in Game.cs to use AskQuestionForPlayer. In Questions.cs: - Made _categoryToquestionListMap readonly. - Added readonly list _categoryList for categories. - Renamed PrepareQuestionsPercategory to PrepareQuestionsForcategory. - Updated PrepareQuestionsForcategory to add categories to _categoryList. - Renamed AskNextQuestionFromCategory to AskQuestionForPlayer. - Added GetQuestionCategoryForPlayer to determine category by player position.
Removed the private constructor `Game()` and updated the public constructor `Game(List<string> players)` to directly initialize `_questionsDeck` within its body. This change simplifies the constructor logic by eliminating the need for constructor chaining and making the code more straightforward.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.