0% found this document useful (0 votes)
51 views22 pages

R - Wordle Game CS Project

Uploaded by

veerjyotsammi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views22 pages

R - Wordle Game CS Project

Uploaded by

veerjyotsammi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Shaheed Rajpal DAV Public School

COMPUTER SCIENCE PROJECT


2024-2 5
PROJECT TOPIC:
Wordle Game Using SQL Dataset & Python
Submitted by:
Name: Dhruv Gautam
Class: XII-C
CBSE Roll Number:
Under the Guidance of:
Vineeta Garg, PGT (CS)
CERTIFICATE

This is to certify that DHRUV GAUTAM of class: XII - C of


SHAHEED RAJPAL DAVPUBLIC SCHOOL has done his project
on WORDLE GAME USING SQL DATASET AND PYTHON under
my supervision. He has taken interest and has shown at most
sincerity in completion of this project. I certify this project up
to my expectation & as per guidelines issued by CBSE, NEW
DELHI.

Internal Examiner External Examiner

1 | Page
ACKNOWLEDGMENT

On completion of my investigatory project, I feel extremely


delighted. It wasn’t a single effort. I would like to thank my
Computer science teacher for supporting me and giving me
this opportunity to work on this project. I would like to thank
my parents for helping and encouraging me to pursue this
project.

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

The Wordle Game is a popular word puzzle that


challenges players to guess a hidden word within a
limited number of attempts. This project replicates
the mechanics of the game using Python and Flask,
creating an interactive, web-based experience.
Players input their guesses and receive immediate
feedback through color-coded hints, which indicate
the correctness of their guesses and help them refine
subsequent attempts. The goal is to deduce the
correct word before exhausting the allotted
attempts.

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.

The combination of a robust SQL database with a dynamic


web application demonstrates a comprehensive approach to
building an interactive game. This project highlights my skills
in designing back-end logic, integrating databases, and
creating user-friendly front-end interfaces.

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 = Flask( name )


app.secret_key = "your_secret_key"

# Define the correct word


CORRECT_WORD = "flask"

@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 request.method == 'POST' and not game_state['game_over']:


user_word = request.form['word'].lower()

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'

game_state['attempts'].append({'word': user_word, 'feedback': feedback})


if user_word == CORRECT_WORD:
game_state['message'] = "Correct! You guessed the word!"
game_state['game_over'] = True
elif len(game_state['attempts']) >= 5:
game_state['message'] = f"Game over! The correct word was '{CORRECT_WORD}'."
game_state['game_over'] = True
else:
game_state['message'] = f"Wrong! Attempts left: {5 - len(game_state['attempts'])}"
session.modified = True

/* 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>

<!-- Display guessed words with feedback -->


<div class="guesses">
{% for attempt in game_state['attempts'] %}
<div class="guess">
{% for i in range(attempt['word']|length) %}
<span class="letter {{ attempt['feedback'][i] }}">
{{ attempt['word'][i] }}
</span>
{% endfor %}
</div>
{% endfor %}
</div>
Outputs

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

You might also like