Assignment 2: Rewrite Game with Class

Assignment 2: Rewrite Game with Class#

Problem Description#

In this assignment, you will enhance the existing Triple Combo Game by refactoring it to use Python classes. This will not only improve the code structure but also provide you with practical experience in object-oriented programming.

Background#

The Triple Combo Game is a simple yet engaging game where players select numbers from a pool to build an array and earn points by forming consecutive triplets of the same number. Each time a triplet is formed, it is removed from the array, and the player earns points. The game ends when the array reaches a predefined maximum length.

Objectives#

  1. Game Initialization:

    • Initialize a pool of random numbers that players can choose from.

    • Define an array where the chosen numbers will be stored.

    • Set up a scoring system to track the player’s points.

  2. Gameplay Mechanics:

    • Display the current state of the array and the available pool of numbers to the player.

    • Allow the player to select a number from the pool and add it to the array.

    • Check for any consecutive triplets of the same number in the array. If found, remove them and update the score.

    • Ensure the game continues until the array reaches its maximum length.

  3. User Interaction:

    • Prompt the player for input and validate the input to ensure it is a number from the pool.

    • Provide feedback to the player, including their current score, the state of the array, and the available pool of numbers.

    • End the game when the array reaches its maximum length and display the final score.

Deliverables#

  • A Python script that implements the Triple Combo Game using classes with the above-described functionality.

  • Clear and concise comments in the code explaining the logic and flow of the game.

  • User-friendly prompts and messages to enhance the player’s experience.

Instructions#

  1. Class Structure:

    • Define a TripleComboGame class with methods for game initialization, displaying status, handling user input, updating the array and pool, and checking for game over conditions.

  2. Input Validation:

    • Implement the input_validation method to ensure the user selects a valid number from the pool.

  3. Update Array:

    • Implement the update_array method to add the selected number to the array and check for any triplets to remove and score points.

  4. Update Pool:

    • Implement the update_pool method to remove the selected number from the pool and add a new number.

  5. Game Over Check:

    • Implement the check_game_over method to determine when the array has reached its maximum length and end the game.

Download assignment2.py script from here to review and complete game logic.