0% found this document useful (0 votes)
9 views9 pages

Java Mini Project

The document describes a mini project on a Hangman Game developed in Java, showcasing basic programming concepts through a console-based word-guessing game. The game features automatic letter reveals, emoji-based feedback, and a limited lives system, making it engaging for users of all ages. It is designed to be simple and user-friendly, suitable for demonstrating creativity and logic building in Java programming.

Uploaded by

nishant0121106
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)
9 views9 pages

Java Mini Project

The document describes a mini project on a Hangman Game developed in Java, showcasing basic programming concepts through a console-based word-guessing game. The game features automatic letter reveals, emoji-based feedback, and a limited lives system, making it engaging for users of all ages. It is designed to be simple and user-friendly, suitable for demonstrating creativity and logic building in Java programming.

Uploaded by

nishant0121106
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

DAV CENTENARY COLLEGE

FARIDABAD

Mini Project
on
Java

SUBMITTED TO : SUBMITTED BY:


HANGMAN GAME : JAVA PROJECT

Project Name: Hangman Game


Introduction:
This mini-project is a simple console-based game developed to demonstrate basic programming
concepts using Java. The game is designed in the style of the classic "Hangman" word-guessing
game, but with an enhanced and modern touch using emojis to make the gameplay more attractive
and interactive. It helps the user understand how loops, conditions, string handling, and user input
work together in a real program.

Rules of the Hangman Game


1. The player must guess the hidden word by suggesting one letter at a time. Each incorrect
guess reduces the number of remaining chances.
2. At the beginning of the game, one letter of the word is revealed automatically.
This gives the player an initial hint and makes the game more engaging.
3. The player wins if all letters of the word are correctly guessed before the chances run
out.
If all chances are exhausted, the game ends and the complete word is displayed.

Features Offered:
1. Automatic Letter Reveal:
At the start of the game, one random letter from the hidden word is revealed to help the
player begin.
2. Emoji-Based Feedback:
The game uses friendly emojis to display progress, lives, wrong attempts, and winning or
losing messages, making the experience fun and engaging.
3. Limited Lives System:
The user gets 6 chances to guess the word correctly. Each wrong guess reduces one life.

4. Real-Time Word Display:


The program updates the word after every correct guess, showing which letters have been
discovered.
5. Duplicate Guess Protection:
If the user enters the same letter again, the program informs them without deducting a life.
6. Simple and User-Friendly Gameplay:
The game runs directly in the console and is easy to understand for any beginner.

Language Used:
GURUDAS 1241182106

This project is developed using the Java programming language, known for its simplicity and
readability.

End User:
This mini project is designed for any user who enjoys simple console-based games. It can be
played by people of all age groups who want a quick and entertaining word-guessing challenge. The
game is also suitable for displaying as a Java miniproject, where the focus is on demonstrating
creativity, logic building, and interactive console design.

Page 3 of 9
GURUDAS 1241182106

PROGRAM INPUT :
import [Link].*;

public class Hangman_Game {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Random rnd = new Random();

[Link]("🎉🎉 WELCOME TO HANGMAN GAME 🎉🎉");


[Link]("----------------------------------");
[Link]("Guess the hidden word by entering letters.\n");

boolean playAgain = true;

// Word list (simple & common words)


String[] words = {
"computer", "programming", "hangman", "language", "keyboard",
"internet", "laptop", "college", "developer", "software"
};

while (playAgain) {
String word = words[[Link]([Link])].toLowerCase();
char[] hidden = new char[[Link]()]; [Link](hidden,
'_');

Set<Character> correct = new HashSet<>();


Set<Character> wrong = new LinkedHashSet<>(); int
wrongLimit = 6;
int wrongCount = 0;

char reveal = [Link]([Link]([Link]())); revealLetter(reveal, word,


hidden, correct);
[Link]("✨ A random letter has been revealed for you: '" + reveal
+ "'");

boolean won = false;

while (wrongCount < wrongLimit) {


[Link]("\n----------------------------------");
[Link]("📝 Word : " + spaced(hidden));
[Link]("❌ Wrong attempts: " + wrongCount + "/" + wrongLimit);
[Link]("👍 Correct letters : " + setToString(correct));
[Link]("👎 Wrong letters : " + setToString(wrong));
[Link]("\n➡ Enter a letter: ");

Page 4 of 9
GURUDAS 1241182106

String input = [Link]().trim().toLowerCase();

if ([Link]() != 1 || ![Link]([Link](0)))
{ [Link]("⚠ Please enter only ONE alphabet character!");
continue;
}

char guess = [Link](0);

if ([Link](guess) || [Link](guess)) {
[Link]("⚠ '" + guess + "' already guessed. Try another letter.");
continue;
}

if ([Link](guess) >= 0) {
revealLetter(guess, word, hidden, correct);
[Link]("✅ Good guess! '" + guess + "' is in the word.");

// Check win
if ([Link](hidden).equals(word)) {
won = true; break;
}
} else {
[Link](guess);
wrongCount++;
[Link]("❌ '" + guess + "' is not in the word.");
}
}

// Final result
[Link]("\n==================================");

if (won) {
[Link]("🎉 CONGRATULATIONS! You guessed the word!");
[Link]("🎯 Word was: " + word);
} else {
[Link]("😢 GAME OVER!");
[Link]("🔍 The correct word was: " + word);
}

[Link]("==================================\n");

// Ask to play again


[Link]("🔁 Do you want to play again? (y/n): "); playAgain =
[Link]().trim().toLowerCase().startsWith("y");
}

Page 5 of 9
GURUDAS 1241182106

[Link]("\n👋 Thanks for playing Hangman! Goodbye!"); [Link]();


}

static void revealLetter(char ch, String word, char[] hidden, Set<Character>


correct) {
for (int i = 0; i < [Link](); i++) {
if ([Link](i) == ch) {
hidden[i] = ch;
}
}
[Link](ch);
}

static String spaced(char[] arr) { StringBuilder sb


= new StringBuilder(); for (char c : arr)
[Link](c).append(" ");
return [Link]().trim();
}

static String setToString(Set<Character> set) {


if ([Link]()) return "None"; StringBuilder
sb = new StringBuilder(); for (char c : set)
[Link](c).append(' ');
return [Link]().trim();
}
}

OUTPUT
STARTING OF GAME :

Page 6 of 9
GURUDAS 1241182106

Guessing The Character (Correct Guess) :

Guessing The Character (Wrong Guess) :

Page 7 of 9
GURUDAS 1241182106

User Won The Game :

Page 8 of 9
GURUDAS 1241182106

UserLostThe Game :

Page 9 of 9

You might also like