Wordle-Clone-In-Python

Wordle Clone in Python

Description

What is Wordle?

Wordle is a web-based word game created and developed by Welsh software egineer Josh wardle and owned and published by the New York Times Company since 2022.
Every day, a five-letter word is chosen at random wich players aim to guess within six tries. After every guess, each letter is marked as either green, yellow or gray: green indicates that letter is correct and in the correct position, yellow means it is in the answer but not in the right position, while gray indicates it is not in the answer at all.1


Why PyQt5?

PyQt5 is a Python binding of the popular GUI (Graphical User Interface) toolkit, Qt. It allows developers to create desktop applications that can run on different operating systems, such as Windows, macOS, and Linux. PyQt5 provides a wide range of features and widgets for building interactive and professional-looking applications.

In addition, PyQt5 includes a designer called “QT Designer” that enables developers to create beautiful GUIs that can be programmed to perform various tasks.

PyQt5 has a wide range of uses. It can be used to develop games, desktop applications, educational apps, and scientific computing and data visualization using Python libraries such as NumPy, Pandas, and Matplotlib, which are important for data science. The main purpose of the Wordle Clone was to practice PyQt5 and gain more familiarity with its capabilities.


Files and Folders

***Assets*** folder contains the Icons folder as well as all the UI files generated by QT Designer.
***Dataset*** folder contains the words data used for the game in words_alpha.txt.
***Fonts*** folder contains the fonts used in the clone.
***Logs*** folder is initially empty and is used to track if the player won or lost in a given day, and they can’t play more than once.


Usage & Info

To use this program, simply run the **main.py** file. Upon execution, the main() function will initialize a random word from the dataset using the current date as a seed, generating a new random word each day. An instance of the MainWindow class will then be initiated.

The MainWindow class contains all the functionality of the game, including the main game mechanics and connections to other parts of the game in different files.

To explain how the files connect, let’s start with the keyboard. There are two ways to input letters in the game: the laptop’s keyboard ( keyPressEvent() ) and the custom-made keyboard in the game itself ( ButtonClicks() ). Both of these are mapped to the appropriate letter-pressed function in the **keyboard.py** file.

For example, if the user enters the letter “W”, both of these functions will check if there is still space to add letters (i.e., if the letters in one row are less than or equal to 5, and if the number of attempts is less than or equal to 6 (maximum number of rows)). If there is space, the “W” button is connected to WButtonClicked(), which takes settings.try_count and settings.letter_count - global variables stored in **settings.py** - to indicate which row the user is filling and how many letters they have entered.

In the WButtonClicked() function, we first check whether there is space to insert a letter. If there is, the letter associated with the function is set for the current box to be filled, and that letter is added to a temporary string used to compare with the randomly chosen word to see if any of the letters are present in the target word. If so, we check if any of the letters are in the correct place and display that information on the game screen when the “Enter” button is pressed. This involves changing the colors of the boxes to indicate whether the letter is in the word or not. All of this is happening in the BaseGame() function in the **main.py** file.

The game is designed to be played once per day, to prevent cheating where the player can exit and re-enter the game to increase their score. To achieve this, the **played_checker.py** file contains three functions:

Since the scores and stats were just mentioned let’s talk about them, the **scores.py** handles just that, which has different functions:


Instructions for Installing Fonts

If you experience any display issues or the fonts don’t appear correctly when running the game, it might be due to missing fonts on your machine. To resolve this issue, please follow the steps below:

After following these steps, you should be able to run the game without any issues related to missing fonts.

Referances

  1. https://en.wikipedia.org/wiki/Wordle