R - Wordle Game CS Project
R - Wordle Game CS Project
1 | Page
ACKNOWLEDGMENT
Student Signature
2 | Page
HARDWARES AND
SOFTWARES
REQUIRED
HARDWARES
1. Desktop Computer / Laptop
2. Mobile Phone
SOFTWARES
1. Python
2. MySQL
3. MySQL-Connector-Python,Flask
3 | Page
TABLE OF CONTENTS
S.No.
Topic Page No.
1 Certificate 1
2 Acknowledgement 2
3 Hardwares and Softwares
3
Required
4
Introduction 5
5
Python Source Code 10
6
MySQL Database 45
7
Outputs 48
8
References 56
4 | Page
INTRODUCTION
The project LIBRARY MANAGEMENT SYSTEM (DIGITAL
LIBRARY) includes enrolment of users, adding of books into
the library system. The software has the facility to search for
news, Wikipedia articles. It includes an authentication facility
for admin and user to login into the admin panel and user
panel resp. of the system. User can see the books available,
details of books issued by the user in the digital library. The
Library Management System can be login using a user ID and
password. It is accessible either by an admin or user. Only the
admin can add, delete and update the data of users and
books into the database. The data can be retrieved easily. The
interface is very user-friendly. The data are well protected for
personal use and makes the data processing very fast. The
purpose of the project entitled as “DIGITAL LIBRARY” is to
computerize the Front Library Management to develop
software which is user friendly, simple, fast, and cost-
effective. It also has a notes facility where the user can add
notes at any point of the program into the database.
5 | Page
LIBRARY
6 | Page
Wordle Game Using SQL Database
And Python
This project is a web-based implementation of the popular
word puzzle game Wordle, designed to challenge players'
vocabulary and logical deduction skills. Players attempt to
guess a hidden word by submitting five-letter words,
receiving feedback after each guess. The ultimate goal is to
determine the correct word within a limited number of
attempts.
The project is built using Python and Flask for back-end
development and an SQL database that stores a collection of
5,000 five-letter words. The database ensures that guesses
are validated and that the hidden word is selected randomly
from a rich dataset of possible answers.
Key aspects of the project include:
Game Logic: Implements the rules of Wordle, providing
feedback on guesses:
Green: Correct letter in the correct position.
Yellow: Correct letter in the wrong position.
Gray: Incorrect letter.
7 | Page
Database Integration: Utilizes an SQL database to:
Validate user guesses against a predefined list of valid
five-letter words.
Randomly select a new target word for each game
session.
Interactive User Interface: Allows users to:
Enter their guesses.
View previously guessed words with color-coded
feedback.
Use a virtual keyboard that updates dynamically to
indicate which letters are correct, misplaced, or absent.
Real-Time Feedback: Ensures that players receive instant
updates after submitting a guess, improving engagement
and usability.
7 | Page
Python Source
Code
https://github.com/DhrG23/Wordle_game.git
10 | Page
from flask import Flask, request, render_template, session, redirect, url_for, jsonify
@app.route('/', methods=['GET',
'POST']) def wordle():
if 'game_state' not in session:
# Initialize session variables
session['game_state'] = {
'attempts': [],
'keyboard': {chr(c): None for c in range(97, 123)}, # a-z with initial state None
'game_over': False,
'message': ""
}
game_state = session['game_state']
if len(user_word) != len(CORRECT_WORD):
game_state['message'] = f"Word must be {len(CORRECT_WORD)} letters long."
elif len(game_state['attempts']) >= 5:
game_state['message'] = f"Game over! The correct word was '{CORRECT_WORD}'."
game_state['game_over'] = True
else:
feedback = []
for i, char in enumerate(user_word):
if char == CORRECT_WORD[i]:
feedback.append('green') # Correct position
game_state['keyboard'][char] = 'green'
elif char in CORRECT_WORD:
feedback.append('yellow') # Correct letter, wrong position
if game_state['keyboard'][char] != 'green': # Avoid downgrading green game_state['keyboard']
[char] = 'yellow'
else:
feedback.append('gray') # Incorrect letter
game_state['keyboard'][char] = 'gray'
/* General styling */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.message {
font-size: 1.2rem;
margin-bottom: 20px;
}
/* Guesses */
.guesses {
margin: 20px 0;
}
/* General styling */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.message {
font-size: 1.2rem;
margin-bottom: 20px;
}
/* Guesses */
.guesses {
margin: 20px 0;
}
.guess {
display: flex;
justify-content: center;
gap: 5px;
margin-bottom: 10px;
}
.letter {
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
font-size: 1.2rem;
font-weight: bold;
border: 1px solid #ccc;
border-radius: 5px;
}
.green {
background-color: #6aaa64;
color: white;
}
.yellow {
background-color: #c9b458;
color: white;
}
.gray {
background-color: #787c7e;
color: white;
}
/* Keyboard */
.keyboard {
margin-top: 20px;
}
.keyboard-row {
display: flex;
justify-content: center;
gap: 5px;
margin-bottom: 10px;
}
.key {
width: 40px;
height: 40px;
font-size: 1rem;
border: none;
border-radius: 5px;
background-color: #d3d6da;
cursor: not-allowed;
}
.key.green {
background-color: #6aaa64;
color: white;
}
.key.yellow {
background-color: #c9b458;
color: white;
}
.key.gray {
background-color: #787c7e;
color: white;
}
.word-form input {
z- index: 1; /* Ensure it's above other elements
*/ pointer-events: auto; /* Ensure it's interactive
*/
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wordle Game</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<div class="container">
<header>
<h1>Wordle Game</h1>
</header>
<main>
<p class="message">{{ game_state['message'] }}</p>
48 | Page
1.
REFERENCES
1. Flask Documents
https://flask.palletsprojects.com
2. Wikipedia
https://www.wikipedia.org/
3. Python
https://www.python.org/
4. MySQL
https://www.mysql.com/
56 | Page