Welcome to NGG Game - a simple and fun Number Guessing Game designed for the terminal! This project is written in Zsh script and provides a colorful, interactive experience using ASCII art, color codes, and engaging messages. Play against the computer to guess the randomly selected number within a certain number of attempts. Enjoy the game and see if you can win! 🏆
- About the Game
- Features
- Gameplay
- Installation
- How to Run the Game
- Code Overview
- Customization
- Dependencies
NGG Game (Number Guessing Game) is a terminal-based guessing game where players try to guess a randomly generated number within a specified range (1-100 by default). The game provides feedback on each guess, such as "too high" or "too low," helping the player get closer to the target number. It is an exciting game for anyone looking to have some fun in the terminal.
- Interactive Gameplay: Receive instant feedback on each guess.
- Attempts Limitation: Players have a limited number of attempts to guess correctly.
- ASCII Art Banner: A colorful ASCII banner generated using
figlet
andlolcat
. - Colorful Output: Messages are color-coded to improve readability and engagement.
- Easy Customization: Change the number range and attempt limits to make the game easier or harder.
- The game selects a random number between a predefined range (default: 1-100).
- The player has a set number of attempts (default: 10) to guess the number.
- After each guess, the game provides feedback:
- "Too high!" if the guess is greater than the target.
- "Too low!" if the guess is less than the target.
- "Congratulations!" if the guess is correct.
- If the player uses all attempts without guessing correctly, the game reveals the number and ends.
To play this game, ensure you have the necessary dependencies installed.
git clone https://github.com/rkstudio585/NGG-Game
cd NGG-Game
-
Install Zsh (if not already installed):
sudo apt-get install zsh -y
or
apt install zsh -y
-
Install
figlet
:sudo apt-get install figlet -y
or
apt install figlet -y
-
Install
ruby
:sudo apt-get install ruby -y
or
apt install ruby -y
-
Install
lolcat
(for colorful ASCII text):sudo gem install lolcat -y
or
gem install lolcat -y
-
Download the Script:
- Save the code in a file named
ngg.zsh
.
- Save the code in a file named
-
Make the Script Executable:
chmod +x ngg.zsh
-
Run the Game:
./ngg.zsh
or
zsh ngg.zsh
Here's a breakdown of the code structure:
The display_banner
function creates a colorful ASCII banner at the start of the game using figlet
and lolcat
:
display_banner() {
figlet "NGG Game" | lolcat
echo "\033[1;34mWelcome to the Number Guessing Game!\033[0m" # Blue color
echo
}
A random number within the specified range is generated:
min=1
max=100
random_number=$(( ( RANDOM % max ) + min ))
The main game loop allows the player to make guesses and gives feedback after each guess:
while (( attempts < max_attempts )); do
# Code for each guess and feedback
done
The game responds to each guess with feedback using colored text to indicate whether the guess was too high, too low, or correct:
- Green: Correct guess.
- Yellow: Hints (too high or too low).
- Red: Error messages (invalid input or game over).
To modify the range of numbers, adjust the min
and max
variables:
min=1
max=200 # Adjust the range here
To give players more or fewer attempts, change the max_attempts
variable:
max_attempts=5 # Adjust the number of attempts here
You can modify the ANSI color codes to personalize the game’s color scheme. For example, change the color of "Too low" or "Too high" messages:
echo "\033[1;36mToo low! Try a higher number.\033[0m" # Cyan color
This project requires:
zsh
: To run the script.figlet
: For generating ASCII text.lolcat
: For applying rainbow colors to text.
To install these dependencies, use the commands in the Installation section.
Enjoy your guessing journey and see if you can win the NGG Game! 🎉