Our Hearts implementation and Graphics
For our project, we started with an existing implementation of Hearts from GitHub and spent a few weeks modifying it. The original code had a lot of redundancies, with variable and method names being reused in different classes despite having different inputs, outputs, and purposes. This made the code difficult to follow and debug, so I cleaned it up to improve clarity and organization. Making the code more structured not only helped with debugging but also made it much easier to implement graphics.
To create the graphical interface, we used Pygame. First, we set up a display window and added a background. We take the player's hand and render the cards as sprites, which allowed for interactions like clicking and moving them. We organized the sprites into different groups so they could be displayed in different areas of the screen as needed. We also implemented a system for handling the player's turn: when it's their move, the game waits for input, and once they click a card, it disappears from their hand, and the remaining cards shift to adjust for the missing space. Resizing the hand was particularly tricky since every time a card was played, all the remaining cards had to be repositioned dynamically.
Once a card is played, it moves into a separate sprite group representing the current trick. When the trick is complete, the winning player collects the cards, and their score updates based on the points earned. Overall, these graphical features make the game more interactive and provide a clearer way to track the flow of play.