Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Hidden CodeBreaker game #4412

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Games/Hidden-CodeBreaker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Puzzle Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Word Puzzle Game</h1>
<p>Guess the hidden word by clicking on the letters below.</p>
<div class="word-container" id="wordContainer">
<!-- Hidden word will be dynamically inserted here -->
</div>
<p class="clue" id="clue">Clue: <span id="clueText">_ _ _ _ _</span></p>
<div class="letters" id="letters">
<!-- Letters will be dynamically inserted here -->
</div>
<p id="resultMessage"></p>
<p class="lives" id="lives">Lives: <span id="livesCount">5</span></p>
<button id="homeButton" class="home-button" onclick="resetGame()">Home</button>
</div>
<script src="script.js"></script>
</body>
</html>
122 changes: 122 additions & 0 deletions Games/Hidden-CodeBreaker/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const levels = [
{
words: ["HTML", "CSS", "JAVASCRIPT", "PYTHON", "JAVA"],
clues: ["The structure of a webpage", "The style of a webpage", "The language used for web development", "A popular programming language for data science", "A versatile programming language"]
},
{
words: ["RUBY", "PHP", "NODEJS", "REACT", "ANGULAR"],
clues: ["A programming language known for its simplicity", "A server-side scripting language", "A JavaScript runtime built on Chrome's V8 JavaScript engine", "A JavaScript library for building user interfaces", "A platform and framework for building single-page client applications"]
},
{
words: ["VUE", "DATABASE", "MYSQL", "MONGODB", "POSTGRESQL"],
clues: ["A progressive JavaScript framework", "A structured set of data held in a computer", "An open-source relational database management system", "A cross-platform document-oriented database program", "A powerful, open-source object-relational database system"]
},
{
words: ["ALGORITHM", "DATASTRUCTURE", "COMPLEXITY", "INHERITANCE", "ABSTRACTION"],
clues: ["A set of rules or instructions for solving a problem", "A particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently", "The state or quality of being intricate or complicated", "A mechanism of reusing code in object-oriented programming", "A fundamental principle in object-oriented programming"]
},
{
words: ["ENCAPSULATION", "POLYMORPHISM", "RECURSION", "ITERATION", "STACK"],
clues: ["The bundling of data with the methods that operate on that data", "The ability of a single function or method to operate on multiple types of data", "A programming technique in which a function calls itself", "A repetitive process that repeats a set of instructions until a specified condition, known as the termination condition, is met", "A data structure that follows the Last In, First Out (LIFO) principle"]
}
];

let currentLevel = 0;
let hiddenWord = '';
let revealedLetters = [];
let lives = 5;

function initializeGame() {
if (currentLevel < levels.length) {
const currentLevelData = levels[currentLevel];
const randomIndex = Math.floor(Math.random() * currentLevelData.words.length);
hiddenWord = currentLevelData.words[randomIndex];
revealedLetters = new Array(hiddenWord.length).fill(false);
displayWord();
displayLetters();
displayClue(randomIndex);
updateLivesDisplay();
} else {
showMessage("Congratulations! You've completed all levels.");
}
}

function displayWord() {
const wordContainer = document.getElementById('wordContainer');
wordContainer.innerHTML = '';
for (let i = 0; i < hiddenWord.length; i++) {
if (revealedLetters[i]) {
wordContainer.innerHTML += `<span>${hiddenWord[i]}</span>`;
} else {
wordContainer.innerHTML += `<span>_</span>`;
}
}
}

function displayLetters() {
const lettersContainer = document.getElementById('letters');
lettersContainer.innerHTML = '';
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let letter of alphabet) {
lettersContainer.innerHTML += `<div class="letter" onclick="revealLetter('${letter}')">${letter}</div>`;
}
}

function displayClue(index) {
const clueText = document.getElementById('clueText');
const currentLevelData = levels[currentLevel];
clueText.textContent = currentLevelData.clues[index];
}

function revealLetter(letter) {
let found = false;
for (let i = 0; i < hiddenWord.length; i++) {
if (hiddenWord[i] === letter) {
revealedLetters[i] = true;
found = true;
}
}
displayWord();
if (found) {
if (revealedLetters.every((val) => val === true)) {
showMessage("Congratulations! You've guessed the word.");
setTimeout(() => {
nextWord();
}, 2000);
}
} else {
lives--;
updateLivesDisplay();
if (lives === 0) {
showMessage("Game Over. You've run out of lives.");
} else {
showMessage("Incorrect letter. Try again.");
}
}
}

function showMessage(message) {
const resultMessage = document.getElementById('resultMessage');
resultMessage.textContent = message;
}

function updateLivesDisplay() {
const livesCount = document.getElementById('livesCount');
livesCount.textContent = lives;
}

function nextWord() {
lives = 5; // Reset lives for the next word
currentLevel++;
initializeGame();
}

function resetGame() {
currentLevel = 0;
lives = 5;
initializeGame();
showMessage('');
}

// Start the game
initializeGame();
109 changes: 109 additions & 0 deletions Games/Hidden-CodeBreaker/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Raleway:wght@400;700&display=swap');

body {
font-family: 'Roboto', sans-serif;
background-color: #1a1a2e;
color: #f5f6fa;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
text-align: center;
background-color: #16213e;
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
max-width: 600px;
width: 90%;
}

h1 {
font-family: 'Raleway', sans-serif;
color: #e94560;
font-size: 2.5rem;
margin-bottom: 20px;
}

p {
font-size: 1.2rem;
margin-bottom: 20px;
}

.word-container {
margin-bottom: 20px;
font-size: 2rem;
letter-spacing: 10px;
display: flex;
justify-content: center;
}

.word-container span {
margin: 0 5px;
padding: 5px 10px;
background-color: #0f3460;
border-radius: 5px;
min-width: 35px;
}

.clue {
font-style: italic;
color: #a4a4f9;
margin-bottom: 20px;
}

.letters {
display: flex;
flex-wrap: wrap;
justify-content: center;
}

.letter {
margin: 5px;
padding: 10px;
background-color: #53354a;
color: #f5f6fa;
font-size: 1.5rem;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
width: 45px;
text-align: center;
}

.letter:hover {
background-color: #903749;
}

#resultMessage {
margin-top: 20px;
font-weight: bold;
font-size: 1.2rem;
}

.lives {
margin-top: 20px;
color: #a4a4f9;
font-weight: bold;
font-size: 1.2rem;
}

.home-button {
margin-top: 20px;
padding: 10px 20px;
background-color: #e94560;
color: #f5f6fa;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s ease;
}

.home-button:hover {
background-color: #d83a56;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ This repository also provides one such platforms where contributers come over an
| [snake_water_gun](https://github.com/kunjgit/GameZone/tree/main/Games/snake_water_gun) | [Run and Jump](https://github.com/kunjgit/GameZone/tree/main/Games/Run_and_Jump) | [AI CHESS Game](https://github.com/kunjgit/GameZone/tree/main/Games/AI_CHESS_Game) | [Fruit_Catching](https://github.com/kunjgit/GameZone/tree/main/Games/Fruit_Catching) | [Bulls eye](https://github.com/kunjgit/GameZone/tree/main/Games/Bulls_eye) |
| [Crystals_Collecter](https://github.com/kunjgit/GameZone/tree/main/Games/Crystals_Collecter) | [Dots and Boxes Game](https://github.com/kunjgit/GameZone/tree/main/Games/Dots_and_Boxes_Game) | [Infinite Runner Game](https://github.com/kunjgit/GameZone/tree/main/Games/Infinite_Runner_Game) | [Mario_Matching](https://github.com/kunjgit/GameZone/tree/main/Games/mario_matching_game) | [Hand_Cricket](https://github.com/kunjgit/GameZone/tree/main/Games/Hand_Cricket) |
| [Crossword_Puzzle](https://github.com/kunjgit/GameZone/tree/main/Games/Crossword_Puzzle) | [Pixel_Painter](https://github.com/kunjgit/GameZone/tree/main/Games/Pixel_Painter) | [Riddle_Room](https://github.com/kunjgit/GameZone/tree/main/Games/Riddle_Room) | [ArmorAlley](https://github.com/kunjgit/GameZone/tree/main/Games/ArmorAlley) | [Color_switcher](https://github.com/kunjgit/GameZone/tree/main/Games/Color_switcher) |
| [Maze of Cables](https://github.com/VSatwika/GameZonefork/tree/Maze_of_Cables/Games/Maze_of_Cables) | [Escape Room](https://github.com/kunjgit/GameZone/tree/main/Games/Escape_room) | [Super_mario_run](https://github.com/kunjgit/GameZone/tree/main/Games/Super_mario_run) | [Doodle_Draw](https://github.com/kunjgit/GameZone/tree/main/Games/Doodle_Draw) | [Arcade_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Arcade_Game) |
| [Maze of Cables](https://github.com/VSatwika/GameZonefork/tree/Maze_of_Cables/Games/Maze_of_Cables) | [Escape Room](https://github.com/kunjgit/GameZone/tree/main/Games/Escape_room) | [Super_mario_run](https://github.com/kunjgit/GameZone/tree/main/Games/Super_mario_run) | [Doodle_Draw](https://github.com/kunjgit/GameZone/tree/main/Games/Doodle_Draw) | [Arcade_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Arcade_Game) | [Hidden Codebreaker](https://github.com/MuraliDharan7/GameZone/tree/hidden-codebraker/Games/Hidden-CodeBreaker) |
| [Slice Storm](https://github.com/VSatwika/GameZonefork/tree/Slice_Storm/Games/Slice_Storm) | [CodePen_SImulator](https://github.com/kunjgit/GameZone/tree/main/Games/CodePen_Simulator) | [Piano_Tiles](https://github.com/kunjgit/GameZone/tree/main/Games/PianoTiles_Game) | [CareTaker](https://github.com/kunjgit/GameZone/tree/main/Games/CareTaker) | [UNO](https://github.com/kunjgit/GameZone/tree/main/Games/UNO) |
| [Remeber the color](https://github.com/kunjgit/GameZone/tree/main/Games/Remember_the_color) | [Guess The Random Shape](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Random_Shape) | [Save Doraemon](https://github.com/kunjgit/GameZone/tree/main/Games/Save_Doraemon) | [Animal_Match_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Animal_Match_Game) | [Hextris](https://github.com/kunjgit/GameZone/tree/main/Games/Hextris) |
| [MrFakeGame](https://github.com/kunjgit/GameZone/tree/main/Games/MrFakeGame) | [Checkers](https://github.com/kunjgit/GameZone/tree/main/Games/Checkers) | [Roulette](https://github.com/kunjgit/GameZone/tree/main/Games/Roulette) | [Aero Acrobat](https://github.com/kunjgit/GameZone/tree/main/Games/Aero_Acrobat) | [Adventure_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Adventure_Game) |
Expand Down Expand Up @@ -404,4 +404,4 @@ Terms and conditions for use, reproduction and distribution are under the [Apach
</a>
</center>
<br>
<p align="right"><a href="#top">Back to top</a></p>
<p align="right"><a href="#top">Back to top</a></p>
Binary file added assets/images/Hidden_CodeBraker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading