Skip to content

Four in a row GUI game built with tkinter, promoting OOP design

Notifications You must be signed in to change notification settings

NakerTheFirst/Four-in-a-row

Repository files navigation

Four In A Row

A Python-based implementation of a connect-four style game featuring both console and GUI interfaces, allowing play against another human or an AI opponent. It leverages object-oriented programming principles, showcasing polymorphism, inheritance, and composition to create a well-structured and extensible codebase.


Image of an interface of a four in a row game

Game's Graphical User Interface

Project Structure

  • main.py: The entry point of the application. Initializes and starts the game engine.
  • engine.py: Manages the game's main loop and switches between different interfaces (console or GUI). Demonstrates the use of composition by managing different components of the game.
  • board.py: Contains the Board class which handles the game's logic, including grid management and win conditions.
  • player.py: Abstract base class for players, providing a framework for HumanPlayer and AIPlayer. This is a clear example of polymorphism, allowing the use of different player types interchangeably.
  • human_player.py: Implements the human player functionality, handling user inputs. Inherits from Player.
  • ai_player.py: Implements AI behavior, making decisions randomly within the game constraints. Inherits from Player.
  • ui.py: Abstract base class for user interfaces, exemplifying the use of polymorphism through different user interface implementations.
  • console_interface.py: Console-based interface for the game, displaying the board state in the terminal. Inherits from UI.
  • gui.py: Graphical user interface using Tkinter to provide a visual game experience. Inherits from UI and demonstrates advanced polymorphism and composition.

Class diagram

Image of a class diagram of a four in a row game

Usage

Run the game by executing main.py. You'll be prompted to choose between the console and GUI interface and select the type of opponent (human or AI).

About

Four in a row GUI game built with tkinter, promoting OOP design

Topics

Resources

Stars

Watchers

Forks

Languages