Engage in a classic number guessing game from the command line. With options for different difficulty levels and smart hints to guide your guessing, players can enjoy challenges suited to their skills. Comprehensive test coverage ensures a reliable gaming experience, making it perfect for both beginners and seasoned players.
A classic Number Guessing Game designed for command-line interaction, which offers a fun and engaging experience with multiple difficulty levels. This game challenges players to guess a randomly generated number between 1 and 100 while providing a robust feedback system to enhance gameplay.
Key Features
- Multiple Difficulty Levels: Users can select from three levels of difficulty:
- Easy: 10 chances for beginners.
- Medium: 5 chances for a balanced challenge.
- Hard: 3 chances for seasoned players seeking a tougher test.
- Smart Feedback System: Players receive hints when their guesses are too high or too low, aiding them in finding the correct number.
- Input Validation: The game includes robust error handling to ensure that inputs are valid and manage user expectations effectively.
- Performance Tracking: Players can track their guess attempts as well as the time taken to win the game, enriching their gaming experience.
- Replay Option: After finishing a game, players can easily restart without needing to reload the application, facilitating continuous play.
- Comprehensive Testing: The project features a complete set of unit tests with 100% code coverage using pytest, ensuring reliability and quality.
Gameplay Flow
- Launch the Number Guessing Game by running
python main.py. - Select a preferred difficulty level.
- Start making guesses within the defined range of 1 to 100.
- Utilize the hints provided to narrow down the guesses.
- Aim to guess the number correctly before running out of chances.
Game Mechanics
- The game randomly generates a number between 1 and 100 based on the selected difficulty.
- Players are encouraged to guess by entering numbers, while helpful feedback is given to facilitate their guessing strategy.
- Winning is achieved by guessing the number correctly, while losing may occur if all chances are exhausted.
- Players can view their game statistics for a summary of their performance.
Game Structure
The game comprises several key functions:
get_number(): Responsible for generating the random number.get_difficulty(): Prompts the user to choose a difficulty level for gameplay.start_game(): Manages the game loop and logic, facilitating player interactions.main(): Acts as the entry point for the application, incorporating replay functionality.
Testing Framework
The project implements comprehensive unit tests to validate all aspects of the game, including:
- Difficulty level selection and validation
- Random number generation accuracy
- Handling of correct and incorrect guesses
- Management of invalid inputs and feedback message checks
Technical Specifications
- Language: Python 3.10+
- Testing Framework: pytest
- Standard Libraries Used:
random,time - Fully Typed Code: Type hints are used throughout the codebase for enhanced maintainability.
This Number Guessing Game is an engaging way to improve logic and deduction skills, suitable for players of all ages. With its easy-to-use interface and clear mechanics, it's an excellent choice for a quick gaming session.
No comments yet.
Sign in to be the first to comment.