PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Psychic Number Guess Game With Bash For Linux

Go down

Psychic Number Guess Game With Bash For Linux Empty Psychic Number Guess Game With Bash For Linux

Post by jamied_uk 2nd July 2021, 20:37

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
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum