./guess.sh
This here is a simple bash game where you guess a 2 digit number, but is it confined to only guessing the 2 digits? hmm...
Also, this is my first game in bash script.
For it to execute properly, you'll need another bash script named ho. ^.^
guess.sh
#!/bin/bash
well=$(echo $RANDOM | cut -b "1-2")
exec 2>/dev/null
while true; do
echo -e "\nI'm thinking of a number, can you guess what it is?"
read number
if [[ "$number" == "" ]]; then
echo -e "\nAhh breaking the loop ain't we?"
sleep 1
echo -e "\nWhat are you upto lately? "
read programming
case "$programming" in
"programming") echo -e "\nThat's so cool! Me too!"
;;
*) echo -e "\nThat's cool!"
;;
esac
sleep 1
echo -e "\nI've been into programming and pythons lately"
sleep 2
echo -e "\nHmm "
echo
./ho.sh
echo -e "\nI've been into turmoils lately... :c"
sleep 2
echo -e "\nHopefully get a better grip on my life..."
sleep 2
echo -e "\nI will be leaving for college soon"
sleep 2
echo -e "\nTell me about you perhaps on curious.queries@gmail.com?"
sleep 2
echo -e "\nFarewell c:"
sleep 2
echo -e "\nThis was written at 3 pm on January 31st, 2020 on Android 5.1.1 with an app called termux and with vim editor"
echo -e "\nHopefully you have a wonderful rest of your day"
break
exit 0
else
if [[ "$number" -lt "$well" ]]; then
echo -e "\nThe number you guessed is lower than the actual value.."
else
if [[ "$number" -gt "$well" ]]; then
echo -e "\nThe number you guessed is higher than the actual value..."
else
if [[ "$number" = "$well" ]]; then
echo -e "\nYou got it right!!"
echo -e "\nWanna play again?[yes/no] "
read answer
case "$answer" in
yes|y) ./guess.sh
;;
no|n) echo -e "\nProgram ends"
;;
*) echo -e "\nInvalid input... exiting program"
;;
esac
break
fi
fi
fi
fi
done
view raw
You can save this as guess.sh and don't forget to chmod u+x the script. The ho.sh script is below, save it as ho.sh under the same directory as guess.sh, the chmod +x ho.sh, and you're good to go.
ho.sh
#!/bin/bash
runtime="4 second"
endtime=$(date -ud "$runtime" +%s)
while [ "$(date -u +%s)" -lt "$endtime" ]; do
printf "." $(sleep .5); printf "." $(sleep .5); printf "."$(sleep 0.5);
echo
done
view raw
The idea of creating this came while I was reading a book called "Python Crash Course" by Erric Matthes, where the intro goes like this..
"I wrote my first program on a kit computer my dad had assembled in our basement. The computer consisted nothing more than a bare motherboard connected to a keyboard without a case, and it had a bare cathode ray tube for a monitor. My initial program was a simple number guessing game, which looked something like this
I'm thinking of a number, try to guess the number I'm thinking of: 25
Too low! Guess again: 50
Too high! Guess again: 42
That's it. Would you like to play again? (Yes/No) no
Thank's for playing
I'll always remember how satisfied I felt watching my family play a game I created."
Made with <3 by samiuljoy