Skip to content

JoshuaO956/CPEN_333_Final_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPEN_333_Final_Project

This repository contains two interactive Python projects developed in collaboration with a partner for UBC's CPEN 333 courses, exploring real-time systems through graphical interfaces, multithreading, and network communication.
Each part is built on a template provided by the course instructor and demonstrates structured class-based design, thread-safe operations, and event-driven programming, with clear separation between logic and interface.

Part 1 – Multithreaded Snake Game (Tkinter + Pygame)

A functional snake game built in Python, originally developed using Tkinter for the GUI (part1.py) and later re-implemented with Pygame as an alternative version (part1_alternative.py). The game loop runs on a separate thread and communicates with the GUI through a thread-safe queue to ensure responsiveness and concurrency.

Key Features

  • Real-time snake movement and prey generation
  • GUI versions using both Tkinter and Pygame
  • Clean separation of game logic and rendering logic
  • Queue-based communication between threads

Design Overview & Key Insights

The game is structured around several core classes:

  • Game: Manages all gameplay logic, including snake movement, prey generation, and collision detection.
  • QueueHandler: Facilitates safe communication between the game loop and the GUI using a thread-safe queue.
  • GUI wrappers (SnakeApp for Tkinter, PygameApp): Handle rendering, user input, and interface updates based on queued tasks.

These components were designed to ensure modularity, reusability, and responsiveness.

Through this project, we:

  • Built a thread-safe game loop using Python’s queue and threading modules
  • Compared widget-based and immediate-mode GUI paradigms (Tkinter vs Pygame)
  • Improved understanding of coordinate systems, bounding boxes, and frame-based animation
  • Tuned gameplay variables like step size for balanced control and difficulty

Testing

  • Implemented bounding box checks to prevent prey from overlapping with snake or score display
  • Validated movement and collision logic by simulating sequences and adjusting step size
  • Pygame version tested frame redrawing and event queue handling under different framerates

Screenshots – Snake Game

Tkinter Version
The original version of the game was built using Tkinter's canvas system. The screenshot below shows the snake navigating the playfield, with score tracking and live prey generation.

Snake Game - Tkinter Version

Pygame Version
This alternative version re-implements the GUI using Pygame intended as extra challenge.

Snake Game - Pygame Version

Part 2 – Client-Server Chat Application

A lightweight chat system built using Python’s socket module and Tkinter GUI. The project runs a centralized server and multiple clients on localhost, each in its own process, simulating a real-time messaging environment.

Client-Server Architecturen

Key Features

  • Centralized TCP server to handle multiple clients
  • Each client has its own scrollable chat window
  • Real-time message broadcast with basic error handling
  • Graceful disconnect detection and auto-shutdown of server

Design Overview & Key Insights

This project is organized around two core classes:

  • ChatServer: Manages all incoming client connections, maintains a dictionary of client sockets, relays messages between clients, and updates the server-side chat display.
  • ChatClient: Provides the user interface, handles user input, connects to the server, and displays messages in real time.

Both classes make use of dedicated threads to manage socket communication without blocking the GUI. This separation ensures a responsive user experience and allows each component to remain modular and testable.

Through this project, we:

  • Learned to create and manage socket-based TCP connections between multiple processes
  • Built thread-safe message-passing systems between sockets and GUIs using threading and Tkinter
  • Designed both client and server to operate independently while sharing a common communication protocol
  • Encountered and debugged platform-specific issues related to GUI updates and firewall/network permissions (e.g., macOS socket restrictions)

Testing & Challenges

  • Verified message delivery between multiple client windows
  • Tested auto-shutdown on full client disconnect
  • Addressed platform-specific issues including Tkinter widget thread-safety and socket binding behavior

Screenshots – Chat Application

Attached below is an image of the chat application in action:

Chat Application in Action

Contributions

Team Member Contributions
Joshua Obi Lead developer on chat application and co-programmer for the Snake Game Alternative
Bevio Chen Lead developer for the Snake Game and co-programmer for the Snake Game Alternative

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages