Package: pygamebox
PyGameBoxTeam MembersAavishkar GautamAvaneesh DevkotaSoyuj Jung BasnetDescriptionPyGameBox is a versatile Python package that simplifies the development of several popular text-based games.
It abstracts away the intricate details of game logic, allowing you to effortlessly import and integrate the following
games into your own projects:Guess the NumberRock, Paper, ScissorsWord ScrambleHangmanWordleGetting StartedPrerequisitesBefore you start, make sure you have Python 3.7 or higher installed on your system. You can download Python from
theofficial website.InstallationYou can install the package via pip:pipinstallpygameboxCheck outpygameboxpackage on PYPI:https://pypi.org/project/pygamebox.UsageAfter installing the package, import PyGameBox to your program.frompygameboximport*PyGameBox consists of the game classes:GuessTheNumber,RockPaperScissors,WordScramble,Hangman, andWordle.Note: If you want to implement any one of these games, you can simply import it, instantiate a game object, and
callplay()on the game object. PyGameBox will handle all the game logic.However, if you wish to handle the game logic yourself,
PyGameBox also provides you with a host of helper functions designed to make the implementation as simple as use.Example use caseCheck outexamples/play.pyto see how to run the games using thepygameboxpackage.You can run the demo using:pythonexamples/play.pyGuess The NumberfrompygameboximportGuessTheNumbergame=GuessTheNumber()game.play()ScreenshotClass AttributesDEFAULT_START(int): The default start of the range for the number to guess (inclusive), which is1.DEFAULT_END(int): The default end of the range for the number to guess (inclusive), which is100.Methods__init__(self, start: int = DEFAULT_START, end: int = DEFAULT_END) -> NoneDescription: Creates an instance the game with a specified start and end range.Parameters:start(int, optional): The start of the range for the number to be guessed. Defaults toDEFAULT_START.end(int, optional): The end of the range for the number to be guessed. Defaults toDEFAULT_END.reset(self) -> NoneDescription: Resets the game by generating a new random number and setting the number of guesses to0.get_user_guess(self) -> strDescription: Gets the user's guess as a string.Returns: The user's guess as a string.validate_input(self, guess: Union[str, int]) -> boolDescription: Validates the user's guess.Parameters:guess(Union[str, int]): The user's guess.Returns:Trueif the guess is valid;Falseotherwise.guess(self, user_guess: int) -> intDescription: Checks if the user's guess is correct.Parameters:user_guess(int): The user's guess.Returns:-1if the guess is too low.1if the guess is too high.0if the guess is correct.turn(self, user_guess: Union[str, int]) -> boolDescription: Runs a turn of the game.Parameters:user_guess (Union[str, int]): The user's guess.Returns:Trueif the user guessed the number,Falseotherwise.play(self) -> NoneDescription: Plays the game. Takes guesses from the user and checks until the user guesses the correct number.Rock, Paper, ScissorsfrompygameboximportRockPaperScissorsgame=RockPaperScissors()game.play()ScreenshotClass AttributesDEFAULT_ROUNDS(int): The default number of rounds to play, which is1.Methods__init__(self) -> NoneDescription: Creates an instance of the rock, paper, scissors game.get_user_throw(self) -> intDescription: Prompts the user to choose a move (Rock, Paper, or Scissors).Returns: Anint(0: Rock,1: Paper,2: Scissors).validate_input(self, user_input: Union[str, int])-> bool`Description: Checks if the user's input is valid.Parameters:user_input(Union[str, int]): The user's input.Returns:Trueif the input is valid (1, 2, or 3).Falseotherwise.throw() -> intDescription: Generates a random choice for the computer (Rock, Paper, or Scissors).Returns: The computer's choice as anint(0: Rock,1: Paper,2: Scissors).round(user_throw: int, computer_throw: int) -> intDescription: Determines the result of a round based on the user's and computer's choices.Parameters:user_throw(int): The user's choice.computer_throw(int): The computer's choice.Returns:1if the user wins.-1if the computer wins.0if it's a draw.validate_round_input(rounds: int) -> boolDescription: Validates the user's input to ensure it's a valid number of rounds (1 or greater).Parameters:rounds(int): The number of rounds to play.Returns:Trueif the input is valid,Falseotherwise.play(self, rounds: int = DEFAULT_ROUNDS) -> NoneDescription: Runs the Rock, Paper, Scissors game for a specified number of rounds.Parameters:rounds(int, optional): The number of rounds to play (defaults toDEFAULT_ROUNDS).Word ScramblefrompygameboximportWordScramblegame=WordScramble()game.play()ScreenshotClass AttributesDEFAULT_DIFFICULTY(str): The default difficulty level, which is'easy'.DEFAULT_ATTEMPTS(int): The default number of attempts allowed, which is3.Methods:__init__(self) -> NoneDescription: Creates an instance of the Word Scramble game by importing list of words for different
difficulty levels.reset(self, difficulty: str = DEFAULT_DIFFICULTY, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Resets the game to the specified difficulty level and number of attempts. Samples a random word
from the corresponding difficulty list and scrambles it.Parameters:difficulty(str, optional): A difficulty level ('easy','medium','hard') (defaults
toDEFAULT_DIFFICULTY).attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS)scramble_word(word: str) -> strDescription: Scrambles a given word.Parameters:word(str): The word to scramble.Returns: The scrambled word.get_word_list(self, difficulty: str) -> list[str]Description: Retrieves a list of words based on the specified difficulty level.Parameters:difficulty(str): A difficulty level ('easy','medium','hard')Returns: A list of words for the given difficulty.validate_input(self, user_input: str) -> boolDescription: Validates the user's input to ensure it contains the same number of characters as the scrambled
word.Parameters:user_input(str): The user's input.Returns:Trueif the input is valid,Falseotherwise.guess(self, user_input: str) -> boolDescription: Checks if the user's guess is correct and updatesattempts.Parameters:user_input(str): The user's input.Returns:Trueif the guess is correct,Falseotherwise.play(self, difficulty: str = DEFAULT_DIFFICULTY, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Starts a game session for a specified difficulty level and number of attempts.Parameters:difficulty(str, optional): A difficulty level ('easy','medium','hard') (defaults
toDEFAULT_DIFFICULTY).attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS)HangmanfrompygameboximportHangmangame=Hangman()game.play()ScreenshotClass AttributesDEFAULT_DIFFICULTY(str): The default difficulty level, which is'easy'.DEFAULT_ATTEMPTS(int): The default number of attempts allowed, which is10.Methods:__init__(self) -> NoneDescription: Creates an instance of the Hangman game with a set of words for different difficulty levels.reset(self, difficulty: str = DEFAULT_DIFFICULTY, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Resets the game to the specified difficulty level and number of attempts, and chooses a random
word from the list.Parameters:difficulty(str, optional): A difficulty level ('easy','medium','hard') (defaults
toDEFAULT_DIFFICULTY).attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS)get_word_list(self, difficulty: str) -> list[str]Description: Retrieves a list of words based on thedifficultylevel.Parameters:difficulty(str): A difficulty level ('easy','medium','hard')Returns: A list of words for the given difficulty.validate_input(self, user_input: str) -> boolDescription: Validates the user's input to ensure it is a single letter and that it hasn't been guessed.Parameters:user_input(str): The user's input.Returns:Trueif the input is valid,Falseotherwise.guess(self, user_input: str) -> boolDescription: Checks if the user's guess is correct and updates the game status (remaining attempts and guessed
letters).Parameters:user_input(str): The user's guess.Returns:Trueif the user has guessed the entire word,Falseotherwise.print_partial(self) -> NoneDescription: Prints the word with the guessed letters filled in and displays the letters remaining to guess.play(self, difficulty: str = DEFAULT_DIFFICULTY, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Starts a Hangman game session.Parameters:difficulty(str, optional): A difficulty level ('easy','medium','hard') (defaults
toDEFAULT_DIFFICULTY).attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS)WordlefrompygameboximportWordlegame=Wordle()game.play()ScreenshotMethods:__init__(self) -> NoneDescription: Initializes the Wordle game with a list of possible words, valid words, and game parameters, such
as
the current word, guesses, and attempts.reset(self, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Resets the game, generating a new word to guess and resetting the guesses and attempts.Parameters:attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS).get_user_input() -> strDescription: Gets the user's input (the guessed word).Returns: The user's input as a string.validate_input(self, guess: str) -> boolDescription: Ensures guessed word is in the list of valid words.Parameters:guess(str): The user's input (guessed word).Returns:Trueif the word is valid,Falseotherwise.check_win(self, guess: str) -> boolDescription: Checks if the user's guess is correct (equals the hidden word).Parameters:guess(str): The user's input (guessed word).Returns:Trueif the guess is correct,Falseotherwise.check_guess(self, guess: str) -> list[int]Description: Checks what characters in the guess are in the correct positions, are misplaced, or not present.Parameters:guess(str): The user's input (guessed word).Returns: A list of integers representing the status of each character in the guess (0: Correct,1:
Misplaced,-1: Not present).print_output(self) -> NoneDescription: Prints the Wordle game state, including feedback on previous guesses.play(self, attempts: int = DEFAULT_ATTEMPTS) -> NoneDescription: Starts a Wordle game session for a specified number of attempts.Parameters:attempts(int, optional): The number of attempts allowed (defaults toDEFAULT_ATTEMPTS).ContributingIf you'd like to contribute to the PyGameBox project, follow these steps to set up your development environment:Fork the repository or clone it directly:gitclonehttps://github.com/software-students-fall2023/3-python-package-exercise-prime-order.gitcdto the folder and create/activate virutal environment:pipenvshellDownload and install dependencies.pipenvinstallYou can work on the module, add other games, or resolve existing issues. Create unit tests for your functions to test
them
intests/.Run the tests using:python-mpytestPush your code changes, create a pull request and contribute to the project's development.