In this tutorial, we are going to create a Sudoku puzzle using pygame and beautiful soup.
What is a Sudoku puzzle?
The goal of this puzzle is to fill a 9x9 grid with numbers from 1 to 9, so that each row, column, and 3x3 sub-grid have no other duplicate.
Why pygame?
Python alone is not enough to build a game. Pygame is an external library of python that can help python to write a game. It contains generates an interface where we can interact with python.
Getting started
Install virtual environment
pip install virtualenv
Create a Virtual environment in the folder your project is in and activate
virtualenv env
to active in windows
env\Scripts\activate.bat
to activate in UNIX and MAC
source env/bin/activate
After setting up your environment, install:
pip install pygame beautifulsoup
Create two python files, main.py, and settings.py in the project folder. main.py file is the core file to run the project. settings.py file is to set the interface height and width.
File structure
---Sudoku
|--- main.py
|--- settings.py
|--- buttons.py
|---app_class.py
main.py: this is the python file you need to run for the game run.
Settings.py: in this file, we will decide the settings for the game. Like the height and width of the game window, font size, font-weight, etc.
buttons.py: in this file, we write the functions when the buttons in the game are pressed.
app_class.py: this is the core file where all mathematical and logical operations are written.
Output
Below is the screenshot for the sudoku game after running main.py. The window comprises five buttons, namely submit, easy, medium, Hard, Evil.
Easy, medium, hard and evil are the difficulty level settings of the puzzle.
Give your input in blank blocks and submit your answer. After submitting, blank blocks and wrong answer block turns red, otherwise stays as a white block.
Comments