Challenge: PigLatin Game Domain Layer
Implement a PigLatin game in Java to translate words and allow players to guess. Adhere to proper Java conventions and conduct comprehensive testing using Mockito.
We'll cover the following
Task and requirements
You’re tasked with implementing the domain layer of a PigLatin game in Java. The game involves translating words into PigLatin and allowing players to guess the translated words. Your implementation should include several classes to manage the game flow, translate words, and handle player guesses.
Your implementation should follow these rules:
Implement the
PigLatinGame
class, which manages the game flow, including starting a new game and assessing player guesses.Implement the
Game
class, which represents the state of a single game session, including the target word, player attempts, and game-over condition.Implement the
WordSelection
class, which is responsible for selecting a random word from a repository for each game session.Implement the
PigLatin
class, which translates words into PigLatin.Implement the
GuessResult
class, which represents the result of a player’s guess.Write comprehensive unit tests to validate the correctness of the
PigLatinGame
,Game
,WordSelection
, andPigLatin
classes.
Note: Use your implementation for the “Challenge: PigLatin” lesson from earlier in this course as a starting point.
Follow the TDD cycle by writing test cases first and then implementing the function. Write multiple test cases to cover different scenarios, including correct and incorrect guesses, game over conditions, and edge cases.
Rules
Here are the constraints to consider when solving the challenge.
The
Game
class should encapsulate the state of a single game session and provide methods for updating the game state based on player guesses.The
GuessResult
class should handle the following:Whether the word was correctly guessed
Whether the game is over
If there was an error
The
WordSelection
class must select a random word from a repository for each game session. Ensure that it properly handles edge cases, such as an empty repository or invalid word numbers.
Now, you can follow the TDD process by starting with simple test cases and incrementally building your PigLatin game domain layer to meet these requirements.
Try it yourself
Add or modify the code in the widget below to implement your solution.
Get hands-on with 1400+ tech skills courses.