Psychic Number Guess Game With Bash For Linux
Page 1 of 1
Psychic Number Guess Game With Bash For Linux
Vid
- Code:
#!/bin/bash
#
#
score="0"
clear
echo -en "\e[92m "
echo "Welcome To The Psychic Game"
echo "By"
echo "J~Net 2021"|figlet
echo "It has 3 levels and changes everytime while trying to be "
echo "Random As Fuck!"|figlet
if [[ ! -e files/state.txt ]]; then
mkdir -p files
chown $USER files
touch files/state.txt
fi
#
state=`cat files/state.txt`
#
function lvlcomplete(){
clear
echo "Game Complete!"|figlet
echo "Well Done You Are Confirmed Psychic!"
echo ""
#break
exit
}
function lvlone(){
lvl1_num=$(python -S -c "import random; print random.randrange(1,9)")
#echo "$lvl1_num"
while true;
do
echo "Your Guess For Level 1 (1 Digit Long)... Current Score $score"
read guess
if [ "$lvl1_num" = "$guess" ]
then
echo "Winner Now Level 2"
lvl="2"
state="2" && echo $lvl > files/state.txt
score=$(echo $score + 1 | bc)
lvltwo
else
echo "Wrong, Try Again..."
score=$(echo $score - 1 | bc)
fi
done
}
function lvltwo(){
clear
lvl2_num=$(python -S -c "import random; print random.randrange(10,99)")
#echo "$lvl1_num"
while true;
do
echo "Your Guess For Level 2 (2 Digits Long)..."
#echo "Answer For Lvl 2 Is $lvl2_num"
read guess
if [ "$lvl2_num" = "$guess" ]
then
echo "Winner Now Level 3"
score=$(echo $score + 1 | bc)
lvl="3"
state="3" && echo $lvl > files/state.txt
lvlthree
else
echo "Wrong, Try Again..."
score=$(echo $score - 1 | bc)
fi
done
}
function lvlthree(){
clear
lvl3_num=$(python -S -c "import random; print random.randrange(99,199)")
#echo "$lvl1_num"
while true;
do
#echo "Answer For Last Number Is: $lvl3_num"
echo "Your Guess For Level 3 (3 Digits Long)..."
read guess
if [ "$lvl3_num" = "$guess" ]
then
score=$(echo $score + 1 | bc)
lvl="Game Complete"
state="Game Complete" && echo $lvl > files/state.txt
echo "Your Score Is: $score"
echo "Enter To Finish..."
read Y
lvlcomplete
else
echo "Wrong, Try Again..."
score=$(echo $score - 1 | bc)
fi
done
}
input="files/state.txt"
_file="$input"
if [ -s "$_file" ]
then
echo "" # cat $_file
# do something as file has data
else
echo "New Game" > files/state.txt
state="New Game"
# do something as file is empty
fi
if [ "$state" = "New Game" ]
then
echo "Level 1"
lvl="1"
state="1" > files/state.txt
else
lvlone $lvl
echo "" #"$state"
fi
if [ "$lvl" = "2" ]
then
echo "Level 2"
state="2"
#lvlone $lvl
else
# lvlone $lvl
echo "" #"$state"
fi
#
#
#
echo "Level $state"|figlet
#
#lvlone $lvl
#echo $lvl1_num
while true;
do
#echo ""
lvlone # $lvl
done
Similar topics
» Bash Psychic Game For Linux Bash
» Linux Bash 1000 Prime Number Generator
» Linux Bash Shell Script To Pick A Random Number From And To Range
» Linux Bash Who Am I Game Example
» Heads Or Tails Game For Linux Bash CLI With Sound
» Linux Bash 1000 Prime Number Generator
» Linux Bash Shell Script To Pick A Random Number From And To Range
» Linux Bash Who Am I Game Example
» Heads Or Tails Game For Linux Bash CLI With Sound
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum