Guru Nanak Institutions Technical Campus (Autonomous)
Department of Information Technology– Special Batch
WORD GUESSING GAME
A Project Report submitted in the
part of
REAL TIME PROJECT
By
Name of the Student: G.JAHNAVI
HT Number: 22WJ8A1221
Section Number: IT-01
Mobile Number: 9347183835
Signature of the Student:
Evaluation Table
S.NO Criteria Marks Awarded (Max 10) Remarks
1 Abstract
2 Introduction
3 Problem statement
4 Scope of the project
5 System analysis
6 Requirements
7 System design
8 Implementation and Testing
9 Results and Conclusion
10 Future improvements and References
Average Marks
SIGNATURE OF FACULTY SIGNATURE OF
COORDINATOR SIGNATURE OF HOD
I
TABLE OF CONTENTS
S.NO CHAPTER / SUB CHAPTER NAME PAGE NUMBER
1 ABSTRACT IV
2 INTRODUCTION V
3 PROBLEM STATEMENT VI
4 SCOPE OF THE PROJECT VI
5 SYSTEM ANALYSIS VII
6 REQUIREMENTS VII-IX
SYSTEM DESIGN
7 IX-XII
IMPLEMENTATION
8 XIII-XIV
TESTING
9 XV- XVI
RESULTS
10 XVII
CONCLUSION
11 XVII
FUTURE IMPROVEMENTS
12 XVII-XVIII
REFERENCES
13 XVIII
II
LIST OF FIGURES
Figure
S.No Name of the Figure Page Number
Number
1 1 SCANNING XV
2 2 INPUT XV
3 3 MESSAGE DISPLAY XV
4 4 DISPLAY ATTEMPTS XVI
5 5 WORD GUESSED XVI
6 6 RESTART THE GAME XVI
III
ABSTRACT
The Word Guessing Game is an engaging and interactive application developed using the
Java programming language. The primary objective of this project is to create a program that
challenges users to guess a randomly selected word from a predefined list within a limited
number of attempts. This game serves as both a source of entertainment and a practical
demonstration of fundamental and advanced Java concepts.
The project has been implemented in two distinct versions:
Console-Based Game: This version focuses on simplicity, providing a text-based
interface where users interact with the program through basic input and output.
Graphical User Interface (GUI)-Based Game: Utilizing the Java Swing library, this version
offers an enriched user experience with graphical components such as buttons, text fields,
and real-time feedback.
Through this project, we explore and apply several critical aspects of
Java programming, including:
Core Programming Constructs: Implementation of loops, conditionals, and data handling
techniques.
String Manipulation and Game Logic: Dynamic word generation, partial hints, and
incremental letter reveals.
Error Handling and Input Validation: Ensuring robustness against invalid inputs for a smooth
user experience.
GUI Design Principles: Creating an intuitive and visually appealing interface for enhanced
player engagement.
Overall, this project serves as a foundation for developing more complex applications,
fostering logical thinking, and enhancing problem-solving and Java programming skills.
IV
INTRODUCTION
The Word Guessing Game is a simple yet engaging application designed to test players’
vocabulary and logical reasoning skills. Developed using the Java programming language,
this project is both a source of entertainment and an educational tool that showcases
fundamental and advanced concepts of Java programming. The game challenges players to
guess a hidden word by identifying its individual characters within a limited number of
attempts, making it an interactive and brain-teasing activity.
This game is structured to provide an exciting user experience with an intuitive design. It
offers a dynamic challenge, as the hidden word is randomly selected from a predefined list,
ensuring that no two games are the same. By partially revealing some letters of the word at
the start, the game encourages players to make informed guesses, combining skill and chance
for an enjoyable gameplay experience. Gameplay and Features
In the Word Guessing Game, the user interacts with the program through a
straightforward console-based interface. The game logic involves the following steps:
Word Selection: A word is randomly chosen from a predefined list at the start of each
game.
Initial Clues: Some letters of the word are revealed randomly to give players a head start.
Guessing Phase: Players attempt to guess the hidden word by entering one letter at a
time.
Validation: Each guess is validated, with correct letters being revealed and incorrect
guesses reducing the number of remaining attempts.
Winning and Losing Conditions: The game ends when the player correctly
guesses all letters of the word or exhausts their allotted attempts.
V
PROBLEM STATEMENT
In today’s digital age, there is a growing need for engaging and interactive applications
that provide both entertainment and learning opportunities. The challenge lies in
designing a simple yet captivating game that is easy to understand, accessible to all age
groups, and effectively demonstrates programming concepts for educational purposes.
Many existing games focus on either entertainment or learning, but few
manage to blend these two aspects seamlessly.
The Word Guessing Game addresses this gap by offering a fun and challenging experience
where users attempt to guess a randomly selected word within a limited number of attempts.
The game requires logical thinking, memory recall, and strategic decision-making, making it
both enjoyable and intellectually stimulating. Additionally, the development of this game
serves as a practical exercise for programmers, providing insights into core programming
constructs, error handling, and user interaction.
SCOPE OF THE PROJECT
The Word Guessing Game is designed to achieve the following objectives and deliverables:
Functional Scope
1. Dynamic Word Selection:
o A word is randomly chosen from a predefined list at the start of each
game, ensuring variety and replayability.
2. Interactive Gameplay:
o Players guess the word one letter at a time, with feedback provided for
correct and incorrect guesses. o Partial letters of the word are revealed at the
start to provide hints and enhance user engagement.
3. Input Validation and Feedback:
o Handles invalid inputs, such as non-alphabetic characters or multiple letters,
with clear feedback to the user.
o Tracks and displays the number of attempts remaining.
4. Winning and Losing Conditions: o Players win if they guess the word within
the allowed attempts.
o The game displays the correct word if the user fails to guess it before attempts
are exhausted.
VI
5. Replayability:
o After each game, users can choose to restart or exit.
SYSTEM ANALYSIS
This project introduces two versions of the game to enhance user engagement and provide a
better overall experience:
Console-Based Version: A simple and straightforward format that focuses on the core
game mechanics. It is designed for users who prefer a minimalistic approach and enjoy text-
based interaction without the complexity of a graphical interface.
GUI-Based Version: This version incorporates Java Swing to create an interactive, visually
appealing interface, offering buttons, text fields, and dynamic feedback. It aims to provide a
more immersive and enjoyable experience, with visual cues and error handling features that
enhance gameplay.
The proposed system aims to address the shortcomings of traditional guessing games by offering
real-time feedback, effective error handling, and a more engaging visual experience, making
the game accessible and enjoyable for a wider audience.
REQUIREMENTS
Software Requirements
1. Operating System:
o Windows 7 or higher, macOS, or Linux.
2. Development Environment:
o Java Development Kit (JDK): Version 8 or higher for compiling
and running the game.
o Integrated Development Environment (IDE): Any of the
following:
IntelliJ IDEA
Eclipse
NetBeans
VS Code (with Java extensions)
VI
3. Libraries and Tools:
o Java Standard Library (Core Java API).
o (Optional for GUI version) Java Swing or JavaFX libraries for graphical user
interface development.
4. Memory Requirements:
o At least 512 MB of RAM for basic console-based functionality. o 1 GB or
more for GUI-based version, depending on the complexity.
5. Storage Space:
o Around 100 MB for JDK, IDE, and related project files.
6. Additional Requirements:
o A text editor (Notepad++, Sublime Text, etc.) for quick edits. o
Command-line tools (Command Prompt, Terminal) for running
console based applications.
❖ Hardware Requirements
1. Processor:
o Minimum: Intel Core i3 or equivalent.
o Recommended: Intel Core i5 or higher for smooth development
and execution.
2. RAM:
o Minimum: 512 MB for the console-based game.
o Recommended: 4 GB or higher for IDE-based development and GUI
applications.
3. Storage:
o Minimum: 100 MB free space for game files, IDE, and JDK.
o Recommended: 1 GB or more for storing additional libraries and future
updates.
4. Input Devices:
VI
o Keyboard for interacting with the game and coding.
o Mouse for GUI-based versions.
5. Display:
o Minimum: 800x600 resolution for console-based game.
o Recommended: 1024x768 or higher for GUI development and
testing.
6. Graphics (Optional for GUI):
o Basic onboard graphics for Swing applications. o Dedicated GPU not
required unless advanced graphical features are implemented.
7. Network (Optional):
o Internet connection for downloading JDK, IDE, and related dependencies. o
Not required for offline gameplay.
Additional Considerations
• Compatibility: The game is designed to run on any Java-supported platform,
ensuring cross-platform compatibility.
• Low Resource Usage: The console-based version has minimal hardware
demands, making it suitable for older systems.
• Expandable Requirements: For future updates like multiplayer or online
gameplay, network and additional hardware resources may be needed.
SYSTEM DESIGN
❖ Architecture
The architecture of the Word Guessing Game is designed to create an interactive and engaging
experience for the player. It ensures seamless communication between user input, game
logic, and feedback generation. The system follows a modular approach, dividing the game
into key components that work together to provide smooth gameplay.
IX
These components are outlined below:
X
1. Random Word Generation:
o A predefined list of words is stored in an array or list. The game randomly
selects a word using Java's Random class to ensure that each game has a
unique word to guess. o The word is kept hidden at the start, with some letters
being revealed as part of the hint.
2. Input Handling:
o Console-Based Version:
▪ User input is captured via the Scanner class, allowing the player to
guess a single letter at a time. Input is validated to ensure that only
one letter is entered, and it is a valid alphabet character.
o GUI-Based Version:
▪ In the GUI version, user input is captured through text fields and
buttons. Players can enter guesses and submit them using a button.
The interaction is visually enhanced with Swing components.
3. Game Logic:
o The game keeps track of the randomly selected word and the number of
attempts left. o It compares the player's guess with the word, revealing the
correct letters and updating the display after each guess . o If the guess is
correct, the word is revealed completely. If the guess is
wrong, the number of attempts decreases. o The game ends either when the
word is completely guessed or the player runs out of attempts, with
appropriate feedback provided at the end of the game.
4. Feedback Generation:
o After each guess, the game provides feedback: "Correct guess!", "Wrong
guess!", or "Congratulations!" based on whether the player's guess matches a
letter in the word. o The remaining attempts and the current state of the word
(with guessed
letters revealed and unguessed ones hidden) are continuously updated.
XI
Data Flow
The flow of data within the system is as follows:
1. User Input:
o The user enters a guess (a single letter) using either the console or a GUI input
field.
2. Input Validation:
o The system checks if the input is valid (a single alphabetic character). If the
input is invalid, the user is prompted to try again.
3. Guess Evaluation:
o The system compares the player's guess with the word. If the letter matches, it is
revealed in the word; otherwise, the number of remaining attempts decreases.
4. Game Update:
o After each guess, the system updates the word display to show the revealed
letters and the remaining attempts. o Feedback is displayed indicating whether
the guess was correct or not.
5. End Conditions:
o The game ends when the word is fully guessed or when the player runs out of
attempts. o A message is displayed indicating whether the player won or lost,
and the option to restart the game or exit is provided.
GUI Mock up (for GUI-Based Version)
For the GUI version of the Word Guessing Game, the user interface consists of several
interactive components:
1. Input Fields:
a. A text field where the user can enter their letter guess. The input is restricted to
a single alphabetic character.
2. Buttons:
XII
a. A Submit Guess button that allows the player to submit their guess
after entering a letter.
b. A Restart Game button that restarts the game after it ends, allowing
players to play again.
c. An Exit Game button that ends the game and closes the application.
3. Feedback Display:
A label or text area where feedback is shown, such as:
• "Correct Guess!" when a guess is right.
• "Wrong Guess! Attempts left: X" when the guess is incorrect.
• "Congratulations! You’ve guessed the word!" when the word is correctly guessed.
• "Game Over! The word was: [word]" if the player runs out of attempts.
4. Word Display:
a. A label or text area displaying the word with revealed and hidden
letters, updating after each guess.
5. Attempt Counter:
a. A label displaying the number of attempts left, providing the player with
a visual cue of how many guesses remain.
Overall Game Flow
1. The game starts by randomly selecting a word from a predefined list and revealing
some of its letters as hints.
2. The user enters a guess, either via the console or the GUI input field.
3. The system checks the guess, updates the word display, and provides feedback
based on the guess's correctness.
XIII
IMPLEMENTATION
Console Based Code:
import java.util.Scanner;
import java.util.Random;
public class WordGuessGame {
public static void main(String[] args) {
String[] words = {"apple", "banana", "orange", "grape", "kiwi"};
Random rand = new Random();
int randomIndex = rand.nextInt(words.length);
String wordToGuess = words[randomIndex];
int attempts = 6;
boolean guessed = false;
Scanner scanner = new Scanner(System.in);
while (attempts > 0 && !guessed)
{ System.out.println("Guess a letter:");
char guess = scanner.next().charAt(0);
guessed = true;
for (int i = 0; i < wordToGuess.length(); i++)
{ if (wordToGuess.charAt(i) == guess) {
System.out.print(guess);
} else {
XIV
System.out.print("_");
guessed = false;
System.out.println()
; attempts--;
if (guessed) {
System.out.println("Congratulations! You win!");
} else {
System.out.println("You lose. The word was: " + wordToGuess);
XV
TESTING
1) Working of the character scanning
Characters are tested if they are Scanned or not and the Program is providing a proper Guess
2) Entering Two or More Characters Shows Invalid Input
3) When Entered Numerics Displays Message Displays Message “Enter Alphabets From A-Z”…
XVI
4) When Attempts are Exhausted it Displays Attempts Are Over:
5) If the Word is Guessed Correctly in The Mentioned
Attempts Shows Word Guessed Correctly
6) To Restart a Game Press Yes and No to Exit
XVII
RESULTS
Console Version:
Functionality: The console version operates smoothly, responding promptly to
user inputs. It correctly handles both valid and invalid inputs and provides the
appropriate feedback on guesses, ensuring that the player is informed about
whether their guess is too high, too low, or correct.
User Experience: The console version offers a straightforward, text-based
interaction, and the game logic is clearly communicated through the console
output, making it accessible and easy to use for all players.
CONCLUSION
The "Word Guessing Game" effectively showcases essential Java programming concepts
such as random word selection, string manipulation, input validation, and iterative logic. By
incorporating a console-based interactive interface, it ensures a straightforward yet engaging
experience for users. The game's dynamic elements, such as revealing random letters and
validating user input, enhance its interactivity and maintain user interest. Additionally, the
structured gameplay and replay option make it both educational and entertaining,
highlighting the potential for simple projects to demonstrate core programming skills while
providing an enjoyable challenge.
FUTURE IMPROVEMENTS
Expanding the Range of Words: Allowing players to guess words within
a larger range would increase the challenge and excitement of the game.
Adding a Scoreboard Feature: Implementing a scoreboard to track players'
performances over multiple games could enhance competitiveness and replay
value.
Introducing Difficulty Levels: Providing different levels of difficulty, such
as varying ranges or reducing the number of attempts, would make the game more
dynamic and suitable for a wider audience.
XVIII
Timers-Introducing timers so that Players can view Their best Time and
Compete with others…
Using GUI, JAVA SPRINGBOOT, AND JAVA FRAMEWORKS
(GUI Based Code)- The Program Can use these to make The Game More
Enhancing and Engaging.
These potential enhancements would further elevate the game's functionality and appeal,
making it a more versatile and engaging application.
REFERENCES
1. Oracle Java Documentation: Comprehensive official documentation for
Java programming concepts, libraries, and best practices.
https://docs.oracle.com/javase/
2. TutorialsPoint: An accessible guide for understanding Java Swing
basics, including
GUI development components and
examples.
https://www.tutorialspoint.com/java_swing/index.htm
3. Stack Overflow: Community-driven platform for addressing practical issues,
including handling random number generation and implementing game logic in
Java. https://stackoverflow.com/
These references served as valuable resources in understanding and implementing the core
features and advanced functionalities of the Number Guessing Game.
XIX